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.
 
 
 
 
 
 

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