CMakeLists.txt 5.4 KB

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