blob: 40d8d77290e14171b896181c1aeff807633a26ca [file] [log] [blame]
Andreas Schuh91e16ee2016-03-01 20:03:43 +00001## CMake configuration file of gflags project
2##
3## This CMakeLists.txt defines some gflags specific configuration variables
4## using the "gflags_define" utility macro. The default values of these variables
5## can be overridden either on the CMake command-line using the -D option of
6## the cmake command or in a super-project which includes the gflags source
7## tree by setting the GFLAGS_<varname> CMake variables before adding the
8## gflags source directory via CMake's "add_subdirectory" command. Only when
9## the non-cached variable GFLAGS_IS_SUBPROJECT has a value equivalent to FALSE,
10## these configuration variables are added to the CMake cache so they can be
11## edited in the CMake GUI. By default, GFLAGS_IS_SUBPROJECT is set to TRUE when
12## the CMAKE_SOURCE_DIR is not identical to the directory of this CMakeLists.txt
13## file, i.e., the top-level directory of the gflags project source tree.
14##
15## When this project is a subproject (GFLAGS_IS_SUBPROJECT is TRUE), the default
16## settings are such that only the static single-threaded library is built without
17## installation of the gflags files. The "gflags" target is in this case an ALIAS
Andreas Schuh7a21c162016-03-01 21:04:10 +000018## library target for the "gflags_nothreads_static" library target. Targets which
Andreas Schuh91e16ee2016-03-01 20:03:43 +000019## depend on the gflags library should link to the "gflags" library target.
20##
21## Example CMakeLists.txt of user project which requires separate gflags installation:
22## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
23##
24## project(Foo)
25##
26## find_package(gflags REQUIRED)
27##
28## add_executable(foo src/foo.cc)
29## target_link_libraries(foo gflags)
30##
Andreas Schuh7a21c162016-03-01 21:04:10 +000031## Example CMakeLists.txt of user project which requires separate single-threaded static gflags installation:
32## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
33##
34## project(Foo)
35##
36## find_package(gflags COMPONENTS nothreads_static)
37##
38## add_executable(foo src/foo.cc)
39## target_link_libraries(foo gflags)
40##
Andreas Schuh91e16ee2016-03-01 20:03:43 +000041## Example CMakeLists.txt of super-project which contains gflags source tree:
42## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
43##
44## project(Foo)
45##
46## add_subdirectory(gflags)
47##
48## add_executable(foo src/foo.cc)
49## target_link_libraries(foo gflags)
50##
51## Variables to configure the source files:
52## - GFLAGS_IS_A_DLL
53## - GFLAGS_NAMESPACE
54## - GFLAGS_ATTRIBUTE_UNUSED
55## - GFLAGS_INTTYPES_FORMAT
56##
57## Variables to configure the build:
58## - GFLAGS_SOVERSION
59## - GFLAGS_BUILD_SHARED_LIBS
60## - GFLAGS_BUILD_STATIC_LIBS
61## - GFLAGS_BUILD_gflags_LIB
62## - GFLAGS_BUILD_gflags_nothreads_LIB
63## - GFLAGS_BUILD_TESTING
64## - GFLAGS_BUILD_PACKAGING
65##
66## Variables to configure the installation:
67## - GFLAGS_INCLUDE_DIR
68## - GFLAGS_LIBRARY_INSTALL_DIR or LIB_INSTALL_DIR or LIB_SUFFIX
69## - GFLAGS_INSTALL_HEADERS
70## - GFLAGS_INSTALL_SHARED_LIBS
71## - GFLAGS_INSTALL_STATIC_LIBS
72
Andreas Schuh58345b12015-04-03 16:12:38 +010073cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
unknown3d142b82014-03-19 15:27:08 +010074
Andreas Schuh7b5b0802015-03-24 14:41:10 +000075if (POLICY CMP0042)
76 cmake_policy (SET CMP0042 NEW)
77endif ()
78
unknown3d142b82014-03-19 15:27:08 +010079# ----------------------------------------------------------------------------
80# includes
Andreas Schuh22ed2ce2016-11-26 15:37:45 +000081include ("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
unknown3d142b82014-03-19 15:27:08 +010082
83# ----------------------------------------------------------------------------
84# package information
Andreas Schuhc94a60e2016-11-25 08:50:08 +000085set (PACKAGE_NAME "gflags")
86set (PACKAGE_VERSION "2.2.0")
87set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
88set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
89set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues")
90set (PACKAGE_DESCRIPTION "A commandline flags library that allows for distributed flags.")
91set (PACKAGE_URL "http://gflags.github.io/gflags")
unknown3d142b82014-03-19 15:27:08 +010092
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +000093project (${PACKAGE_NAME} CXX)
Andreas Schuh20858a42016-11-26 21:55:33 +000094if (CMAKE_VERSION VERSION_LESS 3.4)
Andreas Schuh51f1db72015-03-24 15:36:26 +000095 # C language still needed because the following required CMake modules
96 # (or their dependencies, respectively) are not correctly handling
Andreas Schuh20858a42016-11-26 21:55:33 +000097 # the case where only CXX is enabled
98 # - CheckTypeSize.cmake (fixed in CMake 3.1, cf. https://cmake.org/Bug/view.php?id=14056)
99 # - FindThreads.cmake (fixed in CMake 3.4, cf. https://cmake.org/Bug/view.php?id=14905)
Andreas Schuh51f1db72015-03-24 15:36:26 +0000100 enable_language (C)
101endif ()
unknown3d142b82014-03-19 15:27:08 +0100102
103version_numbers (
104 ${PACKAGE_VERSION}
105 PACKAGE_VERSION_MAJOR
106 PACKAGE_VERSION_MINOR
107 PACKAGE_VERSION_PATCH
108)
109
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000110# shared library ABI version number, can be overridden by package maintainers
111# using -DGFLAGS_SOVERSION=XXX on the command-line
112if (GFLAGS_SOVERSION)
113 set (PACKAGE_SOVERSION "${GFLAGS_SOVERSION}")
114else ()
Andreas Schuh45341952016-03-04 10:11:39 +0000115 # TODO: Change default SOVERSION back to PACKAGE_VERSION_MAJOR with the
116 # next increase of major version number (i.e., 3.0.0 -> SOVERSION 3)
117 # The <major>.<minor> SOVERSION should be used for the 2.x releases
118 # versions only which temporarily broke the API by changing the default
119 # namespace from "google" to "gflags".
120 set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000121endif ()
122
123# when gflags is included as subproject (e.g., as Git submodule/subtree) in the source
124# tree of a project that uses it, no variables should be added to the CMake cache;
125# users may set the non-cached variable GFLAGS_IS_SUBPROJECT before add_subdirectory(gflags)
126if (NOT DEFINED GFLAGS_IS_SUBPROJECT)
127 if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
128 set (GFLAGS_IS_SUBPROJECT FALSE)
129 else ()
130 set (GFLAGS_IS_SUBPROJECT TRUE)
131 endif ()
132endif ()
133
134# prefix for package variables in CMake configuration file
135string (TOUPPER "${PACKAGE_NAME}" PACKAGE_PREFIX)
Andreas Schuhbf889782014-05-01 20:16:16 +0100136
Andreas Schuh18469832016-11-24 23:15:34 +0000137# convert file path on Windows with back slashes to path with forward slashes
138# otherwise this causes an issue with the cmake_install.cmake script
139file (TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
140
unknown3d142b82014-03-19 15:27:08 +0100141# ----------------------------------------------------------------------------
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000142# options
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000143
144# maintain binary backwards compatibility with gflags library version <= 2.0,
145# but at the same time enable the use of the preferred new "gflags" namespace
146gflags_define (STRING NAMESPACE "Name(s) of library namespace (separate multiple options by semicolon)" "google;${PACKAGE_NAME}" "${PACKAGE_NAME}")
147gflags_property (NAMESPACE ADVANCED TRUE)
148set (GFLAGS_NAMESPACE_SECONDARY "${NAMESPACE}")
Andreas Schuh659b4402014-05-02 14:56:58 +0100149list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY)
150if (NOT GFLAGS_NAMESPACE_SECONDARY)
151 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 +0000152endif ()
Andreas Schuh659b4402014-05-02 14:56:58 +0100153foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
154 if (NOT ns MATCHES "^[a-zA-Z][a-zA-Z0-9_]*$")
155 message (FATAL_ERROR "GFLAGS_NAMESPACE contains invalid namespace identifier: ${ns}")
156 endif ()
157endforeach ()
158list (GET GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE)
159list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0)
unknown3d142b82014-03-19 15:27:08 +0100160
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000161# cached build options when gflags is not a subproject, otherwise non-cached CMake variables
162# usage: gflags_define(BOOL <name> <doc> <default> [<subproject default>])
163gflags_define (BOOL BUILD_SHARED_LIBS "Request build of shared libraries." OFF OFF)
164gflags_define (BOOL BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF ON)
165gflags_define (BOOL BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON OFF)
166gflags_define (BOOL BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON ON)
167gflags_define (BOOL BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF OFF)
168gflags_define (BOOL BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF OFF)
169gflags_define (BOOL INSTALL_HEADERS "Request installation of headers and other development files." ON OFF)
170gflags_define (BOOL INSTALL_SHARED_LIBS "Request installation of shared libraries." ON ON)
171gflags_define (BOOL INSTALL_STATIC_LIBS "Request installation of static libraries." ON OFF)
Andreas Schuh3886da52016-11-24 22:36:48 +0000172gflags_define (BOOL REGISTER_BUILD_DIR "Request entry of build directory in CMake's package registry." OFF OFF)
173gflags_define (BOOL REGISTER_INSTALL_PREFIX "Request entry of installed package in CMake's package registry." ON OFF)
unknown3d142b82014-03-19 15:27:08 +0100174
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000175gflags_property (BUILD_STATIC_LIBS ADVANCED TRUE)
176gflags_property (INSTALL_HEADERS ADVANCED TRUE)
177gflags_property (INSTALL_SHARED_LIBS ADVANCED TRUE)
178gflags_property (INSTALL_STATIC_LIBS ADVANCED TRUE)
179
180if (NOT GFLAGS_IS_SUBPROJECT)
181 foreach (varname IN ITEMS CMAKE_INSTALL_PREFIX)
182 gflags_property (${varname} ADVANCED FALSE)
183 endforeach ()
184 foreach (varname IN ITEMS CMAKE_CONFIGURATION_TYPES CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
185 gflags_property (${varname} ADVANCED TRUE)
186 endforeach ()
187 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
188 gflags_set (CMAKE_BUILD_TYPE Release)
189 endif ()
190 if (CMAKE_CONFIGURATION_TYPES)
191 gflags_property (CMAKE_BUILD_TYPE STRINGS "${CMAKE_CONFIGURATION_TYPES}")
192 endif ()
193endif () # NOT GFLAGS_IS_SUBPROJECT
unknown3d142b82014-03-19 15:27:08 +0100194
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000195if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
196 set (BUILD_STATIC_LIBS ON)
197endif ()
198if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000199 message (FATAL_ERROR "At least one of [GFLAGS_]BUILD_gflags_LIB and [GFLAGS_]BUILD_gflags_nothreads_LIB must be ON.")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000200endif ()
201
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000202gflags_define (STRING INCLUDE_DIR "Name of include directory of installed header files relative to CMAKE_INSTALL_PREFIX/include/" "${PACKAGE_NAME}")
203gflags_property (INCLUDE_DIR ADVANCED TRUE)
Andreas Schuh18469832016-11-24 23:15:34 +0000204file (TO_CMAKE_PATH "${INCLUDE_DIR}" INCLUDE_DIR)
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000205if (IS_ABSOLUTE INCLUDE_DIR)
206 message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include/")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000207endif ()
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000208if (INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
209 message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must not start with parent directory reference (../)")
Andreas Schuh659b4402014-05-02 14:56:58 +0100210endif ()
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000211set (GFLAGS_INCLUDE_DIR "${INCLUDE_DIR}")
Andreas Schuh659b4402014-05-02 14:56:58 +0100212
unknown3d142b82014-03-19 15:27:08 +0100213# ----------------------------------------------------------------------------
214# system checks
215include (CheckTypeSize)
216include (CheckIncludeFileCXX)
217include (CheckCXXSymbolExists)
218
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000219if (WIN32 AND NOT CYGWIN)
220 set (OS_WINDOWS 1)
221else ()
222 set (OS_WINDOWS 0)
223endif ()
224
unknown3d142b82014-03-19 15:27:08 +0100225if (MSVC)
226 set (HAVE_SYS_TYPES_H 1)
227 set (HAVE_STDINT_H 1)
228 set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
229 set (HAVE_INTTYPES_H 0)
230 set (HAVE_UNISTD_H 0)
231 set (HAVE_SYS_STAT_H 1)
Andreas Schuh92425782014-03-19 17:15:36 +0000232 set (HAVE_SHLWAPI_H 1)
unknown3d142b82014-03-19 15:27:08 +0100233else ()
234 foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
235 string (TOUPPER "${fname}" FNAME)
Andreas Schuh92425782014-03-19 17:15:36 +0000236 string (REPLACE "/" "_" FNAME "${FNAME}")
unknown3d142b82014-03-19 15:27:08 +0100237 if (NOT HAVE_${FNAME}_H)
238 check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
239 endif ()
240 endforeach ()
Andreas Schuhddc53572014-03-19 17:32:23 +0000241 # the following are used in #if directives not #ifdef
unknown3d142b82014-03-19 15:27:08 +0100242 bool_to_int (HAVE_STDINT_H)
243 bool_to_int (HAVE_SYS_TYPES_H)
244 bool_to_int (HAVE_INTTYPES_H)
Andreas Schuh92425782014-03-19 17:15:36 +0000245 if (NOT HAVE_FNMATCH_H AND OS_WINDOWS)
246 check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H)
247 endif ()
unknown3d142b82014-03-19 15:27:08 +0100248endif ()
249
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000250gflags_define (STRING INTTYPES_FORMAT "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "")
251gflags_property (INTTYPES_FORMAT STRINGS "C99;BSD;VC7")
252gflags_property (INTTYPES_FORMAT ADVANCED TRUE)
253if (NOT INTTYPES_FORMAT)
unknown3d142b82014-03-19 15:27:08 +0100254 set (TYPES uint32_t u_int32_t)
255 if (MSVC)
256 list (INSERT TYPES 0 __int32)
257 endif ()
258 foreach (type IN LISTS TYPES)
259 check_type_size (${type} ${type} LANGUAGE CXX)
260 if (HAVE_${type})
261 break ()
262 endif ()
263 endforeach ()
264 if (HAVE_uint32_t)
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000265 gflags_set (INTTYPES_FORMAT C99)
unknown3d142b82014-03-19 15:27:08 +0100266 elseif (HAVE_u_int32_t)
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000267 gflags_set (INTTYPES_FORMAT BSD)
unknown3d142b82014-03-19 15:27:08 +0100268 elseif (HAVE___int32)
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000269 gflags_set (INTTYPES_FORMAT VC7)
unknown3d142b82014-03-19 15:27:08 +0100270 else ()
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000271 gflags_property (INTTYPES_FORMAT ADVANCED FALSE)
unknown3d142b82014-03-19 15:27:08 +0100272 message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
273 " Neither uint32_t, u_int32_t, nor __int32 seem to be available."
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000274 " Set [GFLAGS_]INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
unknown3d142b82014-03-19 15:27:08 +0100275 endif ()
276endif ()
277# use of special characters in strings to circumvent bug #0008226
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000278if ("^${INTTYPES_FORMAT}$" STREQUAL "^WIN$")
279 gflags_set (INTTYPES_FORMAT VC7)
unknown3d142b82014-03-19 15:27:08 +0100280endif ()
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000281if (NOT INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
282 message (FATAL_ERROR "Invalid value for [GFLAGS_]INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
unknown3d142b82014-03-19 15:27:08 +0100283endif ()
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000284set (GFLAGS_INTTYPES_FORMAT "${INTTYPES_FORMAT}")
unknown3d142b82014-03-19 15:27:08 +0100285set (GFLAGS_INTTYPES_FORMAT_C99 0)
286set (GFLAGS_INTTYPES_FORMAT_BSD 0)
287set (GFLAGS_INTTYPES_FORMAT_VC7 0)
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000288set ("GFLAGS_INTTYPES_FORMAT_${INTTYPES_FORMAT}" 1)
unknown3d142b82014-03-19 15:27:08 +0100289
290if (MSVC)
291 set (HAVE_strtoll 0)
292 set (HAVE_strtoq 0)
293else ()
Andreas Schuh0b116eb2014-03-19 15:56:26 +0000294 check_cxx_symbol_exists (strtoll stdlib.h HAVE_STRTOLL)
295 if (NOT HAVE_STRTOLL)
296 check_cxx_symbol_exists (strtoq stdlib.h HAVE_STRTOQ)
297 endif ()
unknown3d142b82014-03-19 15:27:08 +0100298endif ()
299
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000300if (BUILD_gflags_LIB)
301 set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
302 find_package (Threads)
303 if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
304 set (HAVE_PTHREAD 1)
305 check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
306 else ()
307 set (HAVE_PTHREAD 0)
308 endif ()
309 if (UNIX AND NOT HAVE_PTHREAD)
310 if (CMAKE_HAVE_PTHREAD_H)
311 set (what "library")
312 else ()
313 set (what ".h file")
314 endif ()
315 message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
316 "\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
317 "\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
318 endif ()
unknown3d142b82014-03-19 15:27:08 +0100319else ()
320 set (HAVE_PTHREAD 0)
321endif ()
322
unknown3d142b82014-03-19 15:27:08 +0100323# ----------------------------------------------------------------------------
324# source files - excluding root subdirectory and/or .in suffix
325set (PUBLIC_HDRS
326 "gflags.h"
327 "gflags_declare.h"
328 "gflags_completions.h"
329)
330
Andreas Schuh659b4402014-05-02 14:56:58 +0100331if (GFLAGS_NAMESPACE_SECONDARY)
332 set (INCLUDE_GFLAGS_NS_H "// Import gflags library symbols into alternative/deprecated namespace(s)")
333 foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
334 string (TOUPPER "${ns}" NS)
335 set (gflags_ns_h "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/gflags_${ns}.h")
336 configure_file ("${PROJECT_SOURCE_DIR}/src/gflags_ns.h.in" "${gflags_ns_h}" @ONLY)
337 list (APPEND PUBLIC_HDRS "${gflags_ns_h}")
338 set (INCLUDE_GFLAGS_NS_H "${INCLUDE_GFLAGS_NS_H}\n#include \"gflags_${ns}.h\"")
339 endforeach ()
340else ()
341 set (INCLUDE_GFLAGS_NS_H)
342endif ()
343
unknown3d142b82014-03-19 15:27:08 +0100344set (PRIVATE_HDRS
345 "config.h"
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000346 "util.h"
347 "mutex.h"
unknown3d142b82014-03-19 15:27:08 +0100348)
349
350set (GFLAGS_SRCS
351 "gflags.cc"
Andreas Schuh8f2c22a2016-11-25 13:42:29 +0000352 "gflags_reporting.cc"
353 "gflags_completions.cc"
unknown3d142b82014-03-19 15:27:08 +0100354)
355
Andreas Schuh41181662014-03-19 16:46:56 +0000356if (OS_WINDOWS)
unknown3d142b82014-03-19 15:27:08 +0100357 list (APPEND PRIVATE_HDRS "windows_port.h")
358 list (APPEND GFLAGS_SRCS "windows_port.cc")
359endif ()
360
361# ----------------------------------------------------------------------------
362# configure source files
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000363if (NOT DEFINED GFLAGS_ATTRIBUTE_UNUSED)
364 if (CMAKE_COMPILER_IS_GNUCXX)
365 set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
366 else ()
367 set (GFLAGS_ATTRIBUTE_UNUSED)
368 endif ()
unknown3d142b82014-03-19 15:27:08 +0100369endif ()
370
Andreas Schuh6040eac2014-03-25 15:29:56 +0000371# whenever we build a shared library (DLL on Windows), configure the public
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000372# headers of the API for use of this shared library rather than the optionally
Andreas Schuh6040eac2014-03-25 15:29:56 +0000373# also build statically linked library; users can override GFLAGS_DLL_DECL
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000374# in particular, this done by setting the INTERFACE_COMPILE_DEFINITIONS of
375# static libraries to include an empty definition for GFLAGS_DLL_DECL
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000376if (NOT DEFINED GFLAGS_IS_A_DLL)
377 if (BUILD_SHARED_LIBS)
378 set (GFLAGS_IS_A_DLL 1)
379 else ()
380 set (GFLAGS_IS_A_DLL 0)
381 endif ()
Andreas Schuh6040eac2014-03-25 15:29:56 +0000382endif ()
383
unknown3d142b82014-03-19 15:27:08 +0100384configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
385configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
386configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
387
388# ----------------------------------------------------------------------------
389# output directories
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000390if (NOT GFLAGS_IS_SUBPROJECT)
391 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
392 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
393 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
394endif ()
unknown3d142b82014-03-19 15:27:08 +0100395
396# ----------------------------------------------------------------------------
Andreas Schuh76c53b72015-03-24 14:44:12 +0000397# installation directories
398if (OS_WINDOWS)
399 set (RUNTIME_INSTALL_DIR Bin)
400 set (LIBRARY_INSTALL_DIR Lib)
401 set (INCLUDE_INSTALL_DIR Include)
402 set (CONFIG_INSTALL_DIR CMake)
Andreas Schuhc94a60e2016-11-25 08:50:08 +0000403 set (PKGCONFIG_INSTALL_DIR)
Andreas Schuh76c53b72015-03-24 14:44:12 +0000404else ()
405 set (RUNTIME_INSTALL_DIR bin)
406 # The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora
407 # package maintainers. Also package maintainers of other distribution
408 # packages need to be able to specify the name of the library directory.
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000409 if (NOT GFLAGS_LIBRARY_INSTALL_DIR AND LIB_INSTALL_DIR)
410 set (GFLAGS_LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}")
Andreas Schuh76c53b72015-03-24 14:44:12 +0000411 endif ()
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000412 gflags_define (PATH LIBRARY_INSTALL_DIR "Directory of installed libraries, e.g., \"lib64\"" "lib${LIB_SUFFIX}")
413 gflags_property (LIBRARY_INSTALL_DIR ADVANCED TRUE)
Andreas Schuh76c53b72015-03-24 14:44:12 +0000414 set (INCLUDE_INSTALL_DIR include)
415 set (CONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME})
Andreas Schuhc94a60e2016-11-25 08:50:08 +0000416 set (PKGCONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/pkgconfig)
Andreas Schuh76c53b72015-03-24 14:44:12 +0000417endif ()
418
419# ----------------------------------------------------------------------------
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000420# add library targets
421set (TARGETS)
422# static vs. shared
423foreach (TYPE IN ITEMS STATIC SHARED)
424 if (BUILD_${TYPE}_LIBS)
Arnaud Farbosd78b00d2015-11-05 12:03:37 -0800425 string (TOLOWER "${TYPE}" type)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000426 # whether or not targets are a DLL
427 if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$")
428 set (GFLAGS_IS_A_DLL 1)
429 else ()
430 set (GFLAGS_IS_A_DLL 0)
431 endif ()
Andreas Schuh6bd636c2016-02-29 17:58:46 +0000432 # filename suffix for static libraries on Windows
433 if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^STATIC$")
434 set (type_suffix "_${type}")
435 else ()
436 set (type_suffix "")
437 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000438 # multi-threaded vs. single-threaded
439 foreach (opts IN ITEMS "" _nothreads)
440 if (BUILD_gflags${opts}_LIB)
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000441 set (target_name "gflags${opts}_${type}")
442 add_library (${target_name} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
443 set_target_properties (${target_name} PROPERTIES
444 OUTPUT_NAME "gflags${opts}${type_suffix}"
445 VERSION "${PACKAGE_VERSION}"
446 SOVERSION "${PACKAGE_SOVERSION}"
447 )
Andreas Schuh58345b12015-04-03 16:12:38 +0100448 set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>")
449 if (INSTALL_HEADERS)
450 list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")
Andreas Schuh76c53b72015-03-24 14:44:12 +0000451 endif ()
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000452 target_include_directories (${target_name}
Andreas Schuh58345b12015-04-03 16:12:38 +0100453 PUBLIC "${include_dirs}"
454 PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}"
455 )
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000456 target_compile_definitions (${target_name} PUBLIC GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL})
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000457 if (opts MATCHES "nothreads")
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000458 target_compile_definitions (${target_name} PRIVATE NO_THREADS)
459 elseif (CMAKE_USE_PTHREADS_INIT)
460 target_link_libraries (${target_name} ${CMAKE_THREAD_LIBS_INIT})
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000461 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000462 if (HAVE_SHLWAPI_H)
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000463 target_link_libraries (${target_name} shlwapi.lib)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000464 endif ()
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000465 list (APPEND TARGETS ${target_name})
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000466 # add convenience make target for build of both shared and static libraries
467 if (NOT GFLAGS_IS_SUBPROJECT)
468 if (NOT TARGET gflags${opts})
469 add_custom_target (gflags${opts})
470 endif ()
Andreas Schuh3e7ef742016-11-25 08:25:09 +0000471 add_dependencies (gflags${opts} ${target_name})
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000472 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000473 endif ()
474 endforeach ()
Andreas Schuhddc53572014-03-19 17:32:23 +0000475 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000476endforeach ()
unknown3d142b82014-03-19 15:27:08 +0100477
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000478# add ALIAS target for use in super-project, prefer static over shared, single-threaded over multi-threaded
479if (GFLAGS_IS_SUBPROJECT)
480 foreach (type IN ITEMS static shared)
481 foreach (opts IN ITEMS "_nothreads" "")
Andreas Schuh7a21c162016-03-01 21:04:10 +0000482 if (TARGET gflags${opts}_${type})
483 add_library (gflags ALIAS gflags${opts}_${type})
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000484 break ()
485 endif ()
486 endforeach ()
487 if (TARGET gflags)
488 break ()
489 endif ()
490 endforeach ()
491endif ()
492
unknown3d142b82014-03-19 15:27:08 +0100493# ----------------------------------------------------------------------------
Andreas Schuh76c53b72015-03-24 14:44:12 +0000494# installation rules
Andreas Schuh3064f632016-11-24 21:49:41 +0000495set (EXPORT_NAME ${PACKAGE_NAME}-targets)
unknown3d142b82014-03-19 15:27:08 +0100496file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
497configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
498configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
499
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000500if (BUILD_SHARED_LIBS AND INSTALL_SHARED_LIBS)
501 foreach (opts IN ITEMS "" _nothreads)
502 if (BUILD_gflags${opts}_LIB)
Andreas Schuh3064f632016-11-24 21:49:41 +0000503 install (TARGETS gflags${opts}_shared DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT ${EXPORT_NAME})
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000504 endif ()
505 endforeach ()
506endif ()
507if (BUILD_STATIC_LIBS AND INSTALL_STATIC_LIBS)
508 foreach (opts IN ITEMS "" _nothreads)
509 if (BUILD_gflags${opts}_LIB)
Andreas Schuh3064f632016-11-24 21:49:41 +0000510 install (TARGETS gflags${opts}_static DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT ${EXPORT_NAME})
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000511 endif ()
512 endforeach ()
513endif ()
514
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000515if (INSTALL_HEADERS)
Andreas Schuhaff8ef82014-03-27 01:09:20 +0000516 install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR})
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000517 install (
518 FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
519 RENAME ${PACKAGE_NAME}-config.cmake
520 DESTINATION ${CONFIG_INSTALL_DIR}
521 )
522 install (
523 FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
524 DESTINATION ${CONFIG_INSTALL_DIR}
525 )
Andreas Schuh3064f632016-11-24 21:49:41 +0000526 install (EXPORT ${EXPORT_NAME} DESTINATION ${CONFIG_INSTALL_DIR})
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000527 if (UNIX)
528 install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
529 endif ()
unknown3d142b82014-03-19 15:27:08 +0100530endif ()
531
Andreas Schuhc94a60e2016-11-25 08:50:08 +0000532if (PKGCONFIG_INSTALL_DIR)
533 configure_file ("cmake/package.pc.in" "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}.pc" @ONLY)
534 install (FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
535endif ()
536
unknown3d142b82014-03-19 15:27:08 +0100537# ----------------------------------------------------------------------------
538# support direct use of build tree
539set (INSTALL_PREFIX_REL2CONFIG_DIR .)
Andreas Schuh3064f632016-11-24 21:49:41 +0000540export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${EXPORT_NAME}.cmake")
Andreas Schuh3886da52016-11-24 22:36:48 +0000541if (REGISTER_BUILD_DIR)
542 export (PACKAGE ${PACKAGE_NAME})
543endif ()
544if (REGISTER_INSTALL_PREFIX)
545 register_gflags_package(${CONFIG_INSTALL_DIR})
546endif ()
unknown3d142b82014-03-19 15:27:08 +0100547configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
548
549# ----------------------------------------------------------------------------
550# testing - MUST follow the generation of the build tree config file
unknown3d142b82014-03-19 15:27:08 +0100551if (BUILD_TESTING)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000552 include (CTest)
unknown3d142b82014-03-19 15:27:08 +0100553 enable_testing ()
554 add_subdirectory (test)
555endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000556
557# ----------------------------------------------------------------------------
558# packaging
559if (BUILD_PACKAGING)
560
561 if (NOT BUILD_SHARED_LIBS AND NOT INSTALL_HEADERS)
562 message (WARNING "Package will contain static libraries without headers!"
563 "\nRecommended options for generation of runtime package:"
564 "\n BUILD_SHARED_LIBS=ON"
565 "\n BUILD_STATIC_LIBS=OFF"
566 "\n INSTALL_HEADERS=OFF"
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000567 "\n INSTALL_SHARED_LIBS=ON"
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000568 "\nRecommended options for generation of development package:"
569 "\n BUILD_SHARED_LIBS=ON"
570 "\n BUILD_STATIC_LIBS=ON"
Andreas Schuh91e16ee2016-03-01 20:03:43 +0000571 "\n INSTALL_HEADERS=ON"
572 "\n INSTALL_SHARED_LIBS=ON"
573 "\n INSTALL_STATIC_LIBS=ON")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000574 endif ()
575
576 # default package generators
577 if (APPLE)
578 set (PACKAGE_GENERATOR "PackageMaker")
579 set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
580 elseif (UNIX)
581 set (PACKAGE_GENERATOR "DEB;RPM")
582 set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
583 else ()
584 set (PACKAGE_GENERATOR "ZIP")
585 set (PACKAGE_SOURCE_GENERATOR "ZIP")
586 endif ()
587
588 # used package generators
589 set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).")
590 set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
591 mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR)
592
Andreas Schuh64ac2e32015-03-24 16:21:44 +0000593 # some package generators (e.g., PackageMaker) do not allow .md extension
594 configure_file ("${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_BINARY_DIR}/README.txt" COPYONLY)
595
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000596 # common package information
Andreas Schuhfc6e0792014-03-20 04:09:02 +0000597 set (CPACK_PACKAGE_VENDOR "Andreas Schuh")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000598 set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com")
599 set (CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
600 set (CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}")
601 set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
602 set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
603 set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
Andreas Schuhc94a60e2016-11-25 08:50:08 +0000604 set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE_DESCRIPTION}")
Andreas Schuha819f0f2015-03-24 16:29:31 +0000605 set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000606 set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt")
Andreas Schuha819f0f2015-03-24 16:29:31 +0000607 set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000608 set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
609 set (CPACK_OUTPUT_FILE_PREFIX packages)
610 set (CPACK_PACKAGE_RELOCATABLE TRUE)
611 set (CPACK_MONOLITHIC_INSTALL TRUE)
612
Andreas Schuhe8890f22014-03-20 04:20:15 +0000613 # RPM package information -- used in cmake/package.cmake.in also for DEB
Andreas Schuh37a9a902014-03-20 03:27:13 +0000614 set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
615 set (CPACK_RPM_PACKAGE_LICENSE "BSD")
Andreas Schuhc94a60e2016-11-25 08:50:08 +0000616 set (CPACK_RPM_PACKAGE_URL "${PACKAGE_URL}")
Andreas Schuh37a9a902014-03-20 03:27:13 +0000617 set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
618
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000619 if (INSTALL_HEADERS)
Andreas Schuh2b8deaa2015-03-24 14:41:52 +0000620 set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000621 else ()
622 set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt")
623 endif ()
624
Andreas Schuhd6995592014-03-20 20:21:30 +0000625 # system/architecture
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000626 if (WINDOWS)
627 if (CMAKE_CL_64)
628 set (CPACK_SYSTEM_NAME "win64")
629 else ()
630 set (CPACK_SYSTEM_NAME "win32")
631 endif ()
Andreas Schuhd6995592014-03-20 20:21:30 +0000632 set (CPACK_PACKAGE_ARCHITECTURE)
Andreas Schuhef5c5472014-03-30 15:34:13 +0100633 elseif (APPLE)
634 set (CPACK_PACKAGE_ARCHITECTURE darwin)
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000635 else ()
636 string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
Andreas Schuhcf40f732014-03-20 20:56:05 +0000637 if (CMAKE_CXX_FLAGS MATCHES "-m32")
638 set (CPACK_PACKAGE_ARCHITECTURE i386)
639 else ()
640 execute_process (
641 COMMAND dpkg --print-architecture
642 RESULT_VARIABLE RV
643 OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
644 )
645 if (RV EQUAL 0)
646 string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
647 else ()
648 execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
649 if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
650 set (CPACK_PACKAGE_ARCHITECTURE amd64)
651 else ()
652 set (CPACK_PACKAGE_ARCHITECTURE i386)
653 endif ()
654 endif ()
655 endif ()
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000656 endif ()
657
658 # source package settings
659 set (CPACK_SOURCE_TOPLEVEL_TAG "source")
660 set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
661 set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
662
663 # default binary package settings
Andreas Schuhd6995592014-03-20 20:21:30 +0000664 set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
665 set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
666 if (CPACK_PACKAGE_ARCHITECTURE)
667 set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}")
Andreas Schuh9ecc4ca2014-03-20 02:11:44 +0000668 endif ()
669
670 # generator specific configuration file
671 #
672 # allow package maintainers to use their own configuration file
673 # $ cmake -DCPACK_PROJECT_CONFIG_FILE:FILE=/path/to/package/config
674 if (NOT CPACK_PROJECT_CONFIG_FILE)
675 configure_file (
676 "${CMAKE_CURRENT_LIST_DIR}/cmake/package.cmake.in"
677 "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake" @ONLY
678 )
679 set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake")
680 endif ()
681
682 include (CPack)
683
684endif () # BUILD_PACKAGING