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