CMakeLists.txt 6.2 KB

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