Imported Upstream version 14.30.0
[platform/upstream/libzypp.git] / CMakeLists.txt
1 PROJECT(LIBZYPP)
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)
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
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)
13
14 #--------------------------------------------------------------------------------
15 SET (have_system x)
16
17 IF (DEBIAN)
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)
23 ENDIF (DEBIAN)
24
25 IF (${have_system} STREQUAL x)
26   MESSAGE (STATUS "Building for SUSE")
27 ENDIF (${have_system} STREQUAL x)
28
29 IF (${have_system} STRGREATER xx)
30   MESSAGE (FATAL_ERROR "Can only build for one system type.")
31 ENDIF (${have_system} STRGREATER xx)
32 #--------------------------------------------------------------------------------
33
34 # allow name libraries by name mixed with full
35 # paths
36 if(COMMAND cmake_policy)
37   cmake_policy(SET CMP0003 NEW)
38 endif(COMMAND cmake_policy)
39
40 INCLUDE(ZyppCommon)
41 INCLUDE( ${LIBZYPP_SOURCE_DIR}/VERSION.cmake )
42
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}" )
49
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)
54
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" )
57
58 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3" )
59 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
60
61 IF(${CC_FORMAT_SECURITY})
62   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security")
63 ENDIF(${CC_FORMAT_SECURITY})
64
65 IF(${CXX_FORMAT_SECURITY})
66   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
67 ENDIF(${CXX_FORMAT_SECURITY})
68
69 INCLUDE(CheckFunctionExists)
70 CHECK_FUNCTION_EXISTS(pipe2 PIPE2_FOUND)
71 IF(${PIPE2_FOUND})
72   ADD_DEFINITIONS(-DHAVE_PIPE2)
73 ENDIF(${PIPE2_FOUND})
74
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}" )
79
80 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
81
82 INCLUDE(CPack)
83
84 MACRO(ADD_TESTS)
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 )
91 ENDMACRO(ADD_TESTS)
92
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)
96
97 FIND_PACKAGE(Rpm REQUIRED)
98 IF ( NOT RPM_FOUND)
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)
115
116 FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options unit_test_framework)
117 IF (Boost_FOUND)
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})
121 ENDIF(Boost_FOUND)
122
123 FIND_PACKAGE(Gettext REQUIRED)
124 IF (GETTEXT_FOUND)
125   MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
126   INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
127 ELSE (GETTEXT_FOUND)
128   MESSAGE( FATAL_ERROR "Gettext not found" )
129 ENDIF (GETTEXT_FOUND)
130
131 FIND_PACKAGE(Curl REQUIRED)
132 IF ( NOT CURL_FOUND)
133   MESSAGE( FATAL_ERROR " curl not found" )
134 ELSE ( NOT CURL_FOUND)
135   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
136 ENDIF( NOT CURL_FOUND)
137
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)
144
145 FIND_PACKAGE(ZLIB REQUIRED)
146 IF ( NOT ZLIB_FOUND)
147   MESSAGE( FATAL_ERROR " zlib not found" )
148 ELSE ( NOT ZLIB_FOUND)
149   INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
150 ENDIF( NOT ZLIB_FOUND)
151
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" )
156 ELSE()
157   INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
158 ENDIF()
159
160 # libsolv uses expat and has open references to it:
161 FIND_PACKAGE(EXPAT REQUIRED)
162
163 FIND_PACKAGE(OpenSSL REQUIRED)
164
165 FIND_PACKAGE(Udev)
166 IF ( NOT UDEV_FOUND )
167   FIND_PACKAGE(Hal)
168   IF ( NOT HAL_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)
176       IF(DBUS_FOUND)
177         INCLUDE_DIRECTORIES(${DBUS_INCLUDE_DIR})
178         INCLUDE_DIRECTORIES(${DBUS_ARCH_INCLUDE_DIR})
179       ENDIF(DBUS_FOUND)
180   ENDIF ( NOT HAL_FOUND )
181 ELSE ( NOT UDEV_FOUND )
182   ADD_DEFINITIONS(-DHAVE_UDEV)
183 ENDIF ( NOT UDEV_FOUND )
184
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 )
196
197 FIND_PROGRAM( DOXYGEN doxygen )
198 IF ( NOT 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 )
204 ELSE ( NOT DOXYGEN )
205   MESSAGE( STATUS "doxygen found: ${DOXYGEN}" )
206 ENDIF ( NOT DOXYGEN )
207
208 MESSAGE(STATUS "soname: ${LIBZYPP_VERSION_INFO}")
209 MESSAGE(STATUS "version: ${VERSION}")
210
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 )
214
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 )
218
219 ####################################################################
220 # config templates
221 # (don't forget to mention them in the .spec file)
222 ####################################################################
223
224 MESSAGE(STATUS "zypp.conf will be installed in ${SYSCONFDIR}/zypp")
225 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp.conf DESTINATION ${SYSCONFDIR}/zypp )
226
227 #install systemCheck
228 MESSAGE(STATUS "systemCheck will be installed in ${SYSCONFDIR}/zypp")
229 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/systemCheck DESTINATION ${SYSCONFDIR}/zypp )
230
231 # logrotate config file
232 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp-history.lr DESTINATION ${SYSCONFDIR}/logrotate.d )
233
234 ####################################################################
235 # SUBDIRECTORIES                                                   #
236 ####################################################################
237
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 )
245
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 )
251
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 )
257 INCLUDE(CTest)
258 ENABLE_TESTING()