CMakeLists.txt 6.4 KB

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