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