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.
 
 
 
 
 
 

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