Detect and compile with rpm 4.7 (bnc #444211)
[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 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -Wall -Woverloaded-virtual -Wnon-virtual-dtor -Wl,-as-needed" )
24 SET( CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   -fPIC -g -Wall -Wl,-as-needed" )
25 set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3" )
26 set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
27
28 ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
29 ADD_DEFINITIONS( -DVERSION="${VERSION}" )
30 SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
31 SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" )
32
33 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
34
35 INCLUDE(CPack)
36
37 MACRO(ADD_TESTS)
38   FOREACH( loop_var ${ARGV} )
39     SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN -DBOOST_AUTO_TEST_MAIN=\"\" " )
40     ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc )
41     TARGET_LINK_LIBRARIES( ${loop_var}_test  zypp boost_unit_test_framework zypp_test_utils)
42     ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test)
43   ENDFOREACH( loop_var )
44 ENDMACRO(ADD_TESTS)
45
46 ####################################################################
47
48 FIND_PACKAGE(Rpm REQUIRED)
49 IF ( NOT RPM_FOUND)
50   MESSAGE( FATAL_ERROR " rpm-devel not found" )
51 ELSE ( NOT RPM_FOUND)
52   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
53   # fix includes not relative to rpm
54   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
55   if (RPM_4_4_LEGACY)
56     MESSAGE( STATUS "Enable rpm 4.4 legacy interface")
57     ADD_DEFINITIONS(-D_RPM_4_4_COMPAT)
58   endif (RPM_4_4_LEGACY)
59 ENDIF( NOT RPM_FOUND)
60
61 FIND_PACKAGE(Boost REQUIRED)
62 IF (Boost_FOUND)
63   MESSAGE( STATUS "boost found: includes in ${Boost_INCLUDE_DIRS}, library in ${Boost_LIBRARY_DIRS}")
64   INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
65   LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
66 ENDIF(Boost_FOUND)
67
68 FIND_PACKAGE(Gettext REQUIRED)
69 IF (GETTEXT_FOUND)
70   MESSAGE(STATUS "Found Gettext: ${GETTEXT_SOURCE}")
71   INCLUDE_DIRECTORIES(${GETTEXT_INCLUDE_DIR})
72 ELSE (GETTEXT_FOUND)
73   MESSAGE( FATAL_ERROR "Gettext not found" )
74 ENDIF (GETTEXT_FOUND)
75
76 FIND_PACKAGE(Hal REQUIRED)
77 IF ( NOT HAL_FOUND)
78   MESSAGE( FATAL_ERROR " Hal not found" )
79 ELSE ( NOT HAL_FOUND)
80   INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR})
81 # hal/libhal-storage.h is broken grrr
82   INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR}/hal)
83 ENDIF( NOT HAL_FOUND)
84
85 FIND_PACKAGE(Dbus REQUIRED)
86 IF ( NOT DBUS_FOUND)
87   MESSAGE( FATAL_ERROR " dbus not found" )
88 ELSE ( NOT DBUS_FOUND)
89   INCLUDE_DIRECTORIES(${DBUS_INCLUDE_DIR})
90   INCLUDE_DIRECTORIES(${DBUS_ARCH_INCLUDE_DIR})
91 ENDIF( NOT DBUS_FOUND)
92
93 FIND_PACKAGE(Curl REQUIRED)
94 IF ( NOT CURL_FOUND)
95   MESSAGE( FATAL_ERROR " curl not found" )
96 ELSE ( NOT CURL_FOUND)
97   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
98 ENDIF( NOT CURL_FOUND)
99
100 FIND_PACKAGE(Libxml REQUIRED)
101 IF ( NOT LIBXML_FOUND)
102   MESSAGE( FATAL_ERROR " libxml not found" )
103 ELSE ( NOT LIBXML_FOUND)
104   INCLUDE_DIRECTORIES(${LIBXML_INCLUDE_DIR})
105 ENDIF( NOT LIBXML_FOUND)
106
107 FIND_PACKAGE(ZLIB REQUIRED)
108 IF ( NOT ZLIB_FOUND)
109   MESSAGE( FATAL_ERROR " zlib not found" )
110 ELSE ( NOT ZLIB_FOUND)
111   INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
112 ENDIF( NOT ZLIB_FOUND)
113
114 FIND_PACKAGE(Satsolver REQUIRED)
115 IF ( NOT SATSOLVER_FOUND )
116   MESSAGE( FATAL_ERROR " libsatsolver not found" )
117 ELSE ( NOT SATSOLVER_FOUND )
118   INCLUDE_DIRECTORIES( ${SATSOLVER_INCLUDE_DIR} )
119 ENDIF( NOT SATSOLVER_FOUND )
120
121 # satsolver uses expat and has open references to it:
122 FIND_PACKAGE(EXPAT REQUIRED)
123
124 FIND_PACKAGE(OpenSSL REQUIRED)
125
126 FIND_PROGRAM( DOXYGEN doxygen )
127 IF ( NOT DOXYGEN )
128   MESSAGE( FATAL_ERROR "doxygen not found: install doxygen to build the documentation." )
129 ELSE ( NOT DOXYGEN )
130   MESSAGE( STATUS "doxygen found: ${DOXYGEN}" )
131 ENDIF ( NOT DOXYGEN )
132
133 MESSAGE(STATUS "soname: ${LIBZYPP_VERSION_INFO}")
134 MESSAGE(STATUS "version: ${VERSION}")
135
136 MESSAGE(STATUS "Writing pkg-config file...")
137 CONFIGURE_FILE(${LIBZYPP_SOURCE_DIR}/libzypp.pc.cmake ${LIBZYPP_BINARY_DIR}/libzypp.pc @ONLY)
138 INSTALL( FILES ${LIBZYPP_BINARY_DIR}/libzypp.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
139
140 MESSAGE(STATUS "FindZypp.cmake will be installed in ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules")
141 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/FindZypp.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
142 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/cmake/modules/ZyppCommon.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
143
144 ####################################################################
145 # config templates
146 # (don't forget to mention them in the .spec file)
147 ####################################################################
148
149 MESSAGE(STATUS "zypp.conf will be installed in ${SYSCONFDIR}/zypp")
150 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp.conf DESTINATION ${SYSCONFDIR}/zypp )
151
152 #install systemCheck
153 MESSAGE(STATUS "systemCheck will be installed in ${SYSCONFDIR}/zypp")
154 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/systemCheck DESTINATION ${SYSCONFDIR}/zypp )
155
156 # logrotate config file
157 INSTALL( FILES ${LIBZYPP_SOURCE_DIR}/zypp-history.lr DESTINATION ${SYSCONFDIR}/logrotate.d )
158
159 ####################################################################
160 # SUBDIRECTORIES                                                   #
161 ####################################################################
162
163 ADD_SUBDIRECTORY( zypp )
164 #ADD_SUBDIRECTORY( zypp2 )
165 # do not build devel by default
166 ADD_SUBDIRECTORY( devel EXCLUDE_FROM_ALL )
167 ADD_SUBDIRECTORY( tools )
168 #ADD_SUBDIRECTORY( examples )
169 ADD_SUBDIRECTORY( po EXCLUDE_FROM_ALL )
170 ADD_SUBDIRECTORY( doc )
171 ADD_SUBDIRECTORY( vendor )
172 ADD_SUBDIRECTORY( tests EXCLUDE_FROM_ALL )
173
174 INCLUDE(CTest)
175 ENABLE_TESTING()