CMakeLists.txt 5.5 KB

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