Fix Werrors with GCC-14.1.0
[platform/upstream/libzypp.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.1)
2 PROJECT(LIBZYPP)
3 SET( PACKAGE "libzypp" )
4 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
5 SET( CMAKE_MODULE_PATH ${LIBZYPP_SOURCE_DIR}/cmake/modules )
6 INCLUDE(ZyppCommon)
7
8 OPTION (ENABLE_BUILD_DOCS "Build documentation by default?" OFF)
9 OPTION (ENABLE_BUILD_TRANS "Build translation files by default?" OFF)
10 OPTION (ENABLE_BUILD_TESTS "Build and run test suite by default?" OFF)
11 OPTION (ENABLE_USE_THREADS "Enable using threads (NOT being used by threads!)?" OFF)
12 OPTION (ENABLE_ZCHUNK_COMPRESSION "Build with zchunk compression support?" OFF)
13 OPTION (DISABLE_MEDIABACKEND_TESTS "Disable Tests depending on Nginx and libfcgi?" OFF)
14
15 OPTION (DISABLE_LIBPROXY "Build without libproxy support even if package is installed?" OFF)
16 OPTION (DISABLE_AUTODOCS "Do not require doxygen being installed (required to build autodocs)?" OFF)
17 OPTION (EXPORT_NG_API "Export experimental libzypp API" OFF)
18 #--------------------------------------------------------------------------------
19 SET (have_system x)
20
21 IF (DEBIAN)
22   MESSAGE (STATUS "Building for Debian")
23   SET (ENABLE_BUILD_DOCS ON)
24   SET (ENABLE_BUILD_TRANS ON)
25   SET (ENABLE_BUILD_TESTS ON)
26   SET (have_system ${have_system}x)
27 ENDIF (DEBIAN)
28
29 IF (${have_system} STREQUAL x)
30   MESSAGE (STATUS "Building for SUSE")
31 ENDIF (${have_system} STREQUAL x)
32
33 IF (${have_system} STRGREATER xx)
34   MESSAGE (FATAL_ERROR "Can only build for one system type.")
35 ENDIF (${have_system} STRGREATER xx)
36 #--------------------------------------------------------------------------------
37
38 # allow name libraries by name mixed with full
39 # paths
40 if(COMMAND cmake_policy)
41   cmake_policy(SET CMP0003 NEW)
42 endif(COMMAND cmake_policy)
43
44 find_package(FindPkgConfig)
45 INCLUDE( ${LIBZYPP_SOURCE_DIR}/VERSION.cmake )
46
47 MATH( EXPR LIBZYPP_NUMVERSION "${LIBZYPP_MAJOR} * 10000 + ${LIBZYPP_MINOR} * 100 + ${LIBZYPP_PATCH}" )
48 MATH( EXPR LIBZYPP_CURRENT "${LIBZYPP_MAJOR} * 100 + ${LIBZYPP_MINOR}" )
49 MATH( EXPR LIBZYPP_AGE     "${LIBZYPP_MINOR} - ${LIBZYPP_COMPATMINOR}" )
50 # Libtool wanted current:patch:age
51 # But cmake is not libtool, it wants the verbatim suffix to libzypp.so
52 MATH( EXPR LIBZYPP_SO_FIRST  "${LIBZYPP_CURRENT}-${LIBZYPP_AGE}" )
53 SET( VERSION "${LIBZYPP_MAJOR}.${LIBZYPP_MINOR}.${LIBZYPP_PATCH}" )
54 CONFIGURE_FILE ( zypp/APIConfig.h.in zypp/APIConfig.h )
55
56 SET (CMAKE_CXX_STANDARD ${ZYPPCOMMON_CXX_STANDARD})
57 include(CheckCCompilerFlag)
58 include(CheckCXXCompilerFlag)
59 CHECK_C_COMPILER_FLAG("-Werror=format-security" CC_FORMAT_SECURITY)
60 CHECK_CXX_COMPILER_FLAG("-Werror=format-security" CXX_FORMAT_SECURITY)
61
62 SET( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC -g -Wall -Wp,-D_GLIBCXX_ASSERTIONS" )
63 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fPIC -g -Wall -Wp,-D_GLIBCXX_ASSERTIONS" )
64
65 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -Woverloaded-virtual -Wnon-virtual-dtor" )
66
67 set( CMAKE_C_FLAGS_RELEASE     "${CMAKE_C_FLAGS} -O3 -DZYPP_NDEBUG" )
68 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DZYPP_NDEBUG" )
69
70 IF(${CC_FORMAT_SECURITY})
71   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security")
72 ENDIF(${CC_FORMAT_SECURITY})
73
74 IF(${CXX_FORMAT_SECURITY})
75   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
76 ENDIF(${CXX_FORMAT_SECURITY})
77
78 if ( NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
79   #cli args ignored by clang, it still prints a noisy warning though
80   SET( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -rdynamic -Wl,-as-needed" )
81   SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic -Wl,-as-needed" )
82 endif()
83
84 INCLUDE(CheckFunctionExists)
85 CHECK_FUNCTION_EXISTS(pipe2 PIPE2_FOUND)
86 IF(${PIPE2_FOUND})
87   ADD_DEFINITIONS(-DHAVE_PIPE2)
88 ENDIF(${PIPE2_FOUND})
89
90 ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
91 SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
92 SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" )
93
94 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
95
96 INCLUDE(CPack)
97
98 MACRO(ADD_TESTS)
99   FOREACH( loop_var ${ARGV} )
100     SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_AUTO_TEST_MAIN=\"\" " )
101     ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc )
102
103     SET(TEST_REQ_LIBS zypp-allsym ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
104     IF(NOT DISABLE_MEDIABACKEND_TESTS)
105       LIST( APPEND TEST_REQ_LIBS zypp_test_utils)
106     ENDIF()
107
108     TARGET_LINK_LIBRARIES( ${loop_var}_test ${TEST_REQ_LIBS} )
109     ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test --catch_system_errors=no)
110   ENDFOREACH( loop_var )
111 ENDMACRO(ADD_TESTS)
112
113 ####################################################################
114
115 IF ( ENABLE_USE_THREADS )
116   SET( CMAKE_THREAD_PREFER_PTHREAD TRUE )
117   FIND_PACKAGE( Threads REQUIRED )
118   IF ( CMAKE_USE_PTHREADS_INIT )
119     MESSAGE( STATUS "May use threads." )
120     SET( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -pthread -DZYPP_USE_THREADS" )
121     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DZYPP_USE_THREADS" )
122   ENDIF ( CMAKE_USE_PTHREADS_INIT )
123 ENDIF ( ENABLE_USE_THREADS )
124
125 INCLUDE(CheckSymbolExists)
126 FIND_PACKAGE(Rpm REQUIRED)
127 IF ( NOT RPM_FOUND)
128   MESSAGE( FATAL_ERROR " rpm-devel not found" )
129 ELSE ( NOT RPM_FOUND)
130   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
131   # fix includes not relative to rpm
132   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
133
134   # rpmtsSetVfyFlags were introduced in rpm-4.15
135   UNSET( RPMTSSETVFYFLAGS_FOUND CACHE )
136   SET( CMAKE_REQUIRED_LIBRARIES "-lrpm" )
137   CHECK_SYMBOL_EXISTS( rpmtsSetVfyFlags rpm/rpmts.h RPMTSSETVFYFLAGS_FOUND )
138   IF ( NOT RPMTSSETVFYFLAGS_FOUND )
139     ADD_DEFINITIONS( -DHAVE_NO_RPMTSSETVFYFLAGS )
140   ENDIF ()
141
142   if ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
143         MESSAGE( STATUS "rpm found: enable rpm-4 compat interface." )
144         ADD_DEFINITIONS(-D_RPM_5)
145   endif ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
146 ENDIF( NOT RPM_FOUND)
147
148 FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options unit_test_framework thread)
149 IF (Boost_FOUND)
150   MESSAGE( STATUS "boost found: includes in ${Boost_INCLUDE_DIRS}, library in ${Boost_LIBRARY_DIRS}")
151   INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
152   LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
153 ENDIF(Boost_FOUND)
154
155 FIND_PACKAGE(Gettext REQUIRED)
156 IF (GETTEXT_FOUND)
157   MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
158   INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
159 ELSE (GETTEXT_FOUND)
160   MESSAGE( FATAL_ERROR "Gettext not found" )
161 ENDIF (GETTEXT_FOUND)
162
163 FIND_PACKAGE(CURL REQUIRED)
164 IF ( NOT CURL_FOUND)
165   MESSAGE( FATAL_ERROR " curl not found" )
166 ELSE ( NOT CURL_FOUND)
167   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
168 ENDIF( NOT CURL_FOUND)
169
170 FIND_PACKAGE(LibXml2 REQUIRED)
171 IF ( NOT LIBXML2_FOUND)
172   MESSAGE( FATAL_ERROR " libxml not found" )
173 ELSE ( NOT LIBXML2_FOUND)
174   INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
175 ENDIF( NOT LIBXML2_FOUND)
176
177 FIND_PACKAGE(ZLIB REQUIRED)
178 IF ( NOT ZLIB_FOUND)
179   MESSAGE( FATAL_ERROR " zlib not found" )
180 ELSE ( NOT ZLIB_FOUND)
181   INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
182 ENDIF( NOT ZLIB_FOUND)
183
184
185 #Allow to override the libsolv install location
186 IF( LIBSOLV_SRCDIR AND LIBSOLV_BUILDDIR )
187   execute_process(
188     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/libsolv
189     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/libsolv/include
190     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/libsolv/ext
191     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/libsolv/solvversion
192     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBSOLV_SRCDIR}/src ${CMAKE_BINARY_DIR}/libsolv/include/solv
193     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBSOLV_SRCDIR}/ext ${CMAKE_BINARY_DIR}/libsolv/ext/solv
194     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBSOLV_BUILDDIR}/src ${CMAKE_BINARY_DIR}/libsolv/solvversion/solv
195   )
196
197   INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/libsolv/include ${CMAKE_BINARY_DIR}/libsolv/ext ${CMAKE_BINARY_DIR}/libsolv/solvversion ${CMAKE_BINARY_DIR}/libsolv/solvversion/solv ${CMAKE_BINARY_DIR}/libsolv/ext/solv ${CMAKE_BINARY_DIR}/libsolv/include/solv )
198   SET( LibSolv_LIBRARIES ${LIBSOLV_BUILDDIR}/src/libsolv.a ${LIBSOLV_BUILDDIR}/ext/libsolvext.a )
199
200 ELSE()
201   FIND_PACKAGE(LibSolv REQUIRED ext)
202   #SET(LibSolv_USE_STATIC_LIBS ON)
203   IF ( NOT LibSolv_FOUND )
204     MESSAGE( FATAL_ERROR " libsolv not found" )
205   ELSE()
206     INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
207   ENDIF()
208 ENDIF( LIBSOLV_SRCDIR AND LIBSOLV_BUILDDIR )
209
210 FIND_PACKAGE(Gpgme REQUIRED)
211 IF ( NOT GPGME_PTHREAD_FOUND )
212   MESSAGE( FATAL_ERROR " gpgme not found" )
213 ELSE()
214   INCLUDE_DIRECTORIES( ${GPGME_INCLUDES} )
215   LINK_DIRECTORIES(${GPGME_LIBRARY_DIR})
216 ENDIF()
217
218 FIND_PACKAGE(OpenSSL REQUIRED)
219
220 FIND_PACKAGE(Udev)
221 IF ( NOT UDEV_FOUND )
222   MESSAGE(WARNING "No udev found. CD device detection will be poor")
223 ELSE ( NOT UDEV_FOUND )
224   ADD_DEFINITIONS(-DHAVE_UDEV)
225 ENDIF ( NOT UDEV_FOUND )
226
227 IF( DISABLE_LIBPROXY )
228   MESSAGE( STATUS "libproxy support disabled" )
229 ELSE( DISABLE_LIBPROXY )
230   FIND_PACKAGE(libproxy)
231   IF ( NOT LIBPROXY_FOUND )
232     MESSAGE( STATUS "libproxy not found" )
233   ELSE ( NOT LIBPROXY_FOUND )
234     INCLUDE_DIRECTORIES( ${LIBPROXY_INCLUDE_DIR} )
235     ADD_DEFINITIONS(-DWITH_LIBPROXY_SUPPORT)
236   ENDIF( NOT LIBPROXY_FOUND )
237 ENDIF( DISABLE_LIBPROXY )
238
239 FIND_PROGRAM( DOXYGEN doxygen )
240 IF ( NOT DOXYGEN )
241   IF ( DISABLE_AUTODOCS )
242     MESSAGE( STATUS "doxygen is not available. Can't build the documentation." )
243   ELSE ( DISABLE_AUTODOCS )
244     MESSAGE( FATAL_ERROR "doxygen not found: install doxygen to build the documentation!" )
245   ENDIF ( DISABLE_AUTODOCS )
246 ELSE ( NOT DOXYGEN )
247   MESSAGE( STATUS "doxygen found: ${DOXYGEN}" )
248 ENDIF ( NOT DOXYGEN )
249
250 IF (ENABLE_ZCHUNK_COMPRESSION)
251   MESSAGE("Building with zchunk support enabled.")
252   PKG_CHECK_MODULES (ZCHUNK zck REQUIRED)
253   SET( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} ${ZCHUNK_CFLAGS}" )
254   SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ZCHUNK_CFLAGS}" )
255   ADD_DEFINITIONS (-DENABLE_ZCHUNK_COMPRESSION=1)
256 ENDIF(ENABLE_ZCHUNK_COMPRESSION)
257
258 pkg_check_modules ( SIGCPP REQUIRED sigc++-2.0 )
259 INCLUDE_DIRECTORIES( ${SIGCPP_INCLUDE_DIRS} )
260
261 pkg_check_modules ( LIBGLIB REQUIRED glib-2.0 )
262 INCLUDE_DIRECTORIES( ${LIBGLIB_INCLUDE_DIRS} )
263
264 MESSAGE(STATUS "soname: ${LIBZYPP_VERSION_INFO}")
265 MESSAGE(STATUS "version: ${VERSION}")
266
267 MESSAGE(STATUS "Writing pkg-config file...")
268 CONFIGURE_FILE(${LIBZYPP_SOURCE_DIR}/libzypp.pc.cmake ${LIBZYPP_BINARY_DIR}/libzypp.pc @ONLY)
269 INSTALL( FILES ${LIBZYPP_BINARY_DIR}/libzypp.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
270
271 MESSAGE(STATUS "FindZypp.cmake will be installed in ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules")
272 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/FindZypp.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
273 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/ZyppCommon.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
274
275 ####################################################################
276 # config templates
277 # (don't forget to mention them in the .spec file)
278 ####################################################################
279
280 MESSAGE(STATUS "zypp.conf will be installed in ${SYSCONFDIR}/zypp")
281 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp.conf DESTINATION ${SYSCONFDIR}/zypp )
282
283 MESSAGE(STATUS "needreboot will be installed in ${SYSCONFDIR}/zypp/")
284 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/needreboot DESTINATION ${SYSCONFDIR}/zypp )
285
286 #install systemCheck
287 MESSAGE(STATUS "systemCheck will be installed in ${SYSCONFDIR}/zypp")
288 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/systemCheck DESTINATION ${SYSCONFDIR}/zypp )
289
290 # logrotate config file
291 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp-history.lr DESTINATION ${SYSCONFDIR}/logrotate.d )
292
293 ####################################################################
294 # SUBDIRECTORIES                                                   #
295 ####################################################################
296
297 ADD_SUBDIRECTORY( zypp )
298 # do not build devel by default
299 ADD_SUBDIRECTORY( devel EXCLUDE_FROM_ALL )
300 ADD_SUBDIRECTORY( tools )
301 ADD_SUBDIRECTORY( doc )
302
303 IF ( ENABLE_BUILD_TRANS )
304   ADD_SUBDIRECTORY( po )
305 ELSE ( ENABLE_BUILD_TRANS )
306   ADD_SUBDIRECTORY( po EXCLUDE_FROM_ALL )
307 ENDIF ( ENABLE_BUILD_TRANS )
308
309 IF ( ENABLE_BUILD_TESTS )
310   ADD_SUBDIRECTORY( tests )
311 ELSE ( ENABLE_BUILD_TESTS )
312   ADD_SUBDIRECTORY( tests EXCLUDE_FROM_ALL )
313 ENDIF ( ENABLE_BUILD_TESTS )
314 INCLUDE(CTest)
315 ENABLE_TESTING()