blob: 1272770898020f31013c51218824215affd13a8a [file] [log] [blame]
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +00001cmake_minimum_required (VERSION 2.8.4 FATAL_ERROR)
unknown3d142b82014-03-19 15:27:08 +01002
Andreas Schuh7b5b0802015-03-24 14:41:10 +00003if (POLICY CMP0042)
4 cmake_policy (SET CMP0042 NEW)
5endif ()
6
unknown3d142b82014-03-19 15:27:08 +01007# ----------------------------------------------------------------------------
8# includes
9set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
unknown3d142b82014-03-19 15:27:08 +010010include (utils)
11
12# ----------------------------------------------------------------------------
13# package information
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000014set (PACKAGE_NAME "gflags")
Andreas Schuh4b771462015-03-24 14:44:57 +000015set (PACKAGE_VERSION "2.2.0")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000016set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
17set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
Andreas Schuh2b8deaa2015-03-24 14:41:52 +000018set (PACKAGE_BUGREPORT "https://github.com/schuhschuh/gflags/issues")
unknown3d142b82014-03-19 15:27:08 +010019
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000020project (${PACKAGE_NAME} CXX)
unknown3d142b82014-03-19 15:27:08 +010021
22version_numbers (
23 ${PACKAGE_VERSION}
24 PACKAGE_VERSION_MAJOR
25 PACKAGE_VERSION_MINOR
26 PACKAGE_VERSION_PATCH
27)
28
Andreas Schuhcd7aece2014-05-02 11:12:05 +010029set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}")
Andreas Schuhbf889782014-05-01 20:16:16 +010030
unknown3d142b82014-03-19 15:27:08 +010031# ----------------------------------------------------------------------------
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000032# options
Andreas Schuh376ef822014-07-17 11:21:36 +010033if (NOT GFLAGS_NAMESPACE)
34 # maintain binary backwards compatibility with gflags library version <= 2.0,
35 # but at the same time enable the use of the preferred new "gflags" namespace
Andreas Schuh2a40e192015-03-24 12:33:52 +000036 set (GFLAGS_NAMESPACE "google;${PACKAGE_NAME}" CACHE STRING "Name(s) of library namespace (separate multiple options by semicolon)")
37 mark_as_advanced (GFLAGS_NAMESPACE)
Andreas Schuh376ef822014-07-17 11:21:36 +010038endif ()
Andreas Schuh659b4402014-05-02 14:56:58 +010039set (GFLAGS_NAMESPACE_SECONDARY "${GFLAGS_NAMESPACE}")
40list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY)
41if (NOT GFLAGS_NAMESPACE_SECONDARY)
42 message (FATAL_ERROR "GFLAGS_NAMESPACE must be set to one (or more) valid C++ namespace identifier(s separated by semicolon \";\").")
Andreas Schuhaff8ef82014-03-27 01:09:20 +000043endif ()
Andreas Schuh659b4402014-05-02 14:56:58 +010044foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
45 if (NOT ns MATCHES "^[a-zA-Z][a-zA-Z0-9_]*$")
46 message (FATAL_ERROR "GFLAGS_NAMESPACE contains invalid namespace identifier: ${ns}")
47 endif ()
48endforeach ()
49list (GET GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE)
50list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0)
unknown3d142b82014-03-19 15:27:08 +010051
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000052option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
53option (BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF)
54option (BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON)
55option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON)
56option (BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF)
57option (BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF)
58option (BUILD_NC_TESTS "Request addition of negative compilation tests." OFF)
59option (INSTALL_HEADERS "Request packaging of headers and other development files." ON)
unknown3d142b82014-03-19 15:27:08 +010060
61mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000062mark_as_advanced (CMAKE_CONFIGURATION_TYPES
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000063 BUILD_STATIC_LIBS
64 BUILD_NC_TESTS
65 INSTALL_HEADERS)
unknown3d142b82014-03-19 15:27:08 +010066if (APPLE)
67 mark_as_advanced(CMAKE_OSX_ARCHITECTURES
68 CMAKE_OSX_DEPLOYMENT_TARGET
69 CMAKE_OSX_SYSROOT)
70endif ()
71
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000072if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
73 set (BUILD_STATIC_LIBS ON)
74endif ()
75if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
76 message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")
77endif ()
78
79if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
80 set_property (CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
81endif ()
82
Andreas Schuh659b4402014-05-02 14:56:58 +010083if (NOT GFLAGS_INCLUDE_DIR)
Andreas Schuh2a40e192015-03-24 12:33:52 +000084 set (GFLAGS_INCLUDE_DIR "${PACKAGE_NAME}" CACHE STRING "Name of include directory of installed header files")
85 mark_as_advanced (GFLAGS_INCLUDE_DIR)
Andreas Schuh659b4402014-05-02 14:56:58 +010086else ()
87 if (IS_ABSOLUTE GFLAGS_INCLUDE_DIR)
88 message (FATAL_ERROR "GFLAGS_INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include")
89 endif ()
90 if (GFLAGS_INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
91 message (FATAL_ERROR "GFLAGS_INCLUDE_DIR must not start with parent directory reference (../)")
92 endif ()
93endif ()
94
unknown3d142b82014-03-19 15:27:08 +010095# ----------------------------------------------------------------------------
96# system checks
97include (CheckTypeSize)
98include (CheckIncludeFileCXX)
99include (CheckCXXSymbolExists)
100
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000101if (WIN32 AND NOT CYGWIN)
102 set (OS_WINDOWS 1)
103else ()
104 set (OS_WINDOWS 0)
105endif ()
106
unknown3d142b82014-03-19 15:27:08 +0100107if (MSVC)
108 set (HAVE_SYS_TYPES_H 1)
109 set (HAVE_STDINT_H 1)
110 set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
111 set (HAVE_INTTYPES_H 0)
112 set (HAVE_UNISTD_H 0)
113 set (HAVE_SYS_STAT_H 1)
Andreas Schuh92425782014-03-19 17:15:36 +0000114 set (HAVE_SHLWAPI_H 1)
unknown3d142b82014-03-19 15:27:08 +0100115else ()
116 foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
117 string (TOUPPER "${fname}" FNAME)
Andreas Schuh92425782014-03-19 17:15:36 +0000118 string (REPLACE "/" "_" FNAME "${FNAME}")
unknown3d142b82014-03-19 15:27:08 +0100119 if (NOT HAVE_${FNAME}_H)
120 check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
121 endif ()
122 endforeach ()
Andreas Schuhddc53572014-03-19 17:32:23 +0000123 # the following are used in #if directives not #ifdef
unknown3d142b82014-03-19 15:27:08 +0100124 bool_to_int (HAVE_STDINT_H)
125 bool_to_int (HAVE_SYS_TYPES_H)
126 bool_to_int (HAVE_INTTYPES_H)
Andreas Schuh92425782014-03-19 17:15:36 +0000127 if (NOT HAVE_FNMATCH_H AND OS_WINDOWS)
128 check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H)
129 endif ()
unknown3d142b82014-03-19 15:27:08 +0100130endif ()
131
132set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
133set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")
134mark_as_advanced (GFLAGS_INTTYPES_FORMAT)
135if (NOT GFLAGS_INTTYPES_FORMAT)
136 set (TYPES uint32_t u_int32_t)
137 if (MSVC)
138 list (INSERT TYPES 0 __int32)
139 endif ()
140 foreach (type IN LISTS TYPES)
141 check_type_size (${type} ${type} LANGUAGE CXX)
142 if (HAVE_${type})
143 break ()
144 endif ()
145 endforeach ()
146 if (HAVE_uint32_t)
147 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)
148 elseif (HAVE_u_int32_t)
149 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)
150 elseif (HAVE___int32)
151 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
152 else ()
153 mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)
154 message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
155 " Neither uint32_t, u_int32_t, nor __int32 seem to be available."
156 " Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
157 endif ()
158endif ()
159# use of special characters in strings to circumvent bug #0008226
160if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")
161 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
162endif ()
163if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
164 message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
165endif ()
166set (GFLAGS_INTTYPES_FORMAT_C99 0)
167set (GFLAGS_INTTYPES_FORMAT_BSD 0)
168set (GFLAGS_INTTYPES_FORMAT_VC7 0)
169set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)
170
171if (MSVC)
172 set (HAVE_strtoll 0)
173 set (HAVE_strtoq 0)
174else ()
Andreas Schuh0b116eb2014-03-19 15:56:26 +0000175 check_cxx_symbol_exists (strtoll stdlib.h HAVE_STRTOLL)
176 if (NOT HAVE_STRTOLL)
177 check_cxx_symbol_exists (strtoq stdlib.h HAVE_STRTOQ)
178 endif ()
unknown3d142b82014-03-19 15:27:08 +0100179endif ()
180
181set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
182find_package (ThreadsCXX)
183if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
184 set (HAVE_PTHREAD 1)
185 check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
186else ()
187 set (HAVE_PTHREAD 0)
188endif ()
189
190if (UNIX AND NOT HAVE_PTHREAD AND BUILD_gflags_LIB)
191 if (CMAKE_HAVE_PTHREAD_H)
192 set (what "library")
193 else ()
194 set (what ".h file")
195 endif ()
196 message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
197 "\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
198 "\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
199endif ()
200
201# ----------------------------------------------------------------------------
202# source files - excluding root subdirectory and/or .in suffix
203set (PUBLIC_HDRS
204 "gflags.h"
205 "gflags_declare.h"
206 "gflags_completions.h"
207)
208
Andreas Schuh659b4402014-05-02 14:56:58 +0100209if (GFLAGS_NAMESPACE_SECONDARY)
210 set (INCLUDE_GFLAGS_NS_H "// Import gflags library symbols into alternative/deprecated namespace(s)")
211 foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
212 string (TOUPPER "${ns}" NS)
213 set (gflags_ns_h "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/gflags_${ns}.h")
214 configure_file ("${PROJECT_SOURCE_DIR}/src/gflags_ns.h.in" "${gflags_ns_h}" @ONLY)
215 list (APPEND PUBLIC_HDRS "${gflags_ns_h}")
216 set (INCLUDE_GFLAGS_NS_H "${INCLUDE_GFLAGS_NS_H}\n#include \"gflags_${ns}.h\"")
217 endforeach ()
218else ()
219 set (INCLUDE_GFLAGS_NS_H)
220endif ()
221
unknown3d142b82014-03-19 15:27:08 +0100222set (PRIVATE_HDRS
223 "config.h"
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000224 "util.h"
225 "mutex.h"
unknown3d142b82014-03-19 15:27:08 +0100226)
227
228set (GFLAGS_SRCS
229 "gflags.cc"
230 "gflags_reporting.cc"
231 "gflags_completions.cc"
232)
233
Andreas Schuh41181662014-03-19 16:46:56 +0000234if (OS_WINDOWS)
unknown3d142b82014-03-19 15:27:08 +0100235 list (APPEND PRIVATE_HDRS "windows_port.h")
236 list (APPEND GFLAGS_SRCS "windows_port.cc")
237endif ()
238
239# ----------------------------------------------------------------------------
240# configure source files
241if (CMAKE_COMPILER_IS_GNUCXX)
242 set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
243else ()
244 set (GFLAGS_ATTRIBUTE_UNUSED)
245endif ()
246
Andreas Schuh6040eac2014-03-25 15:29:56 +0000247# whenever we build a shared library (DLL on Windows), configure the public
248# headers of the API for use of this library rather than the optionally
249# also build statically linked library; users can override GFLAGS_DLL_DECL
250if (BUILD_SHARED_LIBS)
251 set (GFLAGS_IS_A_DLL 1)
252else ()
253 set (GFLAGS_IS_A_DLL 0)
254endif ()
255
unknown3d142b82014-03-19 15:27:08 +0100256configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
257configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
258configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
259
Andreas Schuh76c53b72015-03-24 14:44:12 +0000260# deprecated declaration of include directories for older CMake versions
261if (NOT COMMAND target_include_directories)
262 include_directories ("${PROJECT_SOURCE_DIR}/src")
263 include_directories ("${PROJECT_BINARY_DIR}/include")
264 include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}")
265endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000266
unknown3d142b82014-03-19 15:27:08 +0100267# ----------------------------------------------------------------------------
268# output directories
269set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
270set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
271set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
272
273# ----------------------------------------------------------------------------
Andreas Schuh76c53b72015-03-24 14:44:12 +0000274# installation directories
275if (OS_WINDOWS)
276 set (RUNTIME_INSTALL_DIR Bin)
277 set (LIBRARY_INSTALL_DIR Lib)
278 set (INCLUDE_INSTALL_DIR Include)
279 set (CONFIG_INSTALL_DIR CMake)
280else ()
281 set (RUNTIME_INSTALL_DIR bin)
282 # The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora
283 # package maintainers. Also package maintainers of other distribution
284 # packages need to be able to specify the name of the library directory.
285 if (NOT LIB_INSTALL_DIR)
286 set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
287 endif ()
288 set (LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}"
289 CACHE PATH "Directory of installed libraries, e.g., \"lib64\""
290 )
291 mark_as_advanced (LIBRARY_INSTALL_DIR)
292 set (INCLUDE_INSTALL_DIR include)
293 set (CONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME})
294endif ()
295
296# ----------------------------------------------------------------------------
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000297# add library targets
298set (TARGETS)
299# static vs. shared
300foreach (TYPE IN ITEMS STATIC SHARED)
301 if (BUILD_${TYPE}_LIBS)
302 # whether or not targets are a DLL
303 if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$")
304 set (GFLAGS_IS_A_DLL 1)
305 else ()
306 set (GFLAGS_IS_A_DLL 0)
307 endif ()
308 string (TOLOWER "${TYPE}" type)
309 # multi-threaded vs. single-threaded
310 foreach (opts IN ITEMS "" _nothreads)
311 if (BUILD_gflags${opts}_LIB)
312 add_library (gflags${opts}-${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
Andreas Schuh76c53b72015-03-24 14:44:12 +0000313 if (COMMAND target_include_directories)
314 target_include_directories (gflags${opts}-${type}
315 PUBLIC "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
316 PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}"
317 )
318 if (INSTALL_HEADERS)
319 target_include_directories (gflags${opts}-${type}
320 PUBLIC "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>"
321 )
322 endif ()
323 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000324 if (opts MATCHES "nothreads")
325 set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL};NOTHREADS")
326 else ()
327 set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL}")
Andreas Schuhbf139ea2014-03-20 03:04:44 +0000328 if (CMAKE_USE_PTHREADS_INIT)
329 target_link_libraries (gflags${opts}-${type} ${CMAKE_THREAD_LIBS_INIT})
330 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000331 endif ()
332 set_target_properties (
333 gflags${opts}-${type} PROPERTIES COMPILE_DEFINITIONS "${defines}"
Andreas Schuhcd7aece2014-05-02 11:12:05 +0100334 OUTPUT_NAME "gflags${opts}"
335 VERSION "${PACKAGE_VERSION}"
336 SOVERSION "${PACKAGE_SOVERSION}"
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000337 )
338 if (HAVE_SHLWAPI_H)
339 target_link_libraries (gflags${opts}-${type} shlwapi.lib)
340 endif ()
341 if (NOT TARGET gflags${opts})
342 add_custom_target (gflags${opts})
343 endif ()
344 add_dependencies (gflags${opts} gflags${opts}-${type})
345 list (APPEND TARGETS gflags${opts}-${type})
346 endif ()
347 endforeach ()
Andreas Schuhddc53572014-03-19 17:32:23 +0000348 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000349endforeach ()
unknown3d142b82014-03-19 15:27:08 +0100350
351# ----------------------------------------------------------------------------
Andreas Schuh76c53b72015-03-24 14:44:12 +0000352# installation rules
unknown3d142b82014-03-19 15:27:08 +0100353file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
354configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
355configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
356
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000357install (TARGETS ${TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
358if (INSTALL_HEADERS)
Andreas Schuhaff8ef82014-03-27 01:09:20 +0000359 install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR})
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000360 install (
361 FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
362 RENAME ${PACKAGE_NAME}-config.cmake
363 DESTINATION ${CONFIG_INSTALL_DIR}
364 )
365 install (
366 FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
367 DESTINATION ${CONFIG_INSTALL_DIR}
368 )
369 install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
370 if (UNIX)
371 install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
372 endif ()
unknown3d142b82014-03-19 15:27:08 +0100373endif ()
374
375# ----------------------------------------------------------------------------
376# support direct use of build tree
377set (INSTALL_PREFIX_REL2CONFIG_DIR .)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000378export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
unknown3d142b82014-03-19 15:27:08 +0100379export (PACKAGE gflags)
380configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
381
382# ----------------------------------------------------------------------------
383# testing - MUST follow the generation of the build tree config file
unknown3d142b82014-03-19 15:27:08 +0100384if (BUILD_TESTING)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000385 include (CTest)
unknown3d142b82014-03-19 15:27:08 +0100386 enable_testing ()
387 add_subdirectory (test)
388endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000389
390# ----------------------------------------------------------------------------
391# packaging
392if (BUILD_PACKAGING)
393
394 if (NOT BUILD_SHARED_LIBS AND NOT INSTALL_HEADERS)
395 message (WARNING "Package will contain static libraries without headers!"
396 "\nRecommended options for generation of runtime package:"
397 "\n BUILD_SHARED_LIBS=ON"
398 "\n BUILD_STATIC_LIBS=OFF"
399 "\n INSTALL_HEADERS=OFF"
400 "\nRecommended options for generation of development package:"
401 "\n BUILD_SHARED_LIBS=ON"
402 "\n BUILD_STATIC_LIBS=ON"
403 "\n INSTALL_HEADERS=ON")
404 endif ()
405
406 # default package generators
407 if (APPLE)
408 set (PACKAGE_GENERATOR "PackageMaker")
409 set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
410 elseif (UNIX)
411 set (PACKAGE_GENERATOR "DEB;RPM")
412 set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
413 else ()
414 set (PACKAGE_GENERATOR "ZIP")
415 set (PACKAGE_SOURCE_GENERATOR "ZIP")
416 endif ()
417
418 # used package generators
419 set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).")
420 set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
421 mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR)
422
423 # common package information
Andreas Schuhfc6e0792014-03-20 04:09:02 +0000424 set (CPACK_PACKAGE_VENDOR "Andreas Schuh")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000425 set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com")
426 set (CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
427 set (CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}")
428 set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
429 set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
430 set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
431 set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A commandline flags library that allows for distributed flags.")
Andreas Schuh2b8deaa2015-03-24 14:41:52 +0000432 set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_LIST_DIR}/README.md")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000433 set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt")
Andreas Schuh2b8deaa2015-03-24 14:41:52 +0000434 set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_LIST_DIR}/README.md")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000435 set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
436 set (CPACK_OUTPUT_FILE_PREFIX packages)
437 set (CPACK_PACKAGE_RELOCATABLE TRUE)
438 set (CPACK_MONOLITHIC_INSTALL TRUE)
439
Andreas Schuhe8890f22014-03-20 04:20:15 +0000440 # RPM package information -- used in cmake/package.cmake.in also for DEB
Andreas Schuh37a9a902014-03-20 03:27:13 +0000441 set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
442 set (CPACK_RPM_PACKAGE_LICENSE "BSD")
Andreas Schuh2b8deaa2015-03-24 14:41:52 +0000443 set (CPACK_RPM_PACKAGE_URL "http://schuhschuh.github.com/gflags")
Andreas Schuh37a9a902014-03-20 03:27:13 +0000444 set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
445
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000446 if (INSTALL_HEADERS)
Andreas Schuh2b8deaa2015-03-24 14:41:52 +0000447 set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000448 else ()
449 set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt")
450 endif ()
451
Andreas Schuhd6995592014-03-20 20:21:30 +0000452 # system/architecture
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000453 if (WINDOWS)
454 if (CMAKE_CL_64)
455 set (CPACK_SYSTEM_NAME "win64")
456 else ()
457 set (CPACK_SYSTEM_NAME "win32")
458 endif ()
Andreas Schuhd6995592014-03-20 20:21:30 +0000459 set (CPACK_PACKAGE_ARCHITECTURE)
Andreas Schuhef5c5472014-03-30 15:34:13 +0100460 elseif (APPLE)
461 set (CPACK_PACKAGE_ARCHITECTURE darwin)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000462 else ()
463 string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
Andreas Schuhcf40f732014-03-20 20:56:05 +0000464 if (CMAKE_CXX_FLAGS MATCHES "-m32")
465 set (CPACK_PACKAGE_ARCHITECTURE i386)
466 else ()
467 execute_process (
468 COMMAND dpkg --print-architecture
469 RESULT_VARIABLE RV
470 OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
471 )
472 if (RV EQUAL 0)
473 string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
474 else ()
475 execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
476 if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
477 set (CPACK_PACKAGE_ARCHITECTURE amd64)
478 else ()
479 set (CPACK_PACKAGE_ARCHITECTURE i386)
480 endif ()
481 endif ()
482 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000483 endif ()
484
485 # source package settings
486 set (CPACK_SOURCE_TOPLEVEL_TAG "source")
487 set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
488 set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
489
490 # default binary package settings
Andreas Schuhd6995592014-03-20 20:21:30 +0000491 set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
492 set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
493 if (CPACK_PACKAGE_ARCHITECTURE)
494 set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000495 endif ()
496
497 # generator specific configuration file
498 #
499 # allow package maintainers to use their own configuration file
500 # $ cmake -DCPACK_PROJECT_CONFIG_FILE:FILE=/path/to/package/config
501 if (NOT CPACK_PROJECT_CONFIG_FILE)
502 configure_file (
503 "${CMAKE_CURRENT_LIST_DIR}/cmake/package.cmake.in"
504 "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake" @ONLY
505 )
506 set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake")
507 endif ()
508
509 include (CPack)
510
511endif () # BUILD_PACKAGING