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)
11 OPTION (DISABLE_LIBPROXY "Build without libproxy support even if package is installed?" OFF)
12 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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Woverloaded-virtual -Wnon-virtual-dtor -Wl,-as-needed -std=c++11" )
56 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Wl,-as-needed" )
58 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3" )
59 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
61 IF(${CC_FORMAT_SECURITY})
62 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security")
63 ENDIF(${CC_FORMAT_SECURITY})
65 IF(${CXX_FORMAT_SECURITY})
66 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
67 ENDIF(${CXX_FORMAT_SECURITY})
69 INCLUDE(CheckFunctionExists)
70 CHECK_FUNCTION_EXISTS(pipe2 PIPE2_FOUND)
72 ADD_DEFINITIONS(-DHAVE_PIPE2)
75 ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
76 ADD_DEFINITIONS( -DVERSION="${VERSION}" )
77 SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
78 SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" )
80 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
85 FOREACH( loop_var ${ARGV} )
86 SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_AUTO_TEST_MAIN=\"\" " )
87 ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc )
88 TARGET_LINK_LIBRARIES( ${loop_var}_test zypp boost_unit_test_framework zypp_test_utils)
89 ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test --catch_system_errors=no)
90 ENDFOREACH( loop_var )
93 ####################################################################
94 # prefer packages using the same install prefix as we do
95 SET(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX} usr/localX /usr/local /usr)
97 FIND_PACKAGE(Rpm REQUIRED)
99 MESSAGE( FATAL_ERROR " rpm-devel not found" )
100 ELSE ( NOT RPM_FOUND)
101 INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
102 # fix includes not relative to rpm
103 INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
104 if ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
105 MESSAGE( STATUS "rpm found: enable rpm-4 compat interface." )
106 ADD_DEFINITIONS(-D_RPM_5)
107 elseif ( RPM_SUSPECT_VERSION STREQUAL "4.x" )
108 MESSAGE( STATUS "rpm found: use rpm-4.x interface." )
109 ADD_DEFINITIONS(-D_RPM_4_X)
110 elseif ( RPM_SUSPECT_VERSION STREQUAL "4.4" )
111 MESSAGE( STATUS "rpm found: enable rpm-4.4 legacy interface." )
112 ADD_DEFINITIONS(-D_RPM_4_4)
113 endif ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
114 ENDIF( NOT RPM_FOUND)
116 FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options unit_test_framework)
118 MESSAGE( STATUS "boost found: includes in ${Boost_INCLUDE_DIRS}, library in ${Boost_LIBRARY_DIRS}")
119 INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
120 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
123 FIND_PACKAGE(Gettext REQUIRED)
125 MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
126 INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
128 MESSAGE( FATAL_ERROR "Gettext not found" )
129 ENDIF (GETTEXT_FOUND)
131 FIND_PACKAGE(Curl REQUIRED)
133 MESSAGE( FATAL_ERROR " curl not found" )
134 ELSE ( NOT CURL_FOUND)
135 INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
136 ENDIF( NOT CURL_FOUND)
138 FIND_PACKAGE(Libxml REQUIRED)
139 IF ( NOT LIBXML_FOUND)
140 MESSAGE( FATAL_ERROR " libxml not found" )
141 ELSE ( NOT LIBXML_FOUND)
142 INCLUDE_DIRECTORIES(${LIBXML_INCLUDE_DIR})
143 ENDIF( NOT LIBXML_FOUND)
145 FIND_PACKAGE(ZLIB REQUIRED)
147 MESSAGE( FATAL_ERROR " zlib not found" )
148 ELSE ( NOT ZLIB_FOUND)
149 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
150 ENDIF( NOT ZLIB_FOUND)
152 #SET(LibSolv_USE_STATIC_LIBS ON)
153 FIND_PACKAGE(LibSolv REQUIRED ext)
154 IF ( NOT LibSolv_FOUND )
155 MESSAGE( FATAL_ERROR " libsolv not found" )
157 INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
160 # libsolv uses expat and has open references to it:
161 FIND_PACKAGE(EXPAT REQUIRED)
163 FIND_PACKAGE(OpenSSL REQUIRED)
166 IF ( NOT UDEV_FOUND )
169 MESSAGE(WARNING "No udev or HAL. CD device detection will be poor")
170 ELSE ( NOT HAL_FOUND )
171 ADD_DEFINITIONS(-DHAVE_HAL)
172 INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR})
173 INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR}/hal)
174 # HAL requires working dbus
175 FIND_PACKAGE(Dbus REQUIRED)
177 INCLUDE_DIRECTORIES(${DBUS_INCLUDE_DIR})
178 INCLUDE_DIRECTORIES(${DBUS_ARCH_INCLUDE_DIR})
180 ENDIF ( NOT HAL_FOUND )
181 ELSE ( NOT UDEV_FOUND )
182 ADD_DEFINITIONS(-DHAVE_UDEV)
183 ENDIF ( NOT UDEV_FOUND )
185 IF( DISABLE_LIBPROXY )
186 MESSAGE( STATUS "libproxy support disabled" )
187 ELSE( DISABLE_LIBPROXY )
188 FIND_PACKAGE(libproxy)
189 IF ( NOT LIBPROXY_FOUND )
190 MESSAGE( STATUS "libproxy not found" )
191 ELSE ( NOT LIBPROXY_FOUND )
192 INCLUDE_DIRECTORIES( ${LIBPROXY_INCLUDE_DIR} )
193 ADD_DEFINITIONS(-D_WITH_LIBPROXY_SUPPORT_)
194 ENDIF( NOT LIBPROXY_FOUND )
195 ENDIF( DISABLE_LIBPROXY )
197 FIND_PROGRAM( DOXYGEN doxygen )
199 IF ( DISABLE_AUTODOCS )
200 MESSAGE( STATUS "doxygen is not available. Can't build the documentation." )
201 ELSE ( DISABLE_AUTODOCS )
202 MESSAGE( FATAL_ERROR "doxygen not found: install doxygen to build the documentation!" )
203 ENDIF ( DISABLE_AUTODOCS )
205 MESSAGE( STATUS "doxygen found: ${DOXYGEN}" )
206 ENDIF ( NOT DOXYGEN )
208 MESSAGE(STATUS "soname: ${LIBZYPP_VERSION_INFO}")
209 MESSAGE(STATUS "version: ${VERSION}")
211 MESSAGE(STATUS "Writing pkg-config file...")
212 CONFIGURE_FILE(${LIBZYPP_SOURCE_DIR}/libzypp.pc.cmake ${LIBZYPP_BINARY_DIR}/libzypp.pc @ONLY)
213 INSTALL( FILES ${LIBZYPP_BINARY_DIR}/libzypp.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
215 MESSAGE(STATUS "FindZypp.cmake will be installed in ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules")
216 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/FindZypp.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
217 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/ZyppCommon.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
219 ####################################################################
221 # (don't forget to mention them in the .spec file)
222 ####################################################################
224 MESSAGE(STATUS "zypp.conf will be installed in ${SYSCONFDIR}/zypp")
225 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp.conf DESTINATION ${SYSCONFDIR}/zypp )
228 MESSAGE(STATUS "systemCheck will be installed in ${SYSCONFDIR}/zypp")
229 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/systemCheck DESTINATION ${SYSCONFDIR}/zypp )
231 # logrotate config file
232 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp-history.lr DESTINATION ${SYSCONFDIR}/logrotate.d )
234 ####################################################################
236 ####################################################################
238 ADD_SUBDIRECTORY( zypp )
239 # do not build devel by default
240 ADD_SUBDIRECTORY( devel EXCLUDE_FROM_ALL )
241 ADD_SUBDIRECTORY( tools )
242 ADD_SUBDIRECTORY( examples )
243 ADD_SUBDIRECTORY( doc )
244 ADD_SUBDIRECTORY( vendor )
246 IF ( ENABLE_BUILD_TRANS )
247 ADD_SUBDIRECTORY( po )
248 ELSE ( ENABLE_BUILD_TRANS )
249 ADD_SUBDIRECTORY( po EXCLUDE_FROM_ALL )
250 ENDIF ( ENABLE_BUILD_TRANS )
252 IF ( ENABLE_BUILD_TESTS )
253 ADD_SUBDIRECTORY( tests )
254 ELSE ( ENABLE_BUILD_TESTS )
255 ADD_SUBDIRECTORY( tests EXCLUDE_FROM_ALL )
256 ENDIF ( ENABLE_BUILD_TESTS )