CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. if (CMAKE_USE_PTHREADS_INIT)
  93. set(HAVE_PTHREAD 1)
  94. endif()
  95. # Configure some variables like package, version and architecture.
  96. set(PACKAGE ${PROJECT_NAME})
  97. set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>")
  98. set(PACKAGE_VERSION "1.3~rc2")
  99. if (NOT DEFINED COMMON_ARCH)
  100. execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
  101. OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
  102. endif()
  103. # Configure our configuration headers (config.h and apti18n.h)
  104. configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
  105. configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)
  106. # Generic header locations
  107. include_directories(${PROJECT_BINARY_DIR}/include)
  108. # Add our subdirectories
  109. add_subdirectory(vendor)
  110. add_subdirectory(apt-pkg)
  111. add_subdirectory(apt-private)
  112. add_subdirectory(apt-inst)
  113. add_subdirectory(cmdline)
  114. add_subdirectory(completions)
  115. add_subdirectory(doc)
  116. add_subdirectory(dselect)
  117. add_subdirectory(ftparchive)
  118. add_subdirectory(methods)
  119. add_subdirectory(test)
  120. if (USE_NLS)
  121. add_subdirectory(po)
  122. # Link update-po4a into the update-po target
  123. add_dependencies(update-po update-po4a)
  124. endif()
  125. # Create our directories.
  126. install_empty_directories(
  127. ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/apt.conf.d
  128. ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/preferences.d
  129. ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/sources.list.d
  130. ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/trusted.gpg.d
  131. ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt/archives/partial
  132. ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/lists/partial
  133. ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/mirrors/partial
  134. ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/periodic
  135. ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt
  136. )