You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

269 lines
7.6 KiB

  1. # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>.
  2. # Licensed under the same terms as APT; i.e. GPL 2 or later.
  3. # set minimum version
  4. project(apt)
  5. cmake_minimum_required(VERSION 3.4.0)
  6. # Generic header locations
  7. include_directories(${PROJECT_BINARY_DIR}/include)
  8. enable_testing()
  9. option(WITH_DOC "Build documentation." ON)
  10. option(USE_NLS "Localisation support." ON)
  11. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake")
  12. # Add coverage target
  13. set(CMAKE_CXX_FLAGS_COVERAGE "-g -fprofile-arcs -ftest-coverage")
  14. set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "-lgcov")
  15. set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "-lgcov")
  16. # Work around bug in GNUInstallDirs
  17. if (EXISTS "/etc/debian_version")
  18. set(CMAKE_INSTALL_LIBEXECDIR "lib")
  19. endif()
  20. # Include stuff
  21. include(Misc)
  22. include(CheckIncludeFiles)
  23. include(CheckFunctionExists)
  24. include(CheckStructHasMember)
  25. include(GNUInstallDirs)
  26. include(TestBigEndian)
  27. find_package(Threads REQUIRED)
  28. find_package(LFS REQUIRED)
  29. find_package(Iconv REQUIRED)
  30. find_package(Perl REQUIRED)
  31. find_program(TRIEHASH_EXECUTABLE NAMES triehash)
  32. if (NOT TRIEHASH_EXECUTABLE)
  33. message(FATAL_ERROR "Could not find triehash executable")
  34. endif()
  35. if(USE_NLS)
  36. find_package(Intl REQUIRED)
  37. link_libraries(${Intl_LIBRARIES})
  38. include_directories(${Intl_INCLUDE_DIRS})
  39. endif()
  40. # Add large file support
  41. add_compile_options(${LFS_COMPILE_OPTIONS})
  42. add_definitions(${LFS_DEFINITIONS})
  43. link_libraries(${LFS_LIBRARIES})
  44. # Set compiler flags
  45. set(CMAKE_CXX_STANDARD 14)
  46. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  47. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  48. add_optional_compile_options(Wall)
  49. add_optional_compile_options(Wextra)
  50. add_optional_compile_options(Wcast-align)
  51. add_optional_compile_options(Wlogical-op)
  52. add_optional_compile_options(Wredundant-decls)
  53. add_optional_compile_options(Wmissing-declarations)
  54. add_optional_compile_options(Wunsafe-loop-optimizations)
  55. add_optional_compile_options(Wctor-dtor-privacy)
  56. add_optional_compile_options(Wdisabled-optimization)
  57. add_optional_compile_options(Winit-self)
  58. add_optional_compile_options(Wmissing-include-dirs)
  59. add_optional_compile_options(Wnoexcept)
  60. add_optional_compile_options(Wsign-promo)
  61. add_optional_compile_options(Wundef)
  62. add_optional_compile_options(Wdouble-promotion)
  63. add_optional_compile_options(Wsuggest-override)
  64. add_optional_compile_options(Werror=suggest-override)
  65. add_optional_compile_options(Werror=return-type)
  66. # apt-ftparchive dependencies
  67. find_package(BerkeleyDB REQUIRED)
  68. if (BERKELEY_DB_FOUND)
  69. set(HAVE_BDB 1)
  70. endif()
  71. find_package(GnuTLS REQUIRED)
  72. if (GNUTLS_FOUND)
  73. set(HAVE_GNUTLS 1)
  74. endif()
  75. # (De)Compressor libraries
  76. find_package(ZLIB REQUIRED)
  77. if (ZLIB_FOUND)
  78. set(HAVE_ZLIB 1)
  79. endif()
  80. find_package(BZip2 REQUIRED)
  81. if (BZIP2_FOUND)
  82. set(HAVE_BZ2 1)
  83. endif()
  84. find_package(LZMA REQUIRED)
  85. if (LZMA_FOUND)
  86. set(HAVE_LZMA 1)
  87. endif()
  88. find_package(LZ4 REQUIRED)
  89. if (LZ4_FOUND)
  90. set(HAVE_LZ4 1)
  91. endif()
  92. find_package(Zstd)
  93. if (ZSTD_FOUND)
  94. set(HAVE_ZSTD 1)
  95. endif()
  96. find_package(Udev)
  97. if (UDEV_FOUND)
  98. set(HAVE_UDEV 1)
  99. endif()
  100. find_package(Systemd)
  101. if (SYSTEMD_FOUND)
  102. set(HAVE_SYSTEMD 1)
  103. endif()
  104. find_package(Seccomp)
  105. if (SECCOMP_FOUND)
  106. set(HAVE_SECCOMP 1)
  107. endif()
  108. # Mount()ing and stat()ing and friends
  109. check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
  110. check_include_files(sys/params.h HAVE_PARAMS_H)
  111. check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
  112. if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
  113. message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
  114. endif()
  115. check_function_exists(statvfs HAVE_STATVFS)
  116. if (NOT HAVE_STATVFS)
  117. configure_file(CMake/statvfs.h.in ${PROJECT_BINARY_DIR}/include/sys/statvfs.h COPYONLY)
  118. endif()
  119. CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
  120. # Other checks
  121. check_function_exists(getresuid HAVE_GETRESUID)
  122. check_function_exists(getresgid HAVE_GETRESGID)
  123. check_function_exists(setresuid HAVE_SETRESUID)
  124. check_function_exists(setresgid HAVE_SETRESGID)
  125. check_function_exists(ptsname_r HAVE_PTSNAME_R)
  126. check_function_exists(timegm HAVE_TIMEGM)
  127. test_big_endian(WORDS_BIGENDIAN)
  128. # FreeBSD
  129. add_definitions(-D_WITH_GETLINE=1)
  130. CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
  131. CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
  132. CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
  133. if (NOT HAVE_ENDIAN_H)
  134. if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H)
  135. configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h)
  136. else()
  137. message(FATAL_ERROR "Cannot find endian.h")
  138. endif()
  139. endif()
  140. include(CheckTypeSize)
  141. set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
  142. check_type_size("sig_t" SIG_T LANGUAGE "CXX")
  143. check_type_size("sighandler_t" SIGHANDLER_T LANGUAGE "CXX")
  144. set(CMAKE_EXTRA_INCLUDE_FILES)
  145. if (NOT HAVE_SIGHANDLER_T)
  146. if (HAVE_SIG_T)
  147. add_definitions(-Dsighandler_t=sig_t)
  148. else()
  149. message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
  150. endif()
  151. endif()
  152. # Handle resolving
  153. check_function_exists(res_ninit HAVE_LIBC_RESOLV)
  154. if(HAVE_LIBC_RESOLV)
  155. set(RESOLV_LIBRARIES)
  156. else()
  157. set(RESOLV_LIBRARIES -lresolv)
  158. endif()
  159. # Check multiversioning
  160. include(CheckCxxTarget)
  161. check_cxx_target(HAVE_FMV_SSE42_AND_CRC32 "sse4.2" "__builtin_ia32_crc32si(0, 1llu);")
  162. check_cxx_target(HAVE_FMV_SSE42_AND_CRC32DI "sse4.2" "__builtin_ia32_crc32di(0, 1llu);")
  163. # Configure some variables like package, version and architecture.
  164. set(PACKAGE ${PROJECT_NAME})
  165. set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>")
  166. set(PACKAGE_VERSION "1.9.5")
  167. string(REGEX MATCH "^[0-9.]+" PROJECT_VERSION ${PACKAGE_VERSION})
  168. if (NOT DEFINED DPKG_DATADIR)
  169. execute_process(COMMAND ${PERL_EXECUTABLE} -MDpkg -e "print $Dpkg::DATADIR;"
  170. OUTPUT_VARIABLE DPKG_DATADIR_CMD OUTPUT_STRIP_TRAILING_WHITESPACE)
  171. message(STATUS "Found dpkg data dir: ${DPKG_DATADIR_CMD}")
  172. set(DPKG_DATADIR "${DPKG_DATADIR_CMD}" CACHE PATH "dpkg data directory")
  173. endif()
  174. if (NOT DEFINED COMMON_ARCH)
  175. execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
  176. OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
  177. endif()
  178. if (NOT DEFINED ROOT_GROUP)
  179. execute_process(COMMAND id -gn root
  180. OUTPUT_VARIABLE ROOT_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE)
  181. message(STATUS "Found root group: ${ROOT_GROUP}")
  182. endif()
  183. set(ROOT_GROUP "${ROOT_GROUP}" CACHE STRING "Group of root (e.g.: wheel or root)")
  184. # Set various directories
  185. set(STATE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt" CACHE PATH "Your /var/lib/apt")
  186. set(CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt" CACHE PATH "Your /var/cache/apt")
  187. set(LOG_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt" CACHE PATH "Your /var/log/apt")
  188. set(CONF_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt" CACHE PATH "Your /etc/apt")
  189. set(LIBEXEC_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/apt" CACHE PATH "Your /usr/libexec/apt")
  190. set(BIN_DIR "${CMAKE_INSTALL_FULL_BINDIR}")
  191. # Configure our configuration headers (config.h and apti18n.h)
  192. configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
  193. configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)
  194. # Add our subdirectories
  195. add_subdirectory(vendor)
  196. add_subdirectory(apt-pkg)
  197. add_subdirectory(apt-private)
  198. add_subdirectory(cmdline)
  199. add_subdirectory(completions)
  200. add_subdirectory(doc)
  201. add_subdirectory(dselect)
  202. add_subdirectory(ftparchive)
  203. add_subdirectory(methods)
  204. add_subdirectory(test)
  205. if (USE_NLS)
  206. add_subdirectory(po)
  207. # Link update-po4a into the update-po target
  208. add_dependencies(update-po update-po4a)
  209. endif()
  210. # Create our directories.
  211. install_empty_directories(
  212. ${CONF_DIR}/apt.conf.d
  213. ${CONF_DIR}/auth.conf.d
  214. ${CONF_DIR}/preferences.d
  215. ${CONF_DIR}/sources.list.d
  216. ${CONF_DIR}/trusted.gpg.d
  217. ${CACHE_DIR}/archives/partial
  218. ${STATE_DIR}/lists/partial
  219. ${STATE_DIR}/mirrors/partial
  220. ${STATE_DIR}/periodic
  221. ${LOG_DIR}
  222. )