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.
 
 
 
 
 
 

259 lines
7.3 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(Seccomp)
  95. if (SECCOMP_FOUND)
  96. set(HAVE_SECCOMP 1)
  97. endif()
  98. # Mount()ing and stat()ing and friends
  99. check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
  100. check_include_files(sys/params.h HAVE_PARAMS_H)
  101. check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
  102. if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
  103. message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
  104. endif()
  105. check_function_exists(statvfs HAVE_STATVFS)
  106. if (NOT HAVE_STATVFS)
  107. configure_file(CMake/statvfs.h.in ${PROJECT_BINARY_DIR}/include/sys/statvfs.h COPYONLY)
  108. endif()
  109. CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
  110. # Other checks
  111. check_function_exists(getresuid HAVE_GETRESUID)
  112. check_function_exists(getresgid HAVE_GETRESGID)
  113. check_function_exists(setresuid HAVE_SETRESUID)
  114. check_function_exists(setresgid HAVE_SETRESGID)
  115. check_function_exists(ptsname_r HAVE_PTSNAME_R)
  116. check_function_exists(timegm HAVE_TIMEGM)
  117. test_big_endian(WORDS_BIGENDIAN)
  118. # FreeBSD
  119. add_definitions(-D_WITH_GETLINE=1)
  120. CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
  121. CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
  122. CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
  123. if (NOT HAVE_ENDIAN_H)
  124. if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H)
  125. configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h)
  126. else()
  127. message(FATAL_ERROR "Cannot find endian.h")
  128. endif()
  129. endif()
  130. include(CheckTypeSize)
  131. set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
  132. check_type_size("sig_t" SIG_T LANGUAGE "CXX")
  133. check_type_size("sighandler_t" SIGHANDLER_T LANGUAGE "CXX")
  134. set(CMAKE_EXTRA_INCLUDE_FILES)
  135. if (NOT HAVE_SIGHANDLER_T)
  136. if (HAVE_SIG_T)
  137. add_definitions(-Dsighandler_t=sig_t)
  138. else()
  139. message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
  140. endif()
  141. endif()
  142. # Handle resolving
  143. check_function_exists(res_init HAVE_LIBC_RESOLV)
  144. if(HAVE_LIBC_RESOLV)
  145. set(RESOLV_LIBRARIES)
  146. else()
  147. set(RESOLV_LIBRARIES -lresolv)
  148. endif()
  149. # Check multiversioning
  150. include(CheckCxxTarget)
  151. check_cxx_target(HAVE_FMV_SSE42_AND_CRC32 "sse4.2" "__builtin_ia32_crc32si(0, 1llu);")
  152. check_cxx_target(HAVE_FMV_SSE42_AND_CRC32DI "sse4.2" "__builtin_ia32_crc32di(0, 1llu);")
  153. # Configure some variables like package, version and architecture.
  154. set(PACKAGE ${PROJECT_NAME})
  155. set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>")
  156. set(PACKAGE_VERSION "1.8.0")
  157. string(REGEX MATCH "^[0-9.]+" PROJECT_VERSION ${PACKAGE_VERSION})
  158. if (NOT DEFINED DPKG_DATADIR)
  159. execute_process(COMMAND ${PERL_EXECUTABLE} -MDpkg -e "print $Dpkg::DATADIR;"
  160. OUTPUT_VARIABLE DPKG_DATADIR_CMD OUTPUT_STRIP_TRAILING_WHITESPACE)
  161. message(STATUS "Found dpkg data dir: ${DPKG_DATADIR_CMD}")
  162. set(DPKG_DATADIR "${DPKG_DATADIR_CMD}" CACHE PATH "dpkg data directory")
  163. endif()
  164. if (NOT DEFINED COMMON_ARCH)
  165. execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
  166. OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
  167. endif()
  168. if (NOT DEFINED ROOT_GROUP)
  169. execute_process(COMMAND id -gn root
  170. OUTPUT_VARIABLE ROOT_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE)
  171. message(STATUS "Found root group: ${ROOT_GROUP}")
  172. endif()
  173. set(ROOT_GROUP "${ROOT_GROUP}" CACHE STRING "Group of root (e.g.: wheel or root)")
  174. # Set various directories
  175. set(STATE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt" CACHE PATH "Your /var/lib/apt")
  176. set(CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt" CACHE PATH "Your /var/cache/apt")
  177. set(LOG_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt" CACHE PATH "Your /var/log/apt")
  178. set(CONF_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt" CACHE PATH "Your /etc/apt")
  179. set(LIBEXEC_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/apt" CACHE PATH "Your /usr/libexec/apt")
  180. set(BIN_DIR "${CMAKE_INSTALL_FULL_BINDIR}")
  181. # Configure our configuration headers (config.h and apti18n.h)
  182. configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
  183. configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)
  184. # Add our subdirectories
  185. add_subdirectory(vendor)
  186. add_subdirectory(apt-pkg)
  187. add_subdirectory(apt-private)
  188. add_subdirectory(apt-inst)
  189. add_subdirectory(cmdline)
  190. add_subdirectory(completions)
  191. add_subdirectory(doc)
  192. add_subdirectory(dselect)
  193. add_subdirectory(ftparchive)
  194. add_subdirectory(methods)
  195. add_subdirectory(test)
  196. if (USE_NLS)
  197. add_subdirectory(po)
  198. # Link update-po4a into the update-po target
  199. add_dependencies(update-po update-po4a)
  200. endif()
  201. # Create our directories.
  202. install_empty_directories(
  203. ${CONF_DIR}/apt.conf.d
  204. ${CONF_DIR}/auth.conf.d
  205. ${CONF_DIR}/preferences.d
  206. ${CONF_DIR}/sources.list.d
  207. ${CONF_DIR}/trusted.gpg.d
  208. ${CACHE_DIR}/archives/partial
  209. ${STATE_DIR}/lists/partial
  210. ${STATE_DIR}/mirrors/partial
  211. ${STATE_DIR}/periodic
  212. ${LOG_DIR}
  213. )