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.
 
 
 
 
 
 

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