blob: e479f514e150447cd6262d52962017b9c53f1d1f [file] [log] [blame]
Andreas Schuh58345b12015-04-03 16:12:38 +01001cmake_minimum_required (VERSION 2.8.12 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 Schuhabe4b102016-03-01 16:01:45 +000018set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues")
unknown3d142b82014-03-19 15:27:08 +010019
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000020project (${PACKAGE_NAME} CXX)
Andreas Schuh51f1db72015-03-24 15:36:26 +000021if (CMAKE_VERSION VERSION_LESS 100)
22 # C language still needed because the following required CMake modules
23 # (or their dependencies, respectively) are not correctly handling
24 # the case where only CXX is enabled.
25 # - CheckTypeSize.cmake (fixed in CMake 3.1, cf. http://www.cmake.org/Bug/view.php?id=14056)
26 # - FindThreads.cmake (--> CheckIncludeFiles.cmake <--)
27 enable_language (C)
28endif ()
unknown3d142b82014-03-19 15:27:08 +010029
30version_numbers (
31 ${PACKAGE_VERSION}
32 PACKAGE_VERSION_MAJOR
33 PACKAGE_VERSION_MINOR
34 PACKAGE_VERSION_PATCH
35)
36
Andreas Schuhcd7aece2014-05-02 11:12:05 +010037set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}")
Andreas Schuhbf889782014-05-01 20:16:16 +010038
unknown3d142b82014-03-19 15:27:08 +010039# ----------------------------------------------------------------------------
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000040# options
Andreas Schuh376ef822014-07-17 11:21:36 +010041if (NOT GFLAGS_NAMESPACE)
42 # maintain binary backwards compatibility with gflags library version <= 2.0,
43 # but at the same time enable the use of the preferred new "gflags" namespace
Andreas Schuh2a40e192015-03-24 12:33:52 +000044 set (GFLAGS_NAMESPACE "google;${PACKAGE_NAME}" CACHE STRING "Name(s) of library namespace (separate multiple options by semicolon)")
45 mark_as_advanced (GFLAGS_NAMESPACE)
Andreas Schuh376ef822014-07-17 11:21:36 +010046endif ()
Andreas Schuh659b4402014-05-02 14:56:58 +010047set (GFLAGS_NAMESPACE_SECONDARY "${GFLAGS_NAMESPACE}")
48list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY)
49if (NOT GFLAGS_NAMESPACE_SECONDARY)
50 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 +000051endif ()
Andreas Schuh659b4402014-05-02 14:56:58 +010052foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
53 if (NOT ns MATCHES "^[a-zA-Z][a-zA-Z0-9_]*$")
54 message (FATAL_ERROR "GFLAGS_NAMESPACE contains invalid namespace identifier: ${ns}")
55 endif ()
56endforeach ()
57list (GET GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE)
58list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0)
unknown3d142b82014-03-19 15:27:08 +010059
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000060option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
61option (BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF)
62option (BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON)
63option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON)
64option (BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF)
65option (BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000066option (INSTALL_HEADERS "Request packaging of headers and other development files." ON)
unknown3d142b82014-03-19 15:27:08 +010067
68mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000069mark_as_advanced (CMAKE_CONFIGURATION_TYPES
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000070 BUILD_STATIC_LIBS
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000071 INSTALL_HEADERS)
unknown3d142b82014-03-19 15:27:08 +010072if (APPLE)
73 mark_as_advanced(CMAKE_OSX_ARCHITECTURES
74 CMAKE_OSX_DEPLOYMENT_TARGET
75 CMAKE_OSX_SYSROOT)
76endif ()
77
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000078if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
79 set (BUILD_STATIC_LIBS ON)
80endif ()
81if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
82 message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")
83endif ()
84
85if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
86 set_property (CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
87endif ()
88
Andreas Schuh659b4402014-05-02 14:56:58 +010089if (NOT GFLAGS_INCLUDE_DIR)
Andreas Schuh2a40e192015-03-24 12:33:52 +000090 set (GFLAGS_INCLUDE_DIR "${PACKAGE_NAME}" CACHE STRING "Name of include directory of installed header files")
91 mark_as_advanced (GFLAGS_INCLUDE_DIR)
Andreas Schuh659b4402014-05-02 14:56:58 +010092else ()
93 if (IS_ABSOLUTE GFLAGS_INCLUDE_DIR)
94 message (FATAL_ERROR "GFLAGS_INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include")
95 endif ()
96 if (GFLAGS_INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
97 message (FATAL_ERROR "GFLAGS_INCLUDE_DIR must not start with parent directory reference (../)")
98 endif ()
99endif ()
100
unknown3d142b82014-03-19 15:27:08 +0100101# ----------------------------------------------------------------------------
102# system checks
103include (CheckTypeSize)
104include (CheckIncludeFileCXX)
105include (CheckCXXSymbolExists)
106
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000107if (WIN32 AND NOT CYGWIN)
108 set (OS_WINDOWS 1)
109else ()
110 set (OS_WINDOWS 0)
111endif ()
112
unknown3d142b82014-03-19 15:27:08 +0100113if (MSVC)
114 set (HAVE_SYS_TYPES_H 1)
115 set (HAVE_STDINT_H 1)
116 set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
117 set (HAVE_INTTYPES_H 0)
118 set (HAVE_UNISTD_H 0)
119 set (HAVE_SYS_STAT_H 1)
Andreas Schuh92425782014-03-19 17:15:36 +0000120 set (HAVE_SHLWAPI_H 1)
unknown3d142b82014-03-19 15:27:08 +0100121else ()
122 foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
123 string (TOUPPER "${fname}" FNAME)
Andreas Schuh92425782014-03-19 17:15:36 +0000124 string (REPLACE "/" "_" FNAME "${FNAME}")
unknown3d142b82014-03-19 15:27:08 +0100125 if (NOT HAVE_${FNAME}_H)
126 check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
127 endif ()
128 endforeach ()
Andreas Schuhddc53572014-03-19 17:32:23 +0000129 # the following are used in #if directives not #ifdef
unknown3d142b82014-03-19 15:27:08 +0100130 bool_to_int (HAVE_STDINT_H)
131 bool_to_int (HAVE_SYS_TYPES_H)
132 bool_to_int (HAVE_INTTYPES_H)
Andreas Schuh92425782014-03-19 17:15:36 +0000133 if (NOT HAVE_FNMATCH_H AND OS_WINDOWS)
134 check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H)
135 endif ()
unknown3d142b82014-03-19 15:27:08 +0100136endif ()
137
138set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
139set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")
140mark_as_advanced (GFLAGS_INTTYPES_FORMAT)
141if (NOT GFLAGS_INTTYPES_FORMAT)
142 set (TYPES uint32_t u_int32_t)
143 if (MSVC)
144 list (INSERT TYPES 0 __int32)
145 endif ()
146 foreach (type IN LISTS TYPES)
147 check_type_size (${type} ${type} LANGUAGE CXX)
148 if (HAVE_${type})
149 break ()
150 endif ()
151 endforeach ()
152 if (HAVE_uint32_t)
153 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)
154 elseif (HAVE_u_int32_t)
155 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)
156 elseif (HAVE___int32)
157 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
158 else ()
159 mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)
160 message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
161 " Neither uint32_t, u_int32_t, nor __int32 seem to be available."
162 " Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
163 endif ()
164endif ()
165# use of special characters in strings to circumvent bug #0008226
166if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")
167 set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
168endif ()
169if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
170 message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
171endif ()
172set (GFLAGS_INTTYPES_FORMAT_C99 0)
173set (GFLAGS_INTTYPES_FORMAT_BSD 0)
174set (GFLAGS_INTTYPES_FORMAT_VC7 0)
175set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)
176
177if (MSVC)
178 set (HAVE_strtoll 0)
179 set (HAVE_strtoq 0)
180else ()
Andreas Schuh0b116eb2014-03-19 15:56:26 +0000181 check_cxx_symbol_exists (strtoll stdlib.h HAVE_STRTOLL)
182 if (NOT HAVE_STRTOLL)
183 check_cxx_symbol_exists (strtoq stdlib.h HAVE_STRTOQ)
184 endif ()
unknown3d142b82014-03-19 15:27:08 +0100185endif ()
186
187set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
Andreas Schuh51f1db72015-03-24 15:36:26 +0000188find_package (Threads)
unknown3d142b82014-03-19 15:27:08 +0100189if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
190 set (HAVE_PTHREAD 1)
191 check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
192else ()
193 set (HAVE_PTHREAD 0)
194endif ()
195
196if (UNIX AND NOT HAVE_PTHREAD AND BUILD_gflags_LIB)
197 if (CMAKE_HAVE_PTHREAD_H)
198 set (what "library")
199 else ()
200 set (what ".h file")
201 endif ()
202 message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
203 "\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
204 "\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
205endif ()
206
207# ----------------------------------------------------------------------------
208# source files - excluding root subdirectory and/or .in suffix
209set (PUBLIC_HDRS
210 "gflags.h"
211 "gflags_declare.h"
212 "gflags_completions.h"
213)
214
Andreas Schuh659b4402014-05-02 14:56:58 +0100215if (GFLAGS_NAMESPACE_SECONDARY)
216 set (INCLUDE_GFLAGS_NS_H "// Import gflags library symbols into alternative/deprecated namespace(s)")
217 foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
218 string (TOUPPER "${ns}" NS)
219 set (gflags_ns_h "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/gflags_${ns}.h")
220 configure_file ("${PROJECT_SOURCE_DIR}/src/gflags_ns.h.in" "${gflags_ns_h}" @ONLY)
221 list (APPEND PUBLIC_HDRS "${gflags_ns_h}")
222 set (INCLUDE_GFLAGS_NS_H "${INCLUDE_GFLAGS_NS_H}\n#include \"gflags_${ns}.h\"")
223 endforeach ()
224else ()
225 set (INCLUDE_GFLAGS_NS_H)
226endif ()
227
unknown3d142b82014-03-19 15:27:08 +0100228set (PRIVATE_HDRS
229 "config.h"
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000230 "util.h"
231 "mutex.h"
unknown3d142b82014-03-19 15:27:08 +0100232)
233
234set (GFLAGS_SRCS
235 "gflags.cc"
236 "gflags_reporting.cc"
237 "gflags_completions.cc"
238)
239
Andreas Schuh41181662014-03-19 16:46:56 +0000240if (OS_WINDOWS)
unknown3d142b82014-03-19 15:27:08 +0100241 list (APPEND PRIVATE_HDRS "windows_port.h")
242 list (APPEND GFLAGS_SRCS "windows_port.cc")
243endif ()
244
245# ----------------------------------------------------------------------------
246# configure source files
247if (CMAKE_COMPILER_IS_GNUCXX)
248 set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
249else ()
250 set (GFLAGS_ATTRIBUTE_UNUSED)
251endif ()
252
Andreas Schuh6040eac2014-03-25 15:29:56 +0000253# whenever we build a shared library (DLL on Windows), configure the public
254# headers of the API for use of this library rather than the optionally
255# also build statically linked library; users can override GFLAGS_DLL_DECL
256if (BUILD_SHARED_LIBS)
257 set (GFLAGS_IS_A_DLL 1)
258else ()
259 set (GFLAGS_IS_A_DLL 0)
260endif ()
261
unknown3d142b82014-03-19 15:27:08 +0100262configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
263configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
264configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
265
266# ----------------------------------------------------------------------------
267# output directories
268set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
269set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
270set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
271
272# ----------------------------------------------------------------------------
Andreas Schuh76c53b72015-03-24 14:44:12 +0000273# installation directories
274if (OS_WINDOWS)
275 set (RUNTIME_INSTALL_DIR Bin)
276 set (LIBRARY_INSTALL_DIR Lib)
277 set (INCLUDE_INSTALL_DIR Include)
278 set (CONFIG_INSTALL_DIR CMake)
279else ()
280 set (RUNTIME_INSTALL_DIR bin)
281 # The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora
282 # package maintainers. Also package maintainers of other distribution
283 # packages need to be able to specify the name of the library directory.
284 if (NOT LIB_INSTALL_DIR)
285 set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
286 endif ()
287 set (LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}"
288 CACHE PATH "Directory of installed libraries, e.g., \"lib64\""
289 )
290 mark_as_advanced (LIBRARY_INSTALL_DIR)
291 set (INCLUDE_INSTALL_DIR include)
292 set (CONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME})
293endif ()
294
295# ----------------------------------------------------------------------------
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000296# add library targets
297set (TARGETS)
298# static vs. shared
299foreach (TYPE IN ITEMS STATIC SHARED)
300 if (BUILD_${TYPE}_LIBS)
Arnaud Farbosd78b00d2015-11-05 12:03:37 -0800301 string (TOLOWER "${TYPE}" type)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000302 # 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 ()
Andreas Schuh6bd636c2016-02-29 17:58:46 +0000308 # filename suffix for static libraries on Windows
309 if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^STATIC$")
310 set (type_suffix "_${type}")
311 else ()
312 set (type_suffix "")
313 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000314 # multi-threaded vs. single-threaded
315 foreach (opts IN ITEMS "" _nothreads)
316 if (BUILD_gflags${opts}_LIB)
317 add_library (gflags${opts}-${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
Andreas Schuh58345b12015-04-03 16:12:38 +0100318 set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>")
319 if (INSTALL_HEADERS)
320 list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")
Andreas Schuh76c53b72015-03-24 14:44:12 +0000321 endif ()
Andreas Schuh58345b12015-04-03 16:12:38 +0100322 target_include_directories (gflags${opts}-${type}
323 PUBLIC "${include_dirs}"
324 PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}"
325 )
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000326 if (opts MATCHES "nothreads")
Sam Cleggb572a722016-01-29 16:09:43 -0800327 set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL};NO_THREADS")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000328 else ()
329 set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL}")
Andreas Schuhbf139ea2014-03-20 03:04:44 +0000330 if (CMAKE_USE_PTHREADS_INIT)
331 target_link_libraries (gflags${opts}-${type} ${CMAKE_THREAD_LIBS_INIT})
332 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000333 endif ()
334 set_target_properties (
335 gflags${opts}-${type} PROPERTIES COMPILE_DEFINITIONS "${defines}"
Andreas Schuh6bd636c2016-02-29 17:58:46 +0000336 OUTPUT_NAME "gflags${opts}${type_suffix}"
Andreas Schuhcd7aece2014-05-02 11:12:05 +0100337 VERSION "${PACKAGE_VERSION}"
338 SOVERSION "${PACKAGE_SOVERSION}"
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000339 )
340 if (HAVE_SHLWAPI_H)
341 target_link_libraries (gflags${opts}-${type} shlwapi.lib)
342 endif ()
343 if (NOT TARGET gflags${opts})
344 add_custom_target (gflags${opts})
345 endif ()
346 add_dependencies (gflags${opts} gflags${opts}-${type})
347 list (APPEND TARGETS gflags${opts}-${type})
348 endif ()
349 endforeach ()
Andreas Schuhddc53572014-03-19 17:32:23 +0000350 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000351endforeach ()
unknown3d142b82014-03-19 15:27:08 +0100352
353# ----------------------------------------------------------------------------
Andreas Schuh76c53b72015-03-24 14:44:12 +0000354# installation rules
unknown3d142b82014-03-19 15:27:08 +0100355file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
356configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
357configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
358
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000359install (TARGETS ${TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
360if (INSTALL_HEADERS)
Andreas Schuhaff8ef82014-03-27 01:09:20 +0000361 install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR})
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000362 install (
363 FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
364 RENAME ${PACKAGE_NAME}-config.cmake
365 DESTINATION ${CONFIG_INSTALL_DIR}
366 )
367 install (
368 FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
369 DESTINATION ${CONFIG_INSTALL_DIR}
370 )
371 install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
372 if (UNIX)
373 install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
374 endif ()
unknown3d142b82014-03-19 15:27:08 +0100375endif ()
376
377# ----------------------------------------------------------------------------
378# support direct use of build tree
379set (INSTALL_PREFIX_REL2CONFIG_DIR .)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000380export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
unknown3d142b82014-03-19 15:27:08 +0100381export (PACKAGE gflags)
382configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
383
384# ----------------------------------------------------------------------------
385# testing - MUST follow the generation of the build tree config file
unknown3d142b82014-03-19 15:27:08 +0100386if (BUILD_TESTING)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000387 include (CTest)
unknown3d142b82014-03-19 15:27:08 +0100388 enable_testing ()
389 add_subdirectory (test)
390endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000391
392# ----------------------------------------------------------------------------
393# packaging
394if (BUILD_PACKAGING)
395
396 if (NOT BUILD_SHARED_LIBS AND NOT INSTALL_HEADERS)
397 message (WARNING "Package will contain static libraries without headers!"
398 "\nRecommended options for generation of runtime package:"
399 "\n BUILD_SHARED_LIBS=ON"
400 "\n BUILD_STATIC_LIBS=OFF"
401 "\n INSTALL_HEADERS=OFF"
402 "\nRecommended options for generation of development package:"
403 "\n BUILD_SHARED_LIBS=ON"
404 "\n BUILD_STATIC_LIBS=ON"
405 "\n INSTALL_HEADERS=ON")
406 endif ()
407
408 # default package generators
409 if (APPLE)
410 set (PACKAGE_GENERATOR "PackageMaker")
411 set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
412 elseif (UNIX)
413 set (PACKAGE_GENERATOR "DEB;RPM")
414 set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
415 else ()
416 set (PACKAGE_GENERATOR "ZIP")
417 set (PACKAGE_SOURCE_GENERATOR "ZIP")
418 endif ()
419
420 # used package generators
421 set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).")
422 set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
423 mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR)
424
Andreas Schuh64ac2e32015-03-24 16:21:44 +0000425 # some package generators (e.g., PackageMaker) do not allow .md extension
426 configure_file ("${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_BINARY_DIR}/README.txt" COPYONLY)
427
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000428 # common package information
Andreas Schuhfc6e0792014-03-20 04:09:02 +0000429 set (CPACK_PACKAGE_VENDOR "Andreas Schuh")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000430 set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com")
431 set (CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
432 set (CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}")
433 set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
434 set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
435 set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
436 set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A commandline flags library that allows for distributed flags.")
Andreas Schuha819f0f2015-03-24 16:29:31 +0000437 set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000438 set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt")
Andreas Schuha819f0f2015-03-24 16:29:31 +0000439 set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000440 set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
441 set (CPACK_OUTPUT_FILE_PREFIX packages)
442 set (CPACK_PACKAGE_RELOCATABLE TRUE)
443 set (CPACK_MONOLITHIC_INSTALL TRUE)
444
Andreas Schuhe8890f22014-03-20 04:20:15 +0000445 # RPM package information -- used in cmake/package.cmake.in also for DEB
Andreas Schuh37a9a902014-03-20 03:27:13 +0000446 set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
447 set (CPACK_RPM_PACKAGE_LICENSE "BSD")
Andreas Schuhabe4b102016-03-01 16:01:45 +0000448 set (CPACK_RPM_PACKAGE_URL "http://gflags.github.io/gflags")
Andreas Schuh37a9a902014-03-20 03:27:13 +0000449 set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
450
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000451 if (INSTALL_HEADERS)
Andreas Schuh2b8deaa2015-03-24 14:41:52 +0000452 set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000453 else ()
454 set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt")
455 endif ()
456
Andreas Schuhd6995592014-03-20 20:21:30 +0000457 # system/architecture
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000458 if (WINDOWS)
459 if (CMAKE_CL_64)
460 set (CPACK_SYSTEM_NAME "win64")
461 else ()
462 set (CPACK_SYSTEM_NAME "win32")
463 endif ()
Andreas Schuhd6995592014-03-20 20:21:30 +0000464 set (CPACK_PACKAGE_ARCHITECTURE)
Andreas Schuhef5c5472014-03-30 15:34:13 +0100465 elseif (APPLE)
466 set (CPACK_PACKAGE_ARCHITECTURE darwin)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000467 else ()
468 string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
Andreas Schuhcf40f732014-03-20 20:56:05 +0000469 if (CMAKE_CXX_FLAGS MATCHES "-m32")
470 set (CPACK_PACKAGE_ARCHITECTURE i386)
471 else ()
472 execute_process (
473 COMMAND dpkg --print-architecture
474 RESULT_VARIABLE RV
475 OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
476 )
477 if (RV EQUAL 0)
478 string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
479 else ()
480 execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
481 if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
482 set (CPACK_PACKAGE_ARCHITECTURE amd64)
483 else ()
484 set (CPACK_PACKAGE_ARCHITECTURE i386)
485 endif ()
486 endif ()
487 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000488 endif ()
489
490 # source package settings
491 set (CPACK_SOURCE_TOPLEVEL_TAG "source")
492 set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
493 set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
494
495 # default binary package settings
Andreas Schuhd6995592014-03-20 20:21:30 +0000496 set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
497 set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
498 if (CPACK_PACKAGE_ARCHITECTURE)
499 set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000500 endif ()
501
502 # generator specific configuration file
503 #
504 # allow package maintainers to use their own configuration file
505 # $ cmake -DCPACK_PROJECT_CONFIG_FILE:FILE=/path/to/package/config
506 if (NOT CPACK_PROJECT_CONFIG_FILE)
507 configure_file (
508 "${CMAKE_CURRENT_LIST_DIR}/cmake/package.cmake.in"
509 "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake" @ONLY
510 )
511 set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake")
512 endif ()
513
514 include (CPack)
515
516endif () # BUILD_PACKAGING