4ab1cc674b521195acea64318f6c9925ecde0aa2
[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 #IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERISION} GREATER 2.4)
9 #ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERISION} GREATER 2.4)
10
11 IF (COMMAND cmake_policy)
12   # escape preprocessor, see -DVERSION below
13   CMAKE_POLICY (SET CMP0005 OLD)
14 ENDIF (COMMAND cmake_policy)
15
16 # Library
17 IF (DEFINED LIB)
18   SET (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB}")
19 ELSE (DEFINED  LIB)
20   IF (CMAKE_SIZEOF_VOID_P MATCHES "8")
21     SET (LIB_SUFFIX "64")
22   ENDIF (CMAKE_SIZEOF_VOID_P MATCHES "8")
23   SET (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
24 ENDIF (DEFINED  LIB)
25 MESSAGE (STATUS "Libraries will be installed in ${LIB_INSTALL_DIR}")
26 SET (BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin")
27
28 ####################################################################
29 # CONFIGURATION                                                    #
30 ####################################################################
31
32 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
33 SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
34
35 INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)
36
37 FIND_PACKAGE (EXPAT REQUIRED)
38 FIND_PACKAGE (Check REQUIRED)
39 FIND_PACKAGE (ZLIB REQUIRED)
40
41 IF (FEDORA)
42 MESSAGE(STATUS "Building for Fedora")
43 ADD_DEFINITIONS (-DFEDORA)
44 ENDIF (FEDORA)
45
46 IF (DEBIAN)
47 MESSAGE (STATUS "Building for Debian")
48 ADD_DEFINITIONS (-DDEBIAN -DDEBIAN_SEMANTICS)
49 ENDIF (DEBIAN)
50
51 IF (MULTI_SEMANTICS)
52 MESSAGE (STATUS "Enabling multi dist support")
53 ADD_DEFINITIONS (-DMULTI_SEMANTICS)
54 ENDIF (MULTI_SEMANTICS)
55
56 IF (RPM5)
57 MESSAGE (STATUS "Enabling RPM 5 support")
58 ADD_DEFINITIONS (-DRPM5)
59 FIND_PACKAGE (PkgConfig REQUIRED)
60 PKG_CHECK_MODULES (RPM REQUIRED rpm)
61 INCLUDE_DIRECTORIES (${RPM_INCLUDE_DIRS})
62 ENDIF (RPM5)
63
64
65 IF (RPM5 OR NOT DEBIAN)
66 FIND_LIBRARY (RPMDB_LIBRARY NAMES rpmdb)
67
68 IF (NOT RPMDB_LIBRARY)
69 FIND_LIBRARY (RPMDB_LIBRARY NAMES rpm)
70 ENDIF (NOT RPMDB_LIBRARY)
71
72 FIND_LIBRARY (RPMIO_LIBRARY NAMES rpmio)
73 IF (RPMIO_LIBRARY)
74 SET(RPMDB_LIBRARY ${RPMIO_LIBRARY} ${RPMDB_LIBRARY})
75 ENDIF (RPMIO_LIBRARY)
76
77 IF (RPM5)
78 FIND_LIBRARY (RPMMISC_LIBRARY NAMES rpmmisc)
79 IF (RPMMISC_LIBRARY)
80 SET (RPMDB_LIBRARY ${RPMMISC_LIBRARY} ${RPMDB_LIBRARY})
81 ENDIF (RPMMISC_LIBRARY)
82 ENDIF (RPM5)
83
84 IF (RPM5 OR FEDORA)
85 FIND_LIBRARY (DB_LIBRARY NAMES db)
86 IF (DB_LIBRARY)
87 SET (RPMDB_LIBRARY ${DB_LIBRARY} ${RPMDB_LIBRARY})
88 ENDIF (DB_LIBRARY)
89 ENDIF (RPM5 OR FEDORA)
90
91 ENDIF (RPM5 OR NOT DEBIAN)
92
93 INCLUDE (CheckFunctionExists)
94 INCLUDE (TestBigEndian)
95
96 CHECK_FUNCTION_EXISTS (strchrnul HAVE_STRCHRNUL)
97 CHECK_FUNCTION_EXISTS (fopencookie HAVE_FOPENCOOKIE)
98 CHECK_FUNCTION_EXISTS (funopen HAVE_FUNOPEN)
99 TEST_BIG_ENDIAN (WORDS_BIGENDIAN)
100
101 # should create config.h with #cmakedefine instead...
102 FOREACH (VAR HAVE_STRCHRNUL HAVE_FOPENCOOKIE HAVE_FUNOPEN WORDS_BIGENDIAN)
103   IF(${VAR})
104     ADD_DEFINITIONS (-D${VAR}=1)
105   ENDIF (${VAR})
106 ENDFOREACH (VAR)
107
108 SET (PACKAGE "libsolv")
109 SET (VERSION "${LIBSOLV_MAJOR}.${LIBSOLV_MINOR}.${LIBSOLV_PATCH}")
110
111 ADD_DEFINITIONS (-D_FILE_OFFSET_BITS=64)
112 ADD_DEFINITIONS (-DVERSION=\\\"${VERSION}\\\")
113 CONFIGURE_FILE (src/satversion.h.in src/satversion.h)
114
115 SET (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Package dependency solver library")
116 SET (CPACK_PACKAGE_VENDOR "SUSE")
117 SET (CPACK_PACKAGE_VERSION_MAJOR ${LIBSOLV_MAJOR})
118 SET (CPACK_PACKAGE_VERSION_MINOR ${LIBSOLV_MINOR})
119 SET (CPACK_PACKAGE_VERSION_PATCH ${LIBSOLV_PATCH})
120 SET (CPACK_GENERATOR "TBZ2")
121 SET (CPACK_SOURCE_GENERATOR "TBZ2")
122 SET (CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE}-${VERSION}")
123 SET (CPACK_SOURCE_TOPLEVEL_TAG "Linux-Source:")
124 SET (CPACK_TOPLEVEL_TAG "Linux-Source:")
125
126 # The following components are regex's to match anywhere (unless anchored)
127 # in absolute path + filename to find files or directories to be excluded
128 # from source tarball.
129 SET (CPACK_SOURCE_IGNORE_FILES
130 # temporary files
131 "\\\\.swp$"
132 # backup files
133 "~$"
134 # eclipse files
135 "\\\\.cdtproject$"
136 "\\\\.cproject$"
137 "\\\\.project$"
138 "\\\\.settings/"
139 # others
140 "\\\\.#"
141 "/#"
142 "/build/"
143 "/_build/"
144 "/\\\\.git/"
145 # used before
146 "/\\\\.libs/"
147 "/\\\\.deps/"
148 "\\\\.o$"
149 "\\\\.lo$"
150 "\\\\.la$"
151 "Makefile$"
152 "Makefile\\\\.in$"
153 # cmake cache files
154 "DartConfiguration.tcl$"
155 "CMakeCache.txt"
156 "CMakeFiles"
157 "cmake_install.cmake$"
158 "CMakeLists.txt.auto$"
159 "CTestTestfile.cmake"
160 "CPackConfig.cmake$"
161 "CPackSourceConfig.cmake$"
162 "libsolv.spec$"
163 )
164
165 INCLUDE(CPack)
166
167 ####################################################################
168 # INCLUDES                                                         #
169 ####################################################################
170
171 #SET (CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
172 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 )
173
174 ####################################################################
175
176 MESSAGE (STATUS "Looking for modules in ${CMAKE_MODULE_PATH}")
177
178 set (CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -Werror -Wall -Wl,--as-needed")
179 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -g -O3")
180 set (CMAKE_C_FLAGS_DEBUG     "${CMAKE_C_FLAGS} -g3 -O0")
181
182 ADD_SUBDIRECTORY (src)
183 ADD_SUBDIRECTORY (ext)
184 ADD_SUBDIRECTORY (tools)
185 ADD_SUBDIRECTORY (examples)
186
187 MESSAGE (STATUS "version: ${VERSION}")
188
189 ####################################################################
190 # RPM SPEC                                                         #
191 ####################################################################
192
193 MACRO (SPECFILE)
194   MESSAGE (STATUS "Writing spec file...")
195   CONFIGURE_FILE (${CMAKE_SOURCE_DIR}/package/libsolv.spec.in ${CMAKE_BINARY_DIR}/package/libsolv.spec @ONLY)
196 ENDMACRO (SPECFILE)
197
198 SPECFILE ()
199
200 SET (AUTOBUILD_COMMAND
201   COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/package/*.tar.bz2
202   COMMAND mkdir -p _CPack_Packages/${CPACK_TOPLEVEL_TAG}
203   COMMAND ${CMAKE_MAKE_PROGRAM} package_source
204   COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.bz2 ${CMAKE_BINARY_DIR}/package
205   COMMAND ${CMAKE_COMMAND} -E remove ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.bz2
206   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/package/libsolv.changes" "${CMAKE_BINARY_DIR}/package/libsolv.changes"
207 )
208
209 ADD_CUSTOM_TARGET (srcpackage
210   ${AUTOBUILD_COMMAND}
211 )
212
213 ADD_CUSTOM_TARGET (srcpackage_local
214   ${AUTOBUILD_COMMAND}
215 )