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 )
5 cmake_minimum_required(VERSION 2.6)
7 OPTION (ENABLE_BUILD_DOCS "Build documentation by default?" OFF)
8 OPTION (ENABLE_BUILD_TRANS "Build translation files by default?" OFF)
9 OPTION (ENABLE_BUILD_TESTS "Build and run test suite by default?" OFF)
10 OPTION (ENABLE_USE_THREADS "Enable using threads (NOT being used by threads!)?" OFF)
12 OPTION (DISABLE_LIBPROXY "Build without libproxy support even if package is installed?" OFF)
13 OPTION (DISABLE_AUTODOCS "Do not require doxygen being installed (required to build autodocs)?" OFF)
14 #--------------------------------------------------------------------------------
18 MESSAGE (STATUS "Building for Debian")
19 SET (ENABLE_BUILD_DOCS ON)
20 SET (ENABLE_BUILD_TRANS ON)
21 SET (ENABLE_BUILD_TESTS ON)
22 SET (have_system ${have_system}x)
25 IF (${have_system} STREQUAL x)
26 MESSAGE (STATUS "Building for SUSE")
27 ENDIF (${have_system} STREQUAL x)
29 IF (${have_system} STRGREATER xx)
30 MESSAGE (FATAL_ERROR "Can only build for one system type.")
31 ENDIF (${have_system} STRGREATER xx)
32 #--------------------------------------------------------------------------------
34 # allow name libraries by name mixed with full
36 if(COMMAND cmake_policy)
37 cmake_policy(SET CMP0003 NEW)
38 endif(COMMAND cmake_policy)
41 INCLUDE( ${LIBZYPP_SOURCE_DIR}/VERSION.cmake )
43 MATH( EXPR LIBZYPP_CURRENT "${LIBZYPP_MAJOR} * 100 + ${LIBZYPP_MINOR}" )
44 MATH( EXPR LIBZYPP_AGE "${LIBZYPP_MINOR} - ${LIBZYPP_COMPATMINOR}" )
45 # Libtool wanted current:patch:age
46 # But cmake is not libtool, it wants the verbatim suffix to libzypp.so
47 MATH( EXPR LIBZYPP_SO_FIRST "${LIBZYPP_CURRENT}-${LIBZYPP_AGE}" )
48 SET( VERSION "${LIBZYPP_MAJOR}.${LIBZYPP_MINOR}.${LIBZYPP_PATCH}" )
50 include(CheckCCompilerFlag)
51 include(CheckCXXCompilerFlag)
52 CHECK_C_COMPILER_FLAG("-Werror=format-security" CC_FORMAT_SECURITY)
53 CHECK_CXX_COMPILER_FLAG("-Werror=format-security" CXX_FORMAT_SECURITY)
55 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Wl,-as-needed" )
56 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Wl,-as-needed" )
58 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility-inlines-hidden -Woverloaded-virtual -Wnon-virtual-dtor" )
60 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3 -DZYPP_NDEBUG" )
61 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DZYPP_NDEBUG" )
63 IF(${CC_FORMAT_SECURITY})
64 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security")
65 ENDIF(${CC_FORMAT_SECURITY})
67 IF(${CXX_FORMAT_SECURITY})
68 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
69 ENDIF(${CXX_FORMAT_SECURITY})
71 INCLUDE(CheckFunctionExists)
72 CHECK_FUNCTION_EXISTS(pipe2 PIPE2_FOUND)
74 ADD_DEFINITIONS(-DHAVE_PIPE2)
77 ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
78 ADD_DEFINITIONS( -DVERSION="${VERSION}" )
79 SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
80 SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" )
82 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
87 FOREACH( loop_var ${ARGV} )
88 SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_AUTO_TEST_MAIN=\"\" " )
89 ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc )
90 TARGET_LINK_LIBRARIES( ${loop_var}_test zypp ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} zypp_test_utils)
91 ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test --catch_system_errors=no)
92 ENDFOREACH( loop_var )
95 ####################################################################
96 # prefer packages using the same install prefix as we do
97 SET(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX} usr/localX /usr/local /usr)
99 IF ( ENABLE_USE_THREADS )
100 SET( CMAKE_THREAD_PREFER_PTHREAD TRUE )
101 FIND_PACKAGE( Threads REQUIRED )
102 IF ( CMAKE_USE_PTHREADS_INIT )
103 MESSAGE( STATUS "May use threads." )
104 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -DZYPP_USE_THREADS" )
105 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DZYPP_USE_THREADS" )
106 ENDIF ( CMAKE_USE_PTHREADS_INIT )
107 ENDIF ( ENABLE_USE_THREADS )
109 FIND_PACKAGE(Rpm REQUIRED)
111 MESSAGE( FATAL_ERROR " rpm-devel not found" )
112 ELSE ( NOT RPM_FOUND)
113 INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
114 # fix includes not relative to rpm
115 INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
116 if ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
117 MESSAGE( STATUS "rpm found: enable rpm-4 compat interface." )
118 ADD_DEFINITIONS(-D_RPM_5)
119 elseif ( RPM_SUSPECT_VERSION STREQUAL "4.x" )
120 MESSAGE( STATUS "rpm found: use rpm-4.x interface." )
121 ADD_DEFINITIONS(-D_RPM_4_X)
122 elseif ( RPM_SUSPECT_VERSION STREQUAL "4.4" )
123 MESSAGE( STATUS "rpm found: enable rpm-4.4 legacy interface." )
124 ADD_DEFINITIONS(-D_RPM_4_4)
125 endif ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
126 ENDIF( NOT RPM_FOUND)
128 FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options unit_test_framework)
130 MESSAGE( STATUS "boost found: includes in ${Boost_INCLUDE_DIRS}, library in ${Boost_LIBRARY_DIRS}")
131 INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
132 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
135 FIND_PACKAGE(Gettext REQUIRED)
137 MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
138 INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
140 MESSAGE( FATAL_ERROR "Gettext not found" )
141 ENDIF (GETTEXT_FOUND)
143 FIND_PACKAGE(CURL REQUIRED)
145 MESSAGE( FATAL_ERROR " curl not found" )
146 ELSE ( NOT CURL_FOUND)
147 INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
148 ENDIF( NOT CURL_FOUND)
150 FIND_PACKAGE(LibXml2 REQUIRED)
151 IF ( NOT LIBXML2_FOUND)
152 MESSAGE( FATAL_ERROR " libxml not found" )
153 ELSE ( NOT LIBXML2_FOUND)
154 INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
155 ENDIF( NOT LIBXML2_FOUND)
157 FIND_PACKAGE(ZLIB REQUIRED)
159 MESSAGE( FATAL_ERROR " zlib not found" )
160 ELSE ( NOT ZLIB_FOUND)
161 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
162 ENDIF( NOT ZLIB_FOUND)
164 #SET(LibSolv_USE_STATIC_LIBS ON)
165 FIND_PACKAGE(LibSolv REQUIRED ext)
166 IF ( NOT LibSolv_FOUND )
167 MESSAGE( FATAL_ERROR " libsolv not found" )
169 INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
172 # libsolv uses expat and has open references to it:
173 FIND_PACKAGE(EXPAT REQUIRED)
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 )