Switch to using libsolv instead of satsolver
[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 # allow name libraries by name mixed with full
8 # paths
9 if(COMMAND cmake_policy)
10   cmake_policy(SET CMP0003 NEW)
11 endif(COMMAND cmake_policy)
12
13 INCLUDE(ZyppCommon)
14 INCLUDE( ${LIBZYPP_SOURCE_DIR}/VERSION.cmake )
15
16 MATH( EXPR LIBZYPP_CURRENT "${LIBZYPP_MAJOR} * 100 + ${LIBZYPP_MINOR}" )
17 MATH( EXPR LIBZYPP_AGE     "${LIBZYPP_MINOR} - ${LIBZYPP_COMPATMINOR}" )
18 # Libtool wanted current:patch:age
19 # But cmake is not libtool, it wants the verbatim suffix to libzypp.so
20 MATH( EXPR LIBZYPP_SO_FIRST  "${LIBZYPP_CURRENT}-${LIBZYPP_AGE}" )
21 SET( VERSION "${LIBZYPP_MAJOR}.${LIBZYPP_MINOR}.${LIBZYPP_PATCH}" )
22
23 include(CheckCCompilerFlag)
24 include(CheckCXXCompilerFlag)
25 CHECK_C_COMPILER_FLAG("-Werror=format-security" CC_FORMAT_SECURITY)
26 CHECK_CXX_COMPILER_FLAG("-Werror=format-security" CXX_FORMAT_SECURITY)
27
28 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fPIC -g -Wall -Woverloaded-virtual -Wnon-virtual-dtor -Wl,-as-needed -std=c++0x" )
29 SET( CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   -fno-strict-aliasing -fPIC -g -Wall -Wl,-as-needed" )
30
31 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3" )
32 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
33
34 IF(${CC_FORMAT_SECURITY})
35   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format-security")
36 ENDIF(${CC_FORMAT_SECURITY})
37
38 IF(${CXX_FORMAT_SECURITY})
39   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
40 ENDIF(${CXX_FORMAT_SECURITY})
41
42 INCLUDE(CheckFunctionExists)
43 CHECK_FUNCTION_EXISTS(pipe2 PIPE2_FOUND)
44 IF(${PIPE2_FOUND})
45   ADD_DEFINITIONS(-DHAVE_PIPE2)
46 ENDIF(${PIPE2_FOUND})
47
48 ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
49 ADD_DEFINITIONS( -DVERSION="${VERSION}" )
50 SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
51 SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" )
52
53 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
54
55 INCLUDE(CPack)
56
57 MACRO(ADD_TESTS)
58   FOREACH( loop_var ${ARGV} )
59     SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_AUTO_TEST_MAIN=\"\" " )
60     ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc )
61     TARGET_LINK_LIBRARIES( ${loop_var}_test  zypp boost_unit_test_framework zypp_test_utils)
62     ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test --catch_system_errors=no)
63   ENDFOREACH( loop_var )
64 ENDMACRO(ADD_TESTS)
65
66 ####################################################################
67 # prefer packages using the same install prefix as we do
68 SET(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX} usr/localX /usr/local /usr)
69
70 FIND_PACKAGE(Rpm REQUIRED)
71 IF ( NOT RPM_FOUND)
72   MESSAGE( FATAL_ERROR " rpm-devel not found" )
73 ELSE ( NOT RPM_FOUND)
74   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
75   # fix includes not relative to rpm
76   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
77   if ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
78         MESSAGE( STATUS "rpm found: enable rpm-4 compat interface." )
79         ADD_DEFINITIONS(-D_RPM_5)
80   elseif ( RPM_SUSPECT_VERSION STREQUAL "4.x" )
81         MESSAGE( STATUS "rpm found: use rpm-4.x interface." )
82         ADD_DEFINITIONS(-D_RPM_4_X)
83   elseif ( RPM_SUSPECT_VERSION STREQUAL "4.4" )
84         MESSAGE( STATUS "rpm found: enable rpm-4.4 legacy interface." )
85         ADD_DEFINITIONS(-D_RPM_4_4)
86   endif ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
87 ENDIF( NOT RPM_FOUND)
88
89 FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options unit_test_framework)
90 IF (Boost_FOUND)
91   MESSAGE( STATUS "boost found: includes in ${Boost_INCLUDE_DIRS}, library in ${Boost_LIBRARY_DIRS}")
92   INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
93   LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
94 ENDIF(Boost_FOUND)
95
96 FIND_PACKAGE(Gettext REQUIRED)
97 IF (GETTEXT_FOUND)
98   MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
99   INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
100 ELSE (GETTEXT_FOUND)
101   MESSAGE( FATAL_ERROR "Gettext not found" )
102 ENDIF (GETTEXT_FOUND)
103
104 FIND_PACKAGE(Curl REQUIRED)
105 IF ( NOT CURL_FOUND)
106   MESSAGE( FATAL_ERROR " curl not found" )
107 ELSE ( NOT CURL_FOUND)
108   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
109 ENDIF( NOT CURL_FOUND)
110
111 FIND_PACKAGE(Libxml REQUIRED)
112 IF ( NOT LIBXML_FOUND)
113   MESSAGE( FATAL_ERROR " libxml not found" )
114 ELSE ( NOT LIBXML_FOUND)
115   INCLUDE_DIRECTORIES(${LIBXML_INCLUDE_DIR})
116 ENDIF( NOT LIBXML_FOUND)
117
118 FIND_PACKAGE(ZLIB REQUIRED)
119 IF ( NOT ZLIB_FOUND)
120   MESSAGE( FATAL_ERROR " zlib not found" )
121 ELSE ( NOT ZLIB_FOUND)
122   INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
123 ENDIF( NOT ZLIB_FOUND)
124
125 #SET(LibSolv_USE_STATIC_LIBS ON)
126 FIND_PACKAGE(LibSolv REQUIRED ext)
127 IF ( NOT LibSolv_FOUND )
128   MESSAGE( FATAL_ERROR " libsolv not found" )
129 ELSE()
130   INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
131 ENDIF()
132
133 # libsolv uses expat and has open references to it:
134 FIND_PACKAGE(EXPAT REQUIRED)
135
136 FIND_PACKAGE(OpenSSL REQUIRED)
137
138 FIND_PACKAGE(Udev)
139 IF ( NOT UDEV_FOUND )
140   FIND_PACKAGE(Hal)
141   IF ( NOT HAL_FOUND )
142     MESSAGE(WARNING "No udev or HAL. CD device detection will be poor")
143   ELSE ( NOT HAL_FOUND )
144       ADD_DEFINITIONS(-DHAVE_HAL)
145       INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR})
146       INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR}/hal)
147       # HAL requires working dbus
148       FIND_PACKAGE(Dbus REQUIRED)
149       IF(DBUS_FOUND)
150         INCLUDE_DIRECTORIES(${DBUS_INCLUDE_DIR})
151         INCLUDE_DIRECTORIES(${DBUS_ARCH_INCLUDE_DIR})
152       ENDIF(DBUS_FOUND)
153   ENDIF ( NOT HAL_FOUND )
154 ELSE ( NOT UDEV_FOUND )
155   ADD_DEFINITIONS(-DHAVE_UDEV)
156 ENDIF ( NOT UDEV_FOUND )
157
158 FIND_PACKAGE(libproxy)
159 IF ( NOT LIBPROXY_FOUND )
160   MESSAGE( STATUS " libproxy not found" )
161 ELSE ( NOT LIBPROXY_FOUND )
162   INCLUDE_DIRECTORIES( ${LIBPROXY_INCLUDE_DIR} )
163   ADD_DEFINITIONS(-D_WITH_LIBPROXY_SUPPORT_)
164 ENDIF( NOT LIBPROXY_FOUND )
165
166 FIND_PROGRAM( DOXYGEN doxygen )
167 IF ( NOT DOXYGEN )
168   MESSAGE( FATAL_ERROR "doxygen not found: install doxygen to build the documentation." )
169 ELSE ( NOT DOXYGEN )
170   MESSAGE( STATUS "doxygen found: ${DOXYGEN}" )
171 ENDIF ( NOT DOXYGEN )
172
173 MESSAGE(STATUS "soname: ${LIBZYPP_VERSION_INFO}")
174 MESSAGE(STATUS "version: ${VERSION}")
175
176 MESSAGE(STATUS "Writing pkg-config file...")
177 CONFIGURE_FILE(${LIBZYPP_SOURCE_DIR}/libzypp.pc.cmake ${LIBZYPP_BINARY_DIR}/libzypp.pc @ONLY)
178 INSTALL( FILES ${LIBZYPP_BINARY_DIR}/libzypp.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
179
180 MESSAGE(STATUS "FindZypp.cmake will be installed in ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules")
181 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/FindZypp.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
182 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/ZyppCommon.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
183
184 ####################################################################
185 # config templates
186 # (don't forget to mention them in the .spec file)
187 ####################################################################
188
189 MESSAGE(STATUS "zypp.conf will be installed in ${SYSCONFDIR}/zypp")
190 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp.conf DESTINATION ${SYSCONFDIR}/zypp )
191
192 #install systemCheck
193 MESSAGE(STATUS "systemCheck will be installed in ${SYSCONFDIR}/zypp")
194 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/systemCheck DESTINATION ${SYSCONFDIR}/zypp )
195
196 # logrotate config file
197 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp-history.lr DESTINATION ${SYSCONFDIR}/logrotate.d )
198
199 ####################################################################
200 # SUBDIRECTORIES                                                   #
201 ####################################################################
202
203 ADD_SUBDIRECTORY( zypp )
204 #ADD_SUBDIRECTORY( zypp2 )
205 # do not build devel by default
206 ADD_SUBDIRECTORY( devel EXCLUDE_FROM_ALL )
207 ADD_SUBDIRECTORY( tools )
208 ADD_SUBDIRECTORY( examples )
209 ADD_SUBDIRECTORY( po EXCLUDE_FROM_ALL )
210 ADD_SUBDIRECTORY( doc )
211 ADD_SUBDIRECTORY( vendor )
212 ADD_SUBDIRECTORY( tests EXCLUDE_FROM_ALL )
213
214 INCLUDE(CTest)
215 ENABLE_TESTING()