CMakeLists.txt 5.9 KB

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