-
Notifications
You must be signed in to change notification settings - Fork 92
/
CMakeLists.txt
146 lines (111 loc) · 4.63 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.5...3.26)
PROJECT (librepo C)
OPTION (ENABLE_TESTS "Build test?" ON)
OPTION (ENABLE_DOCS "Build docs?" ON)
OPTION (ENABLE_EXAMPLES "Build examples?" ON)
OPTION (WITH_ZCHUNK "Build with zchunk support" ON)
OPTION (ENABLE_PYTHON "Build Python bindings" ON)
OPTION (USE_GPGME "Use GpgMe (instead of rpm library) for OpenPGP key support" ON)
OPTION (USE_RUN_GNUPG_USER_SOCKET "Create a directory for gpg-agent socket in /run/gnugp/user (instead of /run/user)" OFF)
OPTION (ENABLE_SELINUX "Restore SELinux labels on GnuPG directories" ON)
OPTION (WITH_SANITIZERS "Build with address, leak and undefined sanitizers (DEBUG ONLY)" OFF)
INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)
SET (VERSION "${LIBREPO_MAJOR}.${LIBREPO_MINOR}.${LIBREPO_PATCH}")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall")
SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -ggdb -O0 -Wall -Wextra -DDEBUG")
IF(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "debug"))
MESSAGE("Build type is set do DEBUG!")
ENDIF()
# Set librepo log domain
add_definitions( -DG_LOG_DOMAIN="librepo" )
# Add path with own cmake modules
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# Find necessare libraries
FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(GLIB2 glib-2.0>=2.66 gio-2.0 REQUIRED)
PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto openssl)
PKG_CHECK_MODULES(LIBXML2 libxml-2.0 REQUIRED)
FIND_PACKAGE(CURL 7.52.0 REQUIRED)
IF (USE_GPGME)
FIND_PACKAGE(Gpgme REQUIRED)
IF (ENABLE_SELINUX)
PKG_CHECK_MODULES(SELINUX REQUIRED libselinux)
ENDIF(ENABLE_SELINUX)
ELSE (USE_GPGME)
PKG_CHECK_MODULES(RPM REQUIRED rpm>=4.18.0)
INCLUDE(CheckSymbolExists)
SET(CMAKE_REQUIRED_INCLUDES "${RPM_INCLUDE_DIRS}")
SET(CMAKE_REQUIRED_LIBRARIES "${RPM_LIBRARIES}")
# pgpPrtParams2 added after rpm 4.19.0-alpha
CHECK_SYMBOL_EXISTS(pgpPrtParams2 rpm/rpmpgp.h HAVE_PGPPRTPARAMS2)
IF (HAVE_PGPPRTPARAMS2)
ADD_DEFINITIONS(-DHAVE_PGPPRTPARAMS2)
ENDIF()
# pgpVerifySignature2 added after rpm 4.19.0-alpha
CHECK_SYMBOL_EXISTS(pgpVerifySignature2 rpm/rpmpgp.h HAVE_PGPVERIFYSIGNATURE2)
IF (HAVE_PGPVERIFYSIGNATURE2)
ADD_DEFINITIONS(-DHAVE_PGPVERIFYSIGNATURE2)
ENDIF()
UNSET(CMAKE_REQUIRED_INCLUDES)
UNSET(CMAKE_REQUIRED_LIBRARIES)
ENDIF (USE_GPGME)
IF (USE_RUN_GNUPG_USER_SOCKET)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_RUN_GNUPG_USER_SOCKET")
SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DUSE_RUN_GNUPG_USER_SOCKET")
ENDIF (USE_RUN_GNUPG_USER_SOCKET)
IF (WITH_ZCHUNK)
PKG_CHECK_MODULES(ZCHUNKLIB zck>=0.9.11 REQUIRED)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_ZCHUNK")
SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DWITH_ZCHUNK")
SET (LIBREPO_ZCHUNK_ENABLED "1")
ELSE (WITH_ZCHUNK)
SET (LIBREPO_ZCHUNK_ENABLED "0")
ENDIF (WITH_ZCHUNK)
INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS})
# Enable large file support
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)
# Check libraries
IF (NOT LIBXML2_FOUND)
MESSAGE(FATAL_ERROR "No libxml-2.0 library installed")
ENDIF (NOT LIBXML2_FOUND)
IF (NOT CURL_FOUND)
MESSAGE(FATAL_ERROR "No CURL library installed")
ENDIF (NOT CURL_FOUND)
IF (WITH_SANITIZERS)
MESSAGE(WARNING "Building with sanitizers enabled!")
ADD_COMPILE_OPTIONS(-fsanitize=address -fsanitize=undefined -fsanitize=leak)
LINK_LIBRARIES(asan ubsan)
ENDIF()
# Generate header files with the configured ABI (e.g. with/without zchunk).
configure_file("librepo/downloadtarget.h.in" "librepo/downloadtarget.h" @ONLY)
configure_file("librepo/handle.h.in" "librepo/handle.h" @ONLY)
configure_file("librepo/util.h.in" "librepo/util.h" @ONLY)
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/librepo")
# Add include dirs
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
#INCLUDE_DIRECTORIES(${CHECK_INCLUDE_DIR})
IF (USE_GPGME AND ENABLE_SELINUX)
INCLUDE_DIRECTORIES(${SELINUX_INCLUDE_DIRS})
ADD_DEFINITIONS(-DENABLE_SELINUX=1)
ENDIF (USE_GPGME AND ENABLE_SELINUX)
include (GNUInstallDirs)
# Python stuff
IF (ENABLE_PYTHON)
FIND_PACKAGE (PythonInterp 3 EXACT REQUIRED)
FIND_PACKAGE (PythonLibs REQUIRED)
ENDIF (ENABLE_PYTHON)
# Subdirs
ADD_SUBDIRECTORY (librepo)
IF (ENABLE_TESTS)
PKG_CHECK_MODULES(LIBCHECK REQUIRED check)
ENABLE_TESTING()
ADD_SUBDIRECTORY (tests)
ENDIF (ENABLE_TESTS)
IF (ENABLE_DOCS)
ADD_SUBDIRECTORY (doc)
ENDIF (ENABLE_DOCS)
IF (ENABLE_EXAMPLES)
ADD_SUBDIRECTORY (examples/c)
ENDIF (ENABLE_EXAMPLES)