04d6c8ef798f75d04de81b41ad9470ccd0920173
[platform/upstream/libsolv.git] / CMakeLists.txt
1 PROJECT (libsolv)
2
3 CMAKE_MINIMUM_REQUIRED (VERSION 2.4)
4
5 OPTION (ENABLE_STATIC "Build a static version of the libraries?" OFF)
6 OPTION (DISABLE_SHARED "Do not build a shared version of the libraries?" OFF)
7
8 OPTION (ENABLE_PERL "Build the perl bindings?" OFF)
9 OPTION (ENABLE_PYTHON "Build the python bindings?" OFF)
10 OPTION (ENABLE_RUBY "Build the ruby bindings?" OFF)
11
12 OPTION (USE_VENDORDIRS "Install the bindings in vendor directories?" OFF)
13
14 OPTION (ENABLE_RPMDB "Build with rpm database support?" OFF)
15 OPTION (ENABLE_PUBKEY "Build with pubkey support?" OFF)
16 OPTION (ENABLE_RPMDB_BYRPMHEADER "Build with rpmdb Header support?" OFF)
17 OPTION (ENABLE_RPMMD "Build with rpmmd repository support?" OFF)
18 OPTION (ENABLE_SUSEREPO "Build with suse repository support?" OFF)
19 OPTION (ENABLE_COMPS "Build with fedora comps support?" OFF)
20 OPTION (ENABLE_HELIXREPO "Build with helix repository support?" OFF)
21 OPTION (ENABLE_DEBIAN "Build with debian database/repository support?" OFF)
22 OPTION (ENABLE_MDKREPO "Build with mandriva/mageia repository support?" OFF)
23 OPTION (ENABLE_ARCHREPO "Build with archlinux repository support?" OFF)
24 OPTION (ENABLE_CUDFREPO "Build with cudf repository support?" OFF)
25 OPTION (ENABLE_HAIKU "Build with Haiku package support?" OFF)
26 OPTION (ENABLE_APPDATA "Build with AppStream appdata support?" OFF)
27
28 OPTION (ENABLE_LZMA_COMPRESSION "Build with lzma/xz compression support?" OFF)
29 OPTION (ENABLE_BZIP2_COMPRESSION "Build with bzip2 compression support?" OFF)
30
31 #IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERISION} GREATER 2.4)
32 #ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERISION} GREATER 2.4)
33
34 IF (COMMAND cmake_policy)
35   # escape preprocessor, see -DVERSION below
36   CMAKE_POLICY (SET CMP0005 OLD)
37 ENDIF (COMMAND cmake_policy)
38
39 # Library
40 IF (DEFINED LIB)
41   SET (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB}")
42 ELSE (DEFINED  LIB)
43   IF (CMAKE_SIZEOF_VOID_P MATCHES "8")
44     SET (LIB_SUFFIX "64")
45   ENDIF (CMAKE_SIZEOF_VOID_P MATCHES "8")
46   SET (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
47 ENDIF (DEFINED  LIB)
48 MESSAGE (STATUS "Libraries will be installed in ${LIB_INSTALL_DIR}")
49 SET (BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin")
50 SET (MAN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/man")
51 IF (IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/share/man"  AND NOT IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/man")
52   SET (MAN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/man")
53 ENDIF (IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/share/man"  AND NOT IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/man")
54 MESSAGE(STATUS "Man pages will be installed in ${MAN_INSTALL_DIR}")
55
56 ####################################################################
57 # CONFIGURATION                                                    #
58 ####################################################################
59
60 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
61 SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
62 INSTALL( FILES ${CMAKE_MODULE_PATH}/FindLibSolv.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
63
64 INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)
65
66 SET (have_system x)
67
68 IF (FEDORA)
69 MESSAGE(STATUS "Building for Fedora")
70 ADD_DEFINITIONS (-DFEDORA)
71 SET (ENABLE_RPMDB ON)
72 SET (ENABLE_RPMMD ON)
73 SET (have_system ${have_system}x)
74 ENDIF (FEDORA)
75
76 IF (DEBIAN)
77 MESSAGE (STATUS "Building for Debian")
78 ADD_DEFINITIONS (-DDEBIAN)
79 SET (ENABLE_DEBIAN ON)
80 SET (have_system ${have_system}x)
81 ENDIF (DEBIAN)
82
83 IF (SUSE)
84 MESSAGE (STATUS "Building for SUSE")
85 ADD_DEFINITIONS (-DSUSE)
86 SET (ENABLE_RPMDB ON)
87 SET (ENABLE_PUBKEY ON)
88 SET (ENABLE_RPMDB_BYRPMHEADER ON)
89 SET (ENABLE_RPMMD ON)
90 SET (ENABLE_SUSEREPO ON)
91 SET (ENABLE_HELIXREPO ON)
92 SET (have_system ${have_system}x)
93 ENDIF (SUSE)
94
95 IF (ARCHLINUX)
96 MESSAGE (STATUS "Building for Archlinux")
97 ADD_DEFINITIONS (-DARCHLINUX)
98 SET (ENABLE_ARCHREPO ON)
99 SET (have_system ${have_system}x)
100 ENDIF (ARCHLINUX)
101
102 IF (MANDRIVA)
103 MESSAGE (STATUS "Building for Mandriva/Mageia")
104 ADD_DEFINITIONS (-DMANDRIVA)
105 SET (ENABLE_MDKREPO ON)
106 SET (ENABLE_RPMDB ON)
107 SET (have_system ${have_system}x)
108 ENDIF (MANDRIVA)
109
110 IF (HAIKU)
111 MESSAGE(STATUS "Building for Haiku")
112 FIND_LIBRARY(HAIKU_BE_LIBRARY NAMES be)
113 FIND_LIBRARY(HAIKU_NETWORK_LIBRARY NAMES network)
114 FIND_LIBRARY(HAIKU_PACKAGE_LIBRARY NAMES package)
115 SET (HAIKU_SYSTEM_LIBRARIES
116     ${HAIKU_BE_LIBRARY} ${HAIKU_NETWORK_LIBRARY} ${HAIKU_PACKAGE_LIBRARY})
117 ADD_DEFINITIONS (-DHAIKU)
118 SET (ENABLE_HAIKU ON)
119 SET (have_system ${have_system}x)
120 ENDIF (HAIKU)
121
122 IF (${have_system} STREQUAL x)
123     MESSAGE (STATUS "Building for no system")
124     ADD_DEFINITIONS (-DNOSYSTEM)
125 ENDIF (${have_system} STREQUAL x)
126 IF (${have_system} STRGREATER xx)
127     MESSAGE (FATAL_ERROR "Can only compile for one system type.")
128 ENDIF (${have_system} STRGREATER xx)
129
130 IF (ENABLE_ARCHREPO)
131 SET (ENABLE_LZMA_COMPRESSION ON)
132 ENDIF (ENABLE_ARCHREPO)
133
134 FIND_PACKAGE (EXPAT REQUIRED)
135 FIND_PACKAGE (ZLIB REQUIRED)
136 IF (ENABLE_LZMA_COMPRESSION)
137 FIND_PACKAGE (LZMA REQUIRED)
138 ENDIF (ENABLE_LZMA_COMPRESSION)
139 IF (ENABLE_BZIP2_COMPRESSION)
140 FIND_PACKAGE (BZip2 REQUIRED)
141 ENDIF (ENABLE_BZIP2_COMPRESSION)
142
143 IF (RPM5)
144 MESSAGE (STATUS "Enabling RPM 5 support")
145 ADD_DEFINITIONS (-DRPM5)
146 SET (ENABLE_RPMDB ON)
147 SET (ENABLE_RPMMD ON)
148 FIND_PACKAGE (PkgConfig REQUIRED)
149 PKG_CHECK_MODULES (RPM REQUIRED rpm)
150 INCLUDE_DIRECTORIES (${RPM_INCLUDE_DIRS})
151 ENDIF (RPM5)
152
153 IF (MULTI_SEMANTICS)
154 MESSAGE (STATUS "Enabling multi dist support")
155 ADD_DEFINITIONS (-DMULTI_SEMANTICS)
156 ENDIF (MULTI_SEMANTICS)
157
158 INCLUDE (CheckIncludeFile)
159 IF (ENABLE_RPMDB)
160   FIND_LIBRARY (RPMDB_LIBRARY NAMES rpmdb)
161
162   IF (NOT RPMDB_LIBRARY)
163     FIND_LIBRARY (RPMDB_LIBRARY NAMES rpm)
164   ENDIF (NOT RPMDB_LIBRARY)
165
166   FIND_LIBRARY (RPMIO_LIBRARY NAMES rpmio)
167   IF (RPMIO_LIBRARY)
168     SET(RPMDB_LIBRARY ${RPMIO_LIBRARY} ${RPMDB_LIBRARY})
169   ENDIF (RPMIO_LIBRARY)
170
171   IF (RPM5)
172     FIND_LIBRARY (RPMMISC_LIBRARY NAMES rpmmisc)
173     IF (RPMMISC_LIBRARY)
174       SET (RPMDB_LIBRARY ${RPMMISC_LIBRARY} ${RPMDB_LIBRARY})
175     ENDIF (RPMMISC_LIBRARY)
176   ENDIF (RPM5)
177
178   # check if rpm contains a bundled berkeley db
179   CHECK_INCLUDE_FILE(rpm/db.h HAVE_RPM_DB_H)
180   IF (NOT HAVE_RPM_DB_H)
181     FIND_LIBRARY (DB_LIBRARY NAMES db)
182     IF (DB_LIBRARY)
183       SET (RPMDB_LIBRARY ${DB_LIBRARY} ${RPMDB_LIBRARY})
184     ENDIF (DB_LIBRARY)
185   ENDIF (NOT HAVE_RPM_DB_H)
186   INCLUDE (CheckLibraryExists)
187   CHECK_LIBRARY_EXISTS(rpmio pgpDigGetParams "" HAVE_PGPDIGGETPARAMS)
188 ENDIF (ENABLE_RPMDB)
189
190 IF (ENABLE_PUBKEY)
191   SET (ENABLE_PGPVRFY ON)
192 ENDIF (ENABLE_PUBKEY)
193
194 INCLUDE (CheckFunctionExists)
195 INCLUDE (TestBigEndian)
196
197 CHECK_FUNCTION_EXISTS (strchrnul HAVE_STRCHRNUL)
198 CHECK_FUNCTION_EXISTS (fopencookie HAVE_FOPENCOOKIE)
199 CHECK_FUNCTION_EXISTS (funopen HAVE_FUNOPEN)
200 TEST_BIG_ENDIAN (WORDS_BIGENDIAN)
201
202 # should create config.h with #cmakedefine instead...
203 FOREACH (VAR HAVE_STRCHRNUL HAVE_FOPENCOOKIE HAVE_FUNOPEN WORDS_BIGENDIAN
204   HAVE_RPM_DB_H HAVE_PGPDIGGETPARAMS
205   ENABLE_RPMDB ENABLE_PUBKEY ENABLE_RPMMD ENABLE_RPMDB_BYRPMHEADER ENABLE_SUSEREPO ENABLE_COMPS
206   ENABLE_HELIXREPO ENABLE_MDKREPO ENABLE_ARCHREPO ENABLE_DEBIAN ENABLE_HAIKU
207   ENABLE_LZMA_COMPRESSION ENABLE_BZIP2_COMPRESSION ENABLE_PGPVRFY ENABLE_APPDATA)
208   IF(${VAR})
209     ADD_DEFINITIONS (-D${VAR}=1)
210     SET (SWIG_FLAGS ${SWIG_FLAGS} -D${VAR})
211   ENDIF (${VAR})
212 ENDFOREACH (VAR)
213
214 SET (PACKAGE "libsolv")
215 SET (VERSION "${LIBSOLV_MAJOR}.${LIBSOLV_MINOR}.${LIBSOLV_PATCH}")
216
217 ADD_DEFINITIONS (-D_FILE_OFFSET_BITS=64)
218 ADD_DEFINITIONS (-DVERSION=\\\"${VERSION}\\\")
219 CONFIGURE_FILE (src/solvversion.h.in src/solvversion.h)
220
221 SET (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Package dependency solver library")
222 SET (CPACK_PACKAGE_VENDOR "SUSE")
223 SET (CPACK_PACKAGE_VERSION_MAJOR ${LIBSOLV_MAJOR})
224 SET (CPACK_PACKAGE_VERSION_MINOR ${LIBSOLV_MINOR})
225 SET (CPACK_PACKAGE_VERSION_PATCH ${LIBSOLV_PATCH})
226 SET (CPACK_GENERATOR "TBZ2")
227 SET (CPACK_SOURCE_GENERATOR "TBZ2")
228 SET (CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE}-${VERSION}")
229 SET (CPACK_SOURCE_TOPLEVEL_TAG "Linux-Source:")
230 SET (CPACK_TOPLEVEL_TAG "Linux-Source:")
231
232 # The following components are regex's to match anywhere (unless anchored)
233 # in absolute path + filename to find files or directories to be excluded
234 # from source tarball.
235 SET (CPACK_SOURCE_IGNORE_FILES
236 # temporary files
237 "\\\\.swp$"
238 # backup files
239 "~$"
240 # eclipse files
241 "\\\\.cdtproject$"
242 "\\\\.cproject$"
243 "\\\\.project$"
244 "\\\\.settings/"
245 # others
246 "\\\\.#"
247 "/#"
248 "/build/"
249 "/_build/"
250 "/\\\\.git/"
251 # used before
252 "/\\\\.libs/"
253 "/\\\\.deps/"
254 "\\\\.o$"
255 "\\\\.lo$"
256 "\\\\.la$"
257 "Makefile$"
258 "Makefile\\\\.in$"
259 # cmake cache files
260 "DartConfiguration.tcl$"
261 "CMakeCache.txt"
262 "CMakeFiles"
263 "cmake_install.cmake$"
264 "CMakeLists.txt.auto$"
265 "CTestTestfile.cmake"
266 "CPackConfig.cmake$"
267 "CPackSourceConfig.cmake$"
268 "libsolv.spec$"
269 )
270
271 INCLUDE(CPack)
272
273 ####################################################################
274 # INCLUDES                                                         #
275 ####################################################################
276
277 #SET (CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
278 INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/ext ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/src SYSTEM )
279
280 ####################################################################
281
282 MESSAGE (STATUS "Looking for modules in ${CMAKE_MODULE_PATH}")
283
284 set (CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -Wall")
285 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
286 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O3")
287 set (CMAKE_C_FLAGS_DEBUG     "${CMAKE_C_FLAGS} -g3 -O0")
288
289 SET (SYSTEM_LIBRARIES "-Wl,--as-needed" ${EXPAT_LIBRARY} ${ZLIB_LIBRARY})
290 IF (ENABLE_LZMA_COMPRESSION)
291 SET (SYSTEM_LIBRARIES ${SYSTEM_LIBRARIES} ${LZMA_LIBRARY})
292 ENDIF (ENABLE_LZMA_COMPRESSION)
293 IF (ENABLE_BZIP2_COMPRESSION)
294 SET (SYSTEM_LIBRARIES ${SYSTEM_LIBRARIES} ${BZIP2_LIBRARIES})
295 ENDIF (ENABLE_BZIP2_COMPRESSION)
296 IF (ENABLE_RPMDB)
297 SET (SYSTEM_LIBRARIES ${RPMDB_LIBRARY} ${SYSTEM_LIBRARIES})
298 ENDIF (ENABLE_RPMDB)
299 IF (ENABLE_HAIKU)
300 SET (SYSTEM_LIBRARIES ${HAIKU_SYSTEM_LIBRARIES} ${SYSTEM_LIBRARIES})
301 ENDIF (ENABLE_HAIKU)
302
303 ADD_SUBDIRECTORY (src)
304 ADD_SUBDIRECTORY (ext)
305 ADD_SUBDIRECTORY (tools)
306 IF (ENABLE_PERL OR ENABLE_PYTHON OR ENABLE_RUBY)
307     ADD_SUBDIRECTORY (bindings)
308 ENDIF (ENABLE_PERL OR ENABLE_PYTHON OR ENABLE_RUBY)
309 ADD_SUBDIRECTORY (examples)
310 ADD_SUBDIRECTORY (doc)
311
312 MESSAGE (STATUS "Version: ${VERSION}")
313
314 ####################################################################
315 # RPM SPEC                                                         #
316 ####################################################################
317
318 MACRO (SPECFILE)
319   MESSAGE (STATUS "Writing spec file...")
320   CONFIGURE_FILE (${CMAKE_SOURCE_DIR}/package/libsolv.spec.in ${CMAKE_BINARY_DIR}/package/libsolv.spec @ONLY)
321 ENDMACRO (SPECFILE)
322
323 SPECFILE ()
324
325 SET (AUTOBUILD_COMMAND
326   COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/package/*.tar.bz2
327   COMMAND mkdir -p _CPack_Packages/${CPACK_TOPLEVEL_TAG}
328   COMMAND ${CMAKE_MAKE_PROGRAM} package_source
329   COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.bz2 ${CMAKE_BINARY_DIR}/package
330   COMMAND ${CMAKE_COMMAND} -E remove ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.bz2
331   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/package/libsolv.changes" "${CMAKE_BINARY_DIR}/package/libsolv.changes"
332 )
333
334 ADD_CUSTOM_TARGET (srcpackage
335   ${AUTOBUILD_COMMAND}
336 )
337
338 ADD_CUSTOM_TARGET (srcpackage_local
339   ${AUTOBUILD_COMMAND}
340 )
341
342 ENABLE_TESTING()
343 ADD_SUBDIRECTORY (test)