2 SET( PACKAGE "libzypp" )
3 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
4 SET( CMAKE_MODULE_PATH ${LIBZYPP_SOURCE_DIR}/cmake/modules )
6 cmake_minimum_required(VERSION 2.6)
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)
13 OPTION (DISABLE_LIBPROXY "Build without libproxy support even if package is installed?" OFF)
14 OPTION (DISABLE_AUTODOCS "Do not require doxygen being installed (required to build autodocs)?" OFF)
15 #--------------------------------------------------------------------------------
19 MESSAGE (STATUS "Building for Debian")
20 SET (ENABLE_BUILD_DOCS ON)
21 SET (ENABLE_BUILD_TRANS ON)
22 SET (ENABLE_BUILD_TESTS ON)
23 SET (have_system ${have_system}x)
26 IF (${have_system} STREQUAL x)
27 MESSAGE (STATUS "Building for SUSE")
28 ENDIF (${have_system} STREQUAL x)
30 IF (${have_system} STRGREATER xx)
31 MESSAGE (FATAL_ERROR "Can only build for one system type.")
32 ENDIF (${have_system} STRGREATER xx)
33 #--------------------------------------------------------------------------------
35 # allow name libraries by name mixed with full
37 if(COMMAND cmake_policy)
38 cmake_policy(SET CMP0003 NEW)
39 endif(COMMAND cmake_policy)
42 INCLUDE( ${LIBZYPP_SOURCE_DIR}/VERSION.cmake )
44 MATH( EXPR LIBZYPP_CURRENT "${LIBZYPP_MAJOR} * 100 + ${LIBZYPP_MINOR}" )
45 MATH( EXPR LIBZYPP_AGE "${LIBZYPP_MINOR} - ${LIBZYPP_COMPATMINOR}" )
46 # Libtool wanted current:patch:age
47 # But cmake is not libtool, it wants the verbatim suffix to libzypp.so
48 MATH( EXPR LIBZYPP_SO_FIRST "${LIBZYPP_CURRENT}-${LIBZYPP_AGE}" )
49 SET( VERSION "${LIBZYPP_MAJOR}.${LIBZYPP_MINOR}.${LIBZYPP_PATCH}" )
51 include(CheckCCompilerFlag)
52 include(CheckCXXCompilerFlag)
53 CHECK_C_COMPILER_FLAG("-Werror=format-security" CC_FORMAT_SECURITY)
54 CHECK_CXX_COMPILER_FLAG("-Werror=format-security" CXX_FORMAT_SECURITY)
56 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Wl,-as-needed -Wp,-D_GLIBCXX_ASSERTIONS" )
57 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Wl,-as-needed -Wp,-D_GLIBCXX_ASSERTIONS" )
59 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility-inlines-hidden -Woverloaded-virtual -Wnon-virtual-dtor" )
61 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3 -DZYPP_NDEBUG" )
62 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DZYPP_NDEBUG" )
64 IF(${CC_FORMAT_SECURITY})
65 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security")
66 ENDIF(${CC_FORMAT_SECURITY})
68 IF(${CXX_FORMAT_SECURITY})
69 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
70 ENDIF(${CXX_FORMAT_SECURITY})
72 INCLUDE(CheckFunctionExists)
73 CHECK_FUNCTION_EXISTS(pipe2 PIPE2_FOUND)
75 ADD_DEFINITIONS(-DHAVE_PIPE2)
78 ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
79 ADD_DEFINITIONS( -DVERSION="${VERSION}" )
80 SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
81 SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" )
83 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
88 FOREACH( loop_var ${ARGV} )
89 SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_AUTO_TEST_MAIN=\"\" " )
90 ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc )
91 TARGET_LINK_LIBRARIES( ${loop_var}_test zypp ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} zypp_test_utils)
92 ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test --catch_system_errors=no)
93 ENDFOREACH( loop_var )
96 ####################################################################
97 # prefer packages using the same install prefix as we do
98 SET(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX} usr/localX /usr/local /usr)
100 IF ( ENABLE_USE_THREADS )
101 SET( CMAKE_THREAD_PREFER_PTHREAD TRUE )
102 FIND_PACKAGE( Threads REQUIRED )
103 IF ( CMAKE_USE_PTHREADS_INIT )
104 MESSAGE( STATUS "May use threads." )
105 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -DZYPP_USE_THREADS" )
106 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DZYPP_USE_THREADS" )
107 ENDIF ( CMAKE_USE_PTHREADS_INIT )
108 ENDIF ( ENABLE_USE_THREADS )
110 FIND_PACKAGE(Rpm REQUIRED)
112 MESSAGE( FATAL_ERROR " rpm-devel not found" )
113 ELSE ( NOT RPM_FOUND)
114 INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
115 # fix includes not relative to rpm
116 INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
117 if ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
118 MESSAGE( STATUS "rpm found: enable rpm-4 compat interface." )
119 ADD_DEFINITIONS(-D_RPM_5)
120 endif ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
121 ENDIF( NOT RPM_FOUND)
123 FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options unit_test_framework thread)
125 MESSAGE( STATUS "boost found: includes in ${Boost_INCLUDE_DIRS}, library in ${Boost_LIBRARY_DIRS}")
126 INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
127 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
130 FIND_PACKAGE(Gettext REQUIRED)
132 MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
133 INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
135 MESSAGE( FATAL_ERROR "Gettext not found" )
136 ENDIF (GETTEXT_FOUND)
138 FIND_PACKAGE(CURL REQUIRED)
140 MESSAGE( FATAL_ERROR " curl not found" )
141 ELSE ( NOT CURL_FOUND)
142 INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
143 ENDIF( NOT CURL_FOUND)
145 FIND_PACKAGE(LibXml2 REQUIRED)
146 IF ( NOT LIBXML2_FOUND)
147 MESSAGE( FATAL_ERROR " libxml not found" )
148 ELSE ( NOT LIBXML2_FOUND)
149 INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
150 ENDIF( NOT LIBXML2_FOUND)
152 FIND_PACKAGE(ZLIB REQUIRED)
154 MESSAGE( FATAL_ERROR " zlib not found" )
155 ELSE ( NOT ZLIB_FOUND)
156 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
157 ENDIF( NOT ZLIB_FOUND)
159 #SET(LibSolv_USE_STATIC_LIBS ON)
160 FIND_PACKAGE(LibSolv REQUIRED ext)
161 IF ( NOT LibSolv_FOUND )
162 MESSAGE( FATAL_ERROR " libsolv not found" )
164 INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
167 FIND_PACKAGE(Gpgme REQUIRED)
168 IF ( NOT GPGME_PTHREAD_FOUND )
169 MESSAGE( FATAL_ERROR " gpgme not found" )
171 INCLUDE_DIRECTORIES( ${GPGME_INCLUDES} )
172 LINK_DIRECTORIES(${GPGME_LIBRARY_DIR})
175 FIND_PACKAGE(OpenSSL REQUIRED)
178 IF ( NOT UDEV_FOUND )
181 MESSAGE(WARNING "No udev or HAL. CD device detection will be poor")
182 ELSE ( NOT HAL_FOUND )
183 ADD_DEFINITIONS(-DHAVE_HAL)
184 INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR})
185 INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR}/hal)
186 # HAL requires working dbus
187 FIND_PACKAGE(Dbus REQUIRED)
189 INCLUDE_DIRECTORIES(${DBUS_INCLUDE_DIR})
190 INCLUDE_DIRECTORIES(${DBUS_ARCH_INCLUDE_DIR})
192 ENDIF ( NOT HAL_FOUND )
193 ELSE ( NOT UDEV_FOUND )
194 ADD_DEFINITIONS(-DHAVE_UDEV)
195 ENDIF ( NOT UDEV_FOUND )
197 IF( DISABLE_LIBPROXY )
198 MESSAGE( STATUS "libproxy support disabled" )
199 ELSE( DISABLE_LIBPROXY )
200 FIND_PACKAGE(libproxy)
201 IF ( NOT LIBPROXY_FOUND )
202 MESSAGE( STATUS "libproxy not found" )
203 ELSE ( NOT LIBPROXY_FOUND )
204 INCLUDE_DIRECTORIES( ${LIBPROXY_INCLUDE_DIR} )
205 ADD_DEFINITIONS(-DWITH_LIBPROXY_SUPPORT)
206 ENDIF( NOT LIBPROXY_FOUND )
207 ENDIF( DISABLE_LIBPROXY )
209 FIND_PROGRAM( DOXYGEN doxygen )
211 IF ( DISABLE_AUTODOCS )
212 MESSAGE( STATUS "doxygen is not available. Can't build the documentation." )
213 ELSE ( DISABLE_AUTODOCS )
214 MESSAGE( FATAL_ERROR "doxygen not found: install doxygen to build the documentation!" )
215 ENDIF ( DISABLE_AUTODOCS )
217 MESSAGE( STATUS "doxygen found: ${DOXYGEN}" )
218 ENDIF ( NOT DOXYGEN )
220 MESSAGE(STATUS "soname: ${LIBZYPP_VERSION_INFO}")
221 MESSAGE(STATUS "version: ${VERSION}")
223 MESSAGE(STATUS "Writing pkg-config file...")
224 CONFIGURE_FILE(${LIBZYPP_SOURCE_DIR}/libzypp.pc.cmake ${LIBZYPP_BINARY_DIR}/libzypp.pc @ONLY)
225 INSTALL( FILES ${LIBZYPP_BINARY_DIR}/libzypp.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
227 MESSAGE(STATUS "FindZypp.cmake will be installed in ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules")
228 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/FindZypp.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
229 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/ZyppCommon.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
231 ####################################################################
233 # (don't forget to mention them in the .spec file)
234 ####################################################################
236 MESSAGE(STATUS "zypp.conf will be installed in ${SYSCONFDIR}/zypp")
237 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp.conf DESTINATION ${SYSCONFDIR}/zypp )
240 MESSAGE(STATUS "systemCheck will be installed in ${SYSCONFDIR}/zypp")
241 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/systemCheck DESTINATION ${SYSCONFDIR}/zypp )
243 # logrotate config file
244 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp-history.lr DESTINATION ${SYSCONFDIR}/logrotate.d )
246 ####################################################################
248 ####################################################################
250 ADD_SUBDIRECTORY( zypp )
251 # do not build devel by default
252 ADD_SUBDIRECTORY( devel EXCLUDE_FROM_ALL )
253 ADD_SUBDIRECTORY( tools )
254 ADD_SUBDIRECTORY( doc )
255 ADD_SUBDIRECTORY( vendor )
257 IF ( ENABLE_BUILD_TRANS )
258 ADD_SUBDIRECTORY( po )
259 ELSE ( ENABLE_BUILD_TRANS )
260 ADD_SUBDIRECTORY( po EXCLUDE_FROM_ALL )
261 ENDIF ( ENABLE_BUILD_TRANS )
263 IF ( ENABLE_BUILD_TESTS )
264 ADD_SUBDIRECTORY( tests )
265 ELSE ( ENABLE_BUILD_TESTS )
266 ADD_SUBDIRECTORY( tests EXCLUDE_FROM_ALL )
267 ENDIF ( ENABLE_BUILD_TESTS )