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.
 
 
 
 
 
 

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