CMakeLists.txt 6.6 KB

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