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