CMakeLists.txt 14 KB

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