CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. # === This file is part of Calamares - <https://github.com/calamares> ===
  2. #
  3. # Calamares is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # Calamares is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Calamares. If not, see <http://www.gnu.org/licenses/>.
  15. #
  16. # SPDX-License-Identifier: GPL-3.0+
  17. # License-Filename: LICENSE
  18. #
  19. ###
  20. #
  21. # Generally, this CMakeLists.txt will find all the dependencies for Calamares
  22. # and complain appropriately. See below (later in this file) for CMake-level
  23. # options. There are some "secret" options as well:
  24. #
  25. # SKIP_MODULES : a space or semicolon-separated list of directory names
  26. # under src/modules that should not be built.
  27. #
  28. # Example usage:
  29. #
  30. # cmake . -DSKIP_MODULES="partition luksbootkeycfg"
  31. project( calamares C CXX )
  32. cmake_minimum_required( VERSION 3.2 )
  33. set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules" )
  34. set( CMAKE_CXX_STANDARD 14 )
  35. set( CMAKE_CXX_STANDARD_REQUIRED ON )
  36. set( CMAKE_C_STANDARD 99 )
  37. set( CMAKE_C_STANDARD_REQUIRED ON )
  38. if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
  39. message( STATUS "Found Clang ${CMAKE_CXX_COMPILER_VERSION}, setting up Clang-specific compiler flags." )
  40. set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
  41. set( CMAKE_C_FLAGS_DEBUG "-g" )
  42. set( CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
  43. set( CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG" )
  44. set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g" )
  45. # Clang warnings: doing *everything* is counter-productive, since it warns
  46. # about things which we can't fix (e.g. C++98 incompatibilities, but
  47. # Calamares is C++14).
  48. foreach( CLANG_WARNINGS
  49. -Weverything
  50. -Wno-c++98-compat
  51. -Wno-c++98-compat-pedantic
  52. -Wno-padded
  53. -Wno-undefined-reinterpret-cast
  54. -Wno-global-constructors
  55. -Wno-exit-time-destructors
  56. -Wno-missing-prototypes
  57. -Wno-documentation-unknown-command
  58. )
  59. string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" )
  60. endforeach()
  61. # Third-party code where we don't care so much about compiler warnings
  62. # (because it's uncomfortable to patch) get different flags; use
  63. # mark_thirdparty_code( <file> [<file>...] )
  64. # to switch off warnings for those sources.
  65. set( SUPPRESS_3RDPARTY_WARNINGS "-Wno-everything" )
  66. set( SUPPRESS_BOOST_WARNINGS " -Wno-zero-as-null-pointer-constant -Wno-disabled-macro-expansion" )
  67. set( CMAKE_CXX_FLAGS_DEBUG "-g" )
  68. set( CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
  69. set( CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG" )
  70. set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
  71. set( CMAKE_TOOLCHAIN_PREFIX "llvm-" )
  72. set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
  73. else()
  74. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" )
  75. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
  76. set( SUPPRESS_3RDPARTY_WARNINGS "" )
  77. set( SUPPRESS_BOOST_WARNINGS "" )
  78. endif()
  79. # Use mark_thirdparty_code() to reduce warnings from the compiler
  80. # on code that we're not going to fix. Call this with a list of files.
  81. macro(mark_thirdparty_code)
  82. set_source_files_properties( ${ARGV}
  83. PROPERTIES
  84. COMPILE_FLAGS "${SUPPRESS_3RDPARTY_WARNINGS}"
  85. COMPILE_DEFINITIONS "THIRDPARTY"
  86. )
  87. endmacro()
  88. if( CMAKE_COMPILER_IS_GNUCXX )
  89. if( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR
  90. CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9 )
  91. message( STATUS "Found GNU g++ ${CMAKE_CXX_COMPILER_VERSION}, enabling colorized error messages." )
  92. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )
  93. endif()
  94. endif()
  95. include( FeatureSummary )
  96. set( QT_VERSION 5.6.0 )
  97. find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core Gui Widgets LinguistTools Svg Quick QuickWidgets )
  98. find_package( YAMLCPP 0.5.1 REQUIRED )
  99. find_package( PolkitQt5-1 REQUIRED )
  100. # Find ECM once, and add it to the module search path; Calamares
  101. # modules that need ECM can do
  102. # find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE),
  103. # no need to mess with the module path after.
  104. set( ECM_VERSION 5.10.0 )
  105. find_package(ECM ${ECM_VERSION} NO_MODULE)
  106. if( ECM_FOUND )
  107. set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
  108. endif()
  109. option( INSTALL_CONFIG "Install configuration files" ON )
  110. option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON )
  111. option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." OFF )
  112. option( BUILD_TESTING "Build the testing tree." ON )
  113. if( BUILD_TESTING )
  114. enable_testing()
  115. endif ()
  116. find_package( PythonLibs 3.3 )
  117. set_package_properties(
  118. PythonLibs PROPERTIES
  119. DESCRIPTION "C interface libraries for the Python 3 interpreter."
  120. URL "http://python.org"
  121. PURPOSE "Python 3 is used for Python job modules."
  122. )
  123. if ( PYTHONLIBS_FOUND )
  124. include( BoostPython3 )
  125. find_boost_python3( 1.54.0 ${PYTHONLIBS_VERSION_STRING} CALAMARES_BOOST_PYTHON3_FOUND )
  126. set_package_properties(
  127. Boost PROPERTIES
  128. PURPOSE "Boost.Python is used for Python job modules."
  129. )
  130. find_package( PythonQt )
  131. set_package_properties( PythonQt PROPERTIES
  132. DESCRIPTION "A Python embedding solution for Qt applications."
  133. URL "http://pythonqt.sourceforge.net"
  134. PURPOSE "PythonQt is used for Python view modules."
  135. )
  136. endif()
  137. if( PYTHONLIBS_NOTFOUND OR NOT CALAMARES_BOOST_PYTHON3_FOUND )
  138. set( WITH_PYTHON OFF )
  139. endif()
  140. if( PYTHONLIBS_NOTFOUND OR NOT PYTHONQT_FOUND )
  141. set( WITH_PYTHONQT OFF )
  142. endif()
  143. ###
  144. ### Calamares application info
  145. ###
  146. set( CALAMARES_ORGANIZATION_NAME "Calamares" )
  147. set( CALAMARES_ORGANIZATION_DOMAIN "github.com/calamares" )
  148. set( CALAMARES_APPLICATION_NAME "Calamares" )
  149. set( CALAMARES_DESCRIPTION_SUMMARY "The distribution-independent installer framework" )
  150. set( CALAMARES_TRANSLATION_LANGUAGES ar ast bg ca cs_CZ da de el en en_GB es_MX es eu fr he hr hu id is it_IT ja lt nl pl pt_BR pt_PT ro ru sk sv th tr_TR zh_CN zh_TW )
  151. ### Bump version here
  152. set( CALAMARES_VERSION_MAJOR 3 )
  153. set( CALAMARES_VERSION_MINOR 1 )
  154. set( CALAMARES_VERSION_PATCH 13 )
  155. set( CALAMARES_VERSION_RC 0 )
  156. set( CALAMARES_VERSION ${CALAMARES_VERSION_MAJOR}.${CALAMARES_VERSION_MINOR}.${CALAMARES_VERSION_PATCH} )
  157. set( CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}" )
  158. if( CALAMARES_VERSION_RC )
  159. set( CALAMARES_VERSION ${CALAMARES_VERSION}rc${CALAMARES_VERSION_RC} )
  160. endif()
  161. # additional info for non-release builds
  162. if( NOT BUILD_RELEASE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" )
  163. include( CMakeDateStamp )
  164. set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" )
  165. if( CALAMARES_VERSION_DATE GREATER 0 )
  166. set( CALAMARES_VERSION ${CALAMARES_VERSION}.${CALAMARES_VERSION_DATE} )
  167. endif()
  168. include( CMakeVersionSource )
  169. if( CMAKE_VERSION_SOURCE )
  170. set( CALAMARES_VERSION ${CALAMARES_VERSION}-${CMAKE_VERSION_SOURCE} )
  171. endif()
  172. endif()
  173. # enforce using constBegin, constEnd for const-iterators
  174. add_definitions( "-DQT_STRICT_ITERATORS" )
  175. # set paths
  176. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
  177. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
  178. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
  179. # Better default installation paths: GNUInstallDirs defines
  180. # CMAKE_INSTALL_FULL_SYSCONFDIR to be CMAKE_INSTALL_PREFIX/etc by default
  181. # but we really want /etc
  182. if( NOT DEFINED CMAKE_INSTALL_SYSCONFDIR )
  183. set( CMAKE_INSTALL_SYSCONFDIR "/etc" )
  184. endif()
  185. # make predefined install dirs available everywhere
  186. include( GNUInstallDirs )
  187. # make uninstall support
  188. configure_file(
  189. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  190. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  191. IMMEDIATE @ONLY
  192. )
  193. # Early configure these files as we need them later on
  194. set( CALAMARES_CMAKE_DIR "${CMAKE_SOURCE_DIR}/CMakeModules" )
  195. set( CALAMARES_LIBRARIES calamares )
  196. set( THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/thirdparty" )
  197. ### Example Distro
  198. #
  199. # For testing purposes Calamares includes a very, very, limited sample
  200. # distro called "Generic". The root filesystem of "Generic" lives in
  201. # data/example-root and can be squashed up as part of the build, so
  202. # that a pure-upstream run of ./calamares -d from the build directory
  203. # (with all the default settings and configurations) can actually
  204. # do an complete example run.
  205. #
  206. # Some binaries from the build host (e.g. /bin and /lib) are also
  207. # squashed into the example filesystem.
  208. #
  209. # To build the example distro (for use by the default, example,
  210. # unsquashfs module), build the target 'example-distro', eg.:
  211. #
  212. # make example-distro
  213. #
  214. find_program( mksquashfs_PROGRAM mksquashfs )
  215. if( mksquashfs_PROGRAM )
  216. set( mksquashfs_FOUND ON )
  217. set( src_fs ${CMAKE_SOURCE_DIR}/data/example-root/ )
  218. set( dst_fs ${CMAKE_BINARY_DIR}/example.sqfs )
  219. if( EXISTS ${src_fs} )
  220. # based on the build host. If /lib64 exists, assume it is needed.
  221. # Collect directories needed for a minimal binary distro,
  222. # Note that the last path component is added to the root, so
  223. # if you add /usr/sbin here, it will be put into /sbin_1.
  224. # Add such paths to /etc/profile under ${src_fs}.
  225. set( candidate_fs /sbin /bin /lib /lib64 )
  226. set( host_fs "" )
  227. foreach( c_fs ${candidate_fs} )
  228. if( EXISTS ${c_fs} )
  229. list( APPEND host_fs ${c_fs} )
  230. endif()
  231. endforeach()
  232. add_custom_command(
  233. OUTPUT ${dst_fs}
  234. COMMAND ${mksquashfs_PROGRAM} ${src_fs} ${dst_fs} -all-root
  235. COMMAND ${mksquashfs_PROGRAM} ${host_fs} ${dst_fs} -all-root
  236. )
  237. add_custom_target(example-distro DEPENDS ${dst_fs})
  238. endif()
  239. else()
  240. set( mksquashfs_FOUND OFF )
  241. endif()
  242. # Doesn't list mksquashfs as an optional dep, though, because it
  243. # hasn't been sent through the find_package() scheme.
  244. #
  245. # "http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html"
  246. add_feature_info( ExampleDistro ${mksquashfs_FOUND} "Create example-distro target.")
  247. # add_subdirectory( thirdparty )
  248. add_subdirectory( src )
  249. add_feature_info(Python ${WITH_PYTHON} "Python job modules")
  250. add_feature_info(PythonQt ${WITH_PYTHONQT} "Python view modules")
  251. add_feature_info(Config ${INSTALL_CONFIG} "Install Calamares configuration")
  252. feature_summary(WHAT ALL)
  253. # Add all targets to the build-tree export set
  254. set( CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Calamares" CACHE PATH "Installation directory for CMake files" )
  255. set( CMAKE_INSTALL_FULL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" )
  256. export( TARGETS calamares
  257. FILE "${PROJECT_BINARY_DIR}/CalamaresLibraryDepends.cmake" )
  258. # Export the package for use from the build-tree
  259. # (this registers the build-tree with a global CMake-registry)
  260. export( PACKAGE Calamares )
  261. # Create a CalamaresBuildTreeSettings.cmake file for the use from the build tree
  262. configure_file( CalamaresBuildTreeSettings.cmake.in "${PROJECT_BINARY_DIR}/CalamaresBuildTreeSettings.cmake" @ONLY )
  263. # Create the CalamaresConfig.cmake and CalamaresConfigVersion files
  264. file( RELATIVE_PATH CONF_REL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_CMAKEDIR}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}" )
  265. configure_file( CalamaresConfig.cmake.in "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake" @ONLY )
  266. configure_file( CalamaresConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake" @ONLY )
  267. # Install the cmake files
  268. install(
  269. FILES
  270. "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake"
  271. "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake"
  272. "CMakeModules/CalamaresAddPlugin.cmake"
  273. "CMakeModules/CalamaresAddModuleSubdirectory.cmake"
  274. "CMakeModules/CalamaresAddLibrary.cmake"
  275. "CMakeModules/CalamaresAddBrandingSubdirectory.cmake"
  276. DESTINATION
  277. "${CMAKE_INSTALL_CMAKEDIR}"
  278. )
  279. # Install the export set for use with the install-tree
  280. install(
  281. EXPORT
  282. CalamaresLibraryDepends
  283. DESTINATION
  284. "${CMAKE_INSTALL_CMAKEDIR}"
  285. )
  286. if( INSTALL_CONFIG )
  287. install(
  288. FILES
  289. settings.conf
  290. DESTINATION
  291. share/calamares
  292. )
  293. endif()
  294. install(
  295. FILES
  296. com.github.calamares.calamares.policy
  297. DESTINATION
  298. "${POLKITQT-1_POLICY_FILES_INSTALL_DIR}"
  299. )
  300. install(
  301. FILES
  302. calamares.desktop
  303. DESTINATION
  304. ${CMAKE_INSTALL_DATADIR}/applications
  305. )
  306. install(
  307. FILES
  308. man/calamares.8
  309. DESTINATION
  310. ${CMAKE_INSTALL_MANDIR}/man8/
  311. )
  312. # uninstall target
  313. configure_file(
  314. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  315. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  316. IMMEDIATE @ONLY
  317. )
  318. add_custom_target( uninstall
  319. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  320. )