Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 1 | ## 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 |
| 18 | ## library target for the "gflags_nothreads-static" library target. Targets which |
| 19 | ## 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 | ## |
| 31 | ## Example CMakeLists.txt of super-project which contains gflags source tree: |
| 32 | ## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) |
| 33 | ## |
| 34 | ## project(Foo) |
| 35 | ## |
| 36 | ## add_subdirectory(gflags) |
| 37 | ## |
| 38 | ## add_executable(foo src/foo.cc) |
| 39 | ## target_link_libraries(foo gflags) |
| 40 | ## |
| 41 | ## Variables to configure the source files: |
| 42 | ## - GFLAGS_IS_A_DLL |
| 43 | ## - GFLAGS_NAMESPACE |
| 44 | ## - GFLAGS_ATTRIBUTE_UNUSED |
| 45 | ## - GFLAGS_INTTYPES_FORMAT |
| 46 | ## |
| 47 | ## Variables to configure the build: |
| 48 | ## - GFLAGS_SOVERSION |
| 49 | ## - GFLAGS_BUILD_SHARED_LIBS |
| 50 | ## - GFLAGS_BUILD_STATIC_LIBS |
| 51 | ## - GFLAGS_BUILD_gflags_LIB |
| 52 | ## - GFLAGS_BUILD_gflags_nothreads_LIB |
| 53 | ## - GFLAGS_BUILD_TESTING |
| 54 | ## - GFLAGS_BUILD_PACKAGING |
| 55 | ## |
| 56 | ## Variables to configure the installation: |
| 57 | ## - GFLAGS_INCLUDE_DIR |
| 58 | ## - GFLAGS_LIBRARY_INSTALL_DIR or LIB_INSTALL_DIR or LIB_SUFFIX |
| 59 | ## - GFLAGS_INSTALL_HEADERS |
| 60 | ## - GFLAGS_INSTALL_SHARED_LIBS |
| 61 | ## - GFLAGS_INSTALL_STATIC_LIBS |
| 62 | |
Andreas Schuh | 58345b1 | 2015-04-03 16:12:38 +0100 | [diff] [blame] | 63 | cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 64 | |
Andreas Schuh | 7b5b080 | 2015-03-24 14:41:10 +0000 | [diff] [blame] | 65 | if (POLICY CMP0042) |
| 66 | cmake_policy (SET CMP0042 NEW) |
| 67 | endif () |
| 68 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 69 | # ---------------------------------------------------------------------------- |
| 70 | # includes |
| 71 | set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 72 | include (utils) |
| 73 | |
| 74 | # ---------------------------------------------------------------------------- |
| 75 | # package information |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 76 | set (PACKAGE_NAME "gflags") |
Andreas Schuh | 4b77146 | 2015-03-24 14:44:57 +0000 | [diff] [blame] | 77 | set (PACKAGE_VERSION "2.2.0") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 78 | set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 79 | set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") |
Andreas Schuh | abe4b10 | 2016-03-01 16:01:45 +0000 | [diff] [blame] | 80 | set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 81 | |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 82 | project (${PACKAGE_NAME} CXX) |
Andreas Schuh | 51f1db7 | 2015-03-24 15:36:26 +0000 | [diff] [blame] | 83 | if (CMAKE_VERSION VERSION_LESS 100) |
| 84 | # C language still needed because the following required CMake modules |
| 85 | # (or their dependencies, respectively) are not correctly handling |
| 86 | # the case where only CXX is enabled. |
| 87 | # - CheckTypeSize.cmake (fixed in CMake 3.1, cf. http://www.cmake.org/Bug/view.php?id=14056) |
| 88 | # - FindThreads.cmake (--> CheckIncludeFiles.cmake <--) |
| 89 | enable_language (C) |
| 90 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 91 | |
| 92 | version_numbers ( |
| 93 | ${PACKAGE_VERSION} |
| 94 | PACKAGE_VERSION_MAJOR |
| 95 | PACKAGE_VERSION_MINOR |
| 96 | PACKAGE_VERSION_PATCH |
| 97 | ) |
| 98 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 99 | # shared library ABI version number, can be overridden by package maintainers |
| 100 | # using -DGFLAGS_SOVERSION=XXX on the command-line |
| 101 | if (GFLAGS_SOVERSION) |
| 102 | set (PACKAGE_SOVERSION "${GFLAGS_SOVERSION}") |
| 103 | else () |
| 104 | set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}") |
| 105 | endif () |
| 106 | |
| 107 | # when gflags is included as subproject (e.g., as Git submodule/subtree) in the source |
| 108 | # tree of a project that uses it, no variables should be added to the CMake cache; |
| 109 | # users may set the non-cached variable GFLAGS_IS_SUBPROJECT before add_subdirectory(gflags) |
| 110 | if (NOT DEFINED GFLAGS_IS_SUBPROJECT) |
| 111 | if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$") |
| 112 | set (GFLAGS_IS_SUBPROJECT FALSE) |
| 113 | else () |
| 114 | set (GFLAGS_IS_SUBPROJECT TRUE) |
| 115 | endif () |
| 116 | endif () |
| 117 | |
| 118 | # prefix for package variables in CMake configuration file |
| 119 | string (TOUPPER "${PACKAGE_NAME}" PACKAGE_PREFIX) |
Andreas Schuh | bf88978 | 2014-05-01 20:16:16 +0100 | [diff] [blame] | 120 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 121 | # ---------------------------------------------------------------------------- |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 122 | # options |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 123 | |
| 124 | # maintain binary backwards compatibility with gflags library version <= 2.0, |
| 125 | # but at the same time enable the use of the preferred new "gflags" namespace |
| 126 | gflags_define (STRING NAMESPACE "Name(s) of library namespace (separate multiple options by semicolon)" "google;${PACKAGE_NAME}" "${PACKAGE_NAME}") |
| 127 | gflags_property (NAMESPACE ADVANCED TRUE) |
| 128 | set (GFLAGS_NAMESPACE_SECONDARY "${NAMESPACE}") |
Andreas Schuh | 659b440 | 2014-05-02 14:56:58 +0100 | [diff] [blame] | 129 | list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY) |
| 130 | if (NOT GFLAGS_NAMESPACE_SECONDARY) |
| 131 | message (FATAL_ERROR "GFLAGS_NAMESPACE must be set to one (or more) valid C++ namespace identifier(s separated by semicolon \";\").") |
Andreas Schuh | aff8ef8 | 2014-03-27 01:09:20 +0000 | [diff] [blame] | 132 | endif () |
Andreas Schuh | 659b440 | 2014-05-02 14:56:58 +0100 | [diff] [blame] | 133 | foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY) |
| 134 | if (NOT ns MATCHES "^[a-zA-Z][a-zA-Z0-9_]*$") |
| 135 | message (FATAL_ERROR "GFLAGS_NAMESPACE contains invalid namespace identifier: ${ns}") |
| 136 | endif () |
| 137 | endforeach () |
| 138 | list (GET GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE) |
| 139 | list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 140 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 141 | # cached build options when gflags is not a subproject, otherwise non-cached CMake variables |
| 142 | # usage: gflags_define(BOOL <name> <doc> <default> [<subproject default>]) |
| 143 | gflags_define (BOOL BUILD_SHARED_LIBS "Request build of shared libraries." OFF OFF) |
| 144 | gflags_define (BOOL BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF ON) |
| 145 | gflags_define (BOOL BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON OFF) |
| 146 | gflags_define (BOOL BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON ON) |
| 147 | gflags_define (BOOL BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF OFF) |
| 148 | gflags_define (BOOL BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF OFF) |
| 149 | gflags_define (BOOL INSTALL_HEADERS "Request installation of headers and other development files." ON OFF) |
| 150 | gflags_define (BOOL INSTALL_SHARED_LIBS "Request installation of shared libraries." ON ON) |
| 151 | gflags_define (BOOL INSTALL_STATIC_LIBS "Request installation of static libraries." ON OFF) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 152 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 153 | gflags_property (BUILD_STATIC_LIBS ADVANCED TRUE) |
| 154 | gflags_property (INSTALL_HEADERS ADVANCED TRUE) |
| 155 | gflags_property (INSTALL_SHARED_LIBS ADVANCED TRUE) |
| 156 | gflags_property (INSTALL_STATIC_LIBS ADVANCED TRUE) |
| 157 | |
| 158 | if (NOT GFLAGS_IS_SUBPROJECT) |
| 159 | foreach (varname IN ITEMS CMAKE_INSTALL_PREFIX) |
| 160 | gflags_property (${varname} ADVANCED FALSE) |
| 161 | endforeach () |
| 162 | foreach (varname IN ITEMS CMAKE_CONFIGURATION_TYPES CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT) |
| 163 | gflags_property (${varname} ADVANCED TRUE) |
| 164 | endforeach () |
| 165 | if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) |
| 166 | gflags_set (CMAKE_BUILD_TYPE Release) |
| 167 | endif () |
| 168 | if (CMAKE_CONFIGURATION_TYPES) |
| 169 | gflags_property (CMAKE_BUILD_TYPE STRINGS "${CMAKE_CONFIGURATION_TYPES}") |
| 170 | endif () |
| 171 | endif () # NOT GFLAGS_IS_SUBPROJECT |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 172 | |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 173 | if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS) |
| 174 | set (BUILD_STATIC_LIBS ON) |
| 175 | endif () |
| 176 | if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB) |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 177 | message (FATAL_ERROR "At least one of [GFLAGS_]BUILD_gflags_LIB and [GFLAGS_]BUILD_gflags_nothreads_LIB must be ON.") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 178 | endif () |
| 179 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 180 | gflags_define (STRING INCLUDE_DIR "Name of include directory of installed header files relative to CMAKE_INSTALL_PREFIX/include/" "${PACKAGE_NAME}") |
| 181 | gflags_property (INCLUDE_DIR ADVANCED TRUE) |
| 182 | if (IS_ABSOLUTE INCLUDE_DIR) |
| 183 | message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include/") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 184 | endif () |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 185 | if (INCLUDE_DIR MATCHES "^\\.\\.[/\\]") |
| 186 | message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must not start with parent directory reference (../)") |
Andreas Schuh | 659b440 | 2014-05-02 14:56:58 +0100 | [diff] [blame] | 187 | endif () |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 188 | set (GFLAGS_INCLUDE_DIR "${INCLUDE_DIR}") |
Andreas Schuh | 659b440 | 2014-05-02 14:56:58 +0100 | [diff] [blame] | 189 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 190 | # ---------------------------------------------------------------------------- |
| 191 | # system checks |
| 192 | include (CheckTypeSize) |
| 193 | include (CheckIncludeFileCXX) |
| 194 | include (CheckCXXSymbolExists) |
| 195 | |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 196 | if (WIN32 AND NOT CYGWIN) |
| 197 | set (OS_WINDOWS 1) |
| 198 | else () |
| 199 | set (OS_WINDOWS 0) |
| 200 | endif () |
| 201 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 202 | if (MSVC) |
| 203 | set (HAVE_SYS_TYPES_H 1) |
| 204 | set (HAVE_STDINT_H 1) |
| 205 | set (HAVE_STDDEF_H 1) # used by CheckTypeSize module |
| 206 | set (HAVE_INTTYPES_H 0) |
| 207 | set (HAVE_UNISTD_H 0) |
| 208 | set (HAVE_SYS_STAT_H 1) |
Andreas Schuh | 9242578 | 2014-03-19 17:15:36 +0000 | [diff] [blame] | 209 | set (HAVE_SHLWAPI_H 1) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 210 | else () |
| 211 | foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch) |
| 212 | string (TOUPPER "${fname}" FNAME) |
Andreas Schuh | 9242578 | 2014-03-19 17:15:36 +0000 | [diff] [blame] | 213 | string (REPLACE "/" "_" FNAME "${FNAME}") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 214 | if (NOT HAVE_${FNAME}_H) |
| 215 | check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H) |
| 216 | endif () |
| 217 | endforeach () |
Andreas Schuh | ddc5357 | 2014-03-19 17:32:23 +0000 | [diff] [blame] | 218 | # the following are used in #if directives not #ifdef |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 219 | bool_to_int (HAVE_STDINT_H) |
| 220 | bool_to_int (HAVE_SYS_TYPES_H) |
| 221 | bool_to_int (HAVE_INTTYPES_H) |
Andreas Schuh | 9242578 | 2014-03-19 17:15:36 +0000 | [diff] [blame] | 222 | if (NOT HAVE_FNMATCH_H AND OS_WINDOWS) |
| 223 | check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H) |
| 224 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 225 | endif () |
| 226 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 227 | gflags_define (STRING INTTYPES_FORMAT "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "") |
| 228 | gflags_property (INTTYPES_FORMAT STRINGS "C99;BSD;VC7") |
| 229 | gflags_property (INTTYPES_FORMAT ADVANCED TRUE) |
| 230 | if (NOT INTTYPES_FORMAT) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 231 | set (TYPES uint32_t u_int32_t) |
| 232 | if (MSVC) |
| 233 | list (INSERT TYPES 0 __int32) |
| 234 | endif () |
| 235 | foreach (type IN LISTS TYPES) |
| 236 | check_type_size (${type} ${type} LANGUAGE CXX) |
| 237 | if (HAVE_${type}) |
| 238 | break () |
| 239 | endif () |
| 240 | endforeach () |
| 241 | if (HAVE_uint32_t) |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 242 | gflags_set (INTTYPES_FORMAT C99) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 243 | elseif (HAVE_u_int32_t) |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 244 | gflags_set (INTTYPES_FORMAT BSD) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 245 | elseif (HAVE___int32) |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 246 | gflags_set (INTTYPES_FORMAT VC7) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 247 | else () |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 248 | gflags_property (INTTYPES_FORMAT ADVANCED FALSE) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 249 | message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!" |
| 250 | " Neither uint32_t, u_int32_t, nor __int32 seem to be available." |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 251 | " Set [GFLAGS_]INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 252 | endif () |
| 253 | endif () |
| 254 | # use of special characters in strings to circumvent bug #0008226 |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 255 | if ("^${INTTYPES_FORMAT}$" STREQUAL "^WIN$") |
| 256 | gflags_set (INTTYPES_FORMAT VC7) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 257 | endif () |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 258 | if (NOT INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$") |
| 259 | message (FATAL_ERROR "Invalid value for [GFLAGS_]INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 260 | endif () |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 261 | set (GFLAGS_INTTYPES_FORMAT "${INTTYPES_FORMAT}") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 262 | set (GFLAGS_INTTYPES_FORMAT_C99 0) |
| 263 | set (GFLAGS_INTTYPES_FORMAT_BSD 0) |
| 264 | set (GFLAGS_INTTYPES_FORMAT_VC7 0) |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 265 | set ("GFLAGS_INTTYPES_FORMAT_${INTTYPES_FORMAT}" 1) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 266 | |
| 267 | if (MSVC) |
| 268 | set (HAVE_strtoll 0) |
| 269 | set (HAVE_strtoq 0) |
| 270 | else () |
Andreas Schuh | 0b116eb | 2014-03-19 15:56:26 +0000 | [diff] [blame] | 271 | check_cxx_symbol_exists (strtoll stdlib.h HAVE_STRTOLL) |
| 272 | if (NOT HAVE_STRTOLL) |
| 273 | check_cxx_symbol_exists (strtoq stdlib.h HAVE_STRTOQ) |
| 274 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 275 | endif () |
| 276 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 277 | if (BUILD_gflags_LIB) |
| 278 | set (CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 279 | find_package (Threads) |
| 280 | if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) |
| 281 | set (HAVE_PTHREAD 1) |
| 282 | check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX) |
| 283 | else () |
| 284 | set (HAVE_PTHREAD 0) |
| 285 | endif () |
| 286 | if (UNIX AND NOT HAVE_PTHREAD) |
| 287 | if (CMAKE_HAVE_PTHREAD_H) |
| 288 | set (what "library") |
| 289 | else () |
| 290 | set (what ".h file") |
| 291 | endif () |
| 292 | message (FATAL_ERROR "Could not find pthread${what}. Check the log file" |
| 293 | "\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log" |
| 294 | "\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).") |
| 295 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 296 | else () |
| 297 | set (HAVE_PTHREAD 0) |
| 298 | endif () |
| 299 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 300 | # ---------------------------------------------------------------------------- |
| 301 | # source files - excluding root subdirectory and/or .in suffix |
| 302 | set (PUBLIC_HDRS |
| 303 | "gflags.h" |
| 304 | "gflags_declare.h" |
| 305 | "gflags_completions.h" |
| 306 | ) |
| 307 | |
Andreas Schuh | 659b440 | 2014-05-02 14:56:58 +0100 | [diff] [blame] | 308 | if (GFLAGS_NAMESPACE_SECONDARY) |
| 309 | set (INCLUDE_GFLAGS_NS_H "// Import gflags library symbols into alternative/deprecated namespace(s)") |
| 310 | foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY) |
| 311 | string (TOUPPER "${ns}" NS) |
| 312 | set (gflags_ns_h "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/gflags_${ns}.h") |
| 313 | configure_file ("${PROJECT_SOURCE_DIR}/src/gflags_ns.h.in" "${gflags_ns_h}" @ONLY) |
| 314 | list (APPEND PUBLIC_HDRS "${gflags_ns_h}") |
| 315 | set (INCLUDE_GFLAGS_NS_H "${INCLUDE_GFLAGS_NS_H}\n#include \"gflags_${ns}.h\"") |
| 316 | endforeach () |
| 317 | else () |
| 318 | set (INCLUDE_GFLAGS_NS_H) |
| 319 | endif () |
| 320 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 321 | set (PRIVATE_HDRS |
| 322 | "config.h" |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 323 | "util.h" |
| 324 | "mutex.h" |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 325 | ) |
| 326 | |
| 327 | set (GFLAGS_SRCS |
| 328 | "gflags.cc" |
| 329 | "gflags_reporting.cc" |
| 330 | "gflags_completions.cc" |
| 331 | ) |
| 332 | |
Andreas Schuh | 4118166 | 2014-03-19 16:46:56 +0000 | [diff] [blame] | 333 | if (OS_WINDOWS) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 334 | list (APPEND PRIVATE_HDRS "windows_port.h") |
| 335 | list (APPEND GFLAGS_SRCS "windows_port.cc") |
| 336 | endif () |
| 337 | |
| 338 | # ---------------------------------------------------------------------------- |
| 339 | # configure source files |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 340 | if (NOT DEFINED GFLAGS_ATTRIBUTE_UNUSED) |
| 341 | if (CMAKE_COMPILER_IS_GNUCXX) |
| 342 | set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))") |
| 343 | else () |
| 344 | set (GFLAGS_ATTRIBUTE_UNUSED) |
| 345 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 346 | endif () |
| 347 | |
Andreas Schuh | 6040eac | 2014-03-25 15:29:56 +0000 | [diff] [blame] | 348 | # whenever we build a shared library (DLL on Windows), configure the public |
| 349 | # headers of the API for use of this library rather than the optionally |
| 350 | # also build statically linked library; users can override GFLAGS_DLL_DECL |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 351 | if (NOT DEFINED GFLAGS_IS_A_DLL) |
| 352 | if (BUILD_SHARED_LIBS) |
| 353 | set (GFLAGS_IS_A_DLL 1) |
| 354 | else () |
| 355 | set (GFLAGS_IS_A_DLL 0) |
| 356 | endif () |
Andreas Schuh | 6040eac | 2014-03-25 15:29:56 +0000 | [diff] [blame] | 357 | endif () |
| 358 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 359 | configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS}) |
| 360 | configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS}) |
| 361 | configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS}) |
| 362 | |
| 363 | # ---------------------------------------------------------------------------- |
| 364 | # output directories |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 365 | if (NOT GFLAGS_IS_SUBPROJECT) |
| 366 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin") |
| 367 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib") |
| 368 | set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib") |
| 369 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 370 | |
| 371 | # ---------------------------------------------------------------------------- |
Andreas Schuh | 76c53b7 | 2015-03-24 14:44:12 +0000 | [diff] [blame] | 372 | # installation directories |
| 373 | if (OS_WINDOWS) |
| 374 | set (RUNTIME_INSTALL_DIR Bin) |
| 375 | set (LIBRARY_INSTALL_DIR Lib) |
| 376 | set (INCLUDE_INSTALL_DIR Include) |
| 377 | set (CONFIG_INSTALL_DIR CMake) |
| 378 | else () |
| 379 | set (RUNTIME_INSTALL_DIR bin) |
| 380 | # The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora |
| 381 | # package maintainers. Also package maintainers of other distribution |
| 382 | # packages need to be able to specify the name of the library directory. |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 383 | if (NOT GFLAGS_LIBRARY_INSTALL_DIR AND LIB_INSTALL_DIR) |
| 384 | set (GFLAGS_LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}") |
Andreas Schuh | 76c53b7 | 2015-03-24 14:44:12 +0000 | [diff] [blame] | 385 | endif () |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 386 | gflags_define (PATH LIBRARY_INSTALL_DIR "Directory of installed libraries, e.g., \"lib64\"" "lib${LIB_SUFFIX}") |
| 387 | gflags_property (LIBRARY_INSTALL_DIR ADVANCED TRUE) |
Andreas Schuh | 76c53b7 | 2015-03-24 14:44:12 +0000 | [diff] [blame] | 388 | set (INCLUDE_INSTALL_DIR include) |
| 389 | set (CONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME}) |
| 390 | endif () |
| 391 | |
| 392 | # ---------------------------------------------------------------------------- |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 393 | # add library targets |
| 394 | set (TARGETS) |
| 395 | # static vs. shared |
| 396 | foreach (TYPE IN ITEMS STATIC SHARED) |
| 397 | if (BUILD_${TYPE}_LIBS) |
Arnaud Farbos | d78b00d | 2015-11-05 12:03:37 -0800 | [diff] [blame] | 398 | string (TOLOWER "${TYPE}" type) |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 399 | # whether or not targets are a DLL |
| 400 | if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$") |
| 401 | set (GFLAGS_IS_A_DLL 1) |
| 402 | else () |
| 403 | set (GFLAGS_IS_A_DLL 0) |
| 404 | endif () |
Andreas Schuh | 6bd636c | 2016-02-29 17:58:46 +0000 | [diff] [blame] | 405 | # filename suffix for static libraries on Windows |
| 406 | if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^STATIC$") |
| 407 | set (type_suffix "_${type}") |
| 408 | else () |
| 409 | set (type_suffix "") |
| 410 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 411 | # multi-threaded vs. single-threaded |
| 412 | foreach (opts IN ITEMS "" _nothreads) |
| 413 | if (BUILD_gflags${opts}_LIB) |
| 414 | add_library (gflags${opts}-${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS}) |
Andreas Schuh | 58345b1 | 2015-04-03 16:12:38 +0100 | [diff] [blame] | 415 | set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>") |
| 416 | if (INSTALL_HEADERS) |
| 417 | list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>") |
Andreas Schuh | 76c53b7 | 2015-03-24 14:44:12 +0000 | [diff] [blame] | 418 | endif () |
Andreas Schuh | 58345b1 | 2015-04-03 16:12:38 +0100 | [diff] [blame] | 419 | target_include_directories (gflags${opts}-${type} |
| 420 | PUBLIC "${include_dirs}" |
| 421 | PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}" |
| 422 | ) |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 423 | if (opts MATCHES "nothreads") |
Sam Clegg | b572a72 | 2016-01-29 16:09:43 -0800 | [diff] [blame] | 424 | set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL};NO_THREADS") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 425 | else () |
| 426 | set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL}") |
Andreas Schuh | bf139ea | 2014-03-20 03:04:44 +0000 | [diff] [blame] | 427 | if (CMAKE_USE_PTHREADS_INIT) |
| 428 | target_link_libraries (gflags${opts}-${type} ${CMAKE_THREAD_LIBS_INIT}) |
| 429 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 430 | endif () |
| 431 | set_target_properties ( |
| 432 | gflags${opts}-${type} PROPERTIES COMPILE_DEFINITIONS "${defines}" |
Andreas Schuh | 6bd636c | 2016-02-29 17:58:46 +0000 | [diff] [blame] | 433 | OUTPUT_NAME "gflags${opts}${type_suffix}" |
Andreas Schuh | cd7aece | 2014-05-02 11:12:05 +0100 | [diff] [blame] | 434 | VERSION "${PACKAGE_VERSION}" |
| 435 | SOVERSION "${PACKAGE_SOVERSION}" |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 436 | ) |
| 437 | if (HAVE_SHLWAPI_H) |
| 438 | target_link_libraries (gflags${opts}-${type} shlwapi.lib) |
| 439 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 440 | list (APPEND TARGETS gflags${opts}-${type}) |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 441 | # add convenience make target for build of both shared and static libraries |
| 442 | if (NOT GFLAGS_IS_SUBPROJECT) |
| 443 | if (NOT TARGET gflags${opts}) |
| 444 | add_custom_target (gflags${opts}) |
| 445 | endif () |
| 446 | add_dependencies (gflags${opts} gflags${opts}-${type}) |
| 447 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 448 | endif () |
| 449 | endforeach () |
Andreas Schuh | ddc5357 | 2014-03-19 17:32:23 +0000 | [diff] [blame] | 450 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 451 | endforeach () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 452 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 453 | # add ALIAS target for use in super-project, prefer static over shared, single-threaded over multi-threaded |
| 454 | if (GFLAGS_IS_SUBPROJECT) |
| 455 | foreach (type IN ITEMS static shared) |
| 456 | foreach (opts IN ITEMS "_nothreads" "") |
| 457 | if (TARGET gflags${opts}-${type}) |
| 458 | add_library (gflags ALIAS gflags${opts}-${type}) |
| 459 | break () |
| 460 | endif () |
| 461 | endforeach () |
| 462 | if (TARGET gflags) |
| 463 | break () |
| 464 | endif () |
| 465 | endforeach () |
| 466 | endif () |
| 467 | |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 468 | # ---------------------------------------------------------------------------- |
Andreas Schuh | 76c53b7 | 2015-03-24 14:44:12 +0000 | [diff] [blame] | 469 | # installation rules |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 470 | file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}") |
| 471 | configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY) |
| 472 | configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY) |
| 473 | |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 474 | if (BUILD_SHARED_LIBS AND INSTALL_SHARED_LIBS) |
| 475 | foreach (opts IN ITEMS "" _nothreads) |
| 476 | if (BUILD_gflags${opts}_LIB) |
| 477 | install (TARGETS gflags${opts}-shared DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib) |
| 478 | endif () |
| 479 | endforeach () |
| 480 | endif () |
| 481 | if (BUILD_STATIC_LIBS AND INSTALL_STATIC_LIBS) |
| 482 | foreach (opts IN ITEMS "" _nothreads) |
| 483 | if (BUILD_gflags${opts}_LIB) |
| 484 | install (TARGETS gflags${opts}-static DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib) |
| 485 | endif () |
| 486 | endforeach () |
| 487 | endif () |
| 488 | |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 489 | if (INSTALL_HEADERS) |
Andreas Schuh | aff8ef8 | 2014-03-27 01:09:20 +0000 | [diff] [blame] | 490 | install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR}) |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 491 | install ( |
| 492 | FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" |
| 493 | RENAME ${PACKAGE_NAME}-config.cmake |
| 494 | DESTINATION ${CONFIG_INSTALL_DIR} |
| 495 | ) |
| 496 | install ( |
| 497 | FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" |
| 498 | DESTINATION ${CONFIG_INSTALL_DIR} |
| 499 | ) |
| 500 | install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake) |
| 501 | if (UNIX) |
| 502 | install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR}) |
| 503 | endif () |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 504 | endif () |
| 505 | |
| 506 | # ---------------------------------------------------------------------------- |
| 507 | # support direct use of build tree |
| 508 | set (INSTALL_PREFIX_REL2CONFIG_DIR .) |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 509 | export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake") |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 510 | export (PACKAGE gflags) |
| 511 | configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY) |
| 512 | |
| 513 | # ---------------------------------------------------------------------------- |
| 514 | # testing - MUST follow the generation of the build tree config file |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 515 | if (BUILD_TESTING) |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 516 | include (CTest) |
unknown | 3d142b8 | 2014-03-19 15:27:08 +0100 | [diff] [blame] | 517 | enable_testing () |
| 518 | add_subdirectory (test) |
| 519 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 520 | |
| 521 | # ---------------------------------------------------------------------------- |
| 522 | # packaging |
| 523 | if (BUILD_PACKAGING) |
| 524 | |
| 525 | if (NOT BUILD_SHARED_LIBS AND NOT INSTALL_HEADERS) |
| 526 | message (WARNING "Package will contain static libraries without headers!" |
| 527 | "\nRecommended options for generation of runtime package:" |
| 528 | "\n BUILD_SHARED_LIBS=ON" |
| 529 | "\n BUILD_STATIC_LIBS=OFF" |
| 530 | "\n INSTALL_HEADERS=OFF" |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 531 | "\n INSTALL_SHARED_LIBS=ON" |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 532 | "\nRecommended options for generation of development package:" |
| 533 | "\n BUILD_SHARED_LIBS=ON" |
| 534 | "\n BUILD_STATIC_LIBS=ON" |
Andreas Schuh | 91e16ee | 2016-03-01 20:03:43 +0000 | [diff] [blame^] | 535 | "\n INSTALL_HEADERS=ON" |
| 536 | "\n INSTALL_SHARED_LIBS=ON" |
| 537 | "\n INSTALL_STATIC_LIBS=ON") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 538 | endif () |
| 539 | |
| 540 | # default package generators |
| 541 | if (APPLE) |
| 542 | set (PACKAGE_GENERATOR "PackageMaker") |
| 543 | set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP") |
| 544 | elseif (UNIX) |
| 545 | set (PACKAGE_GENERATOR "DEB;RPM") |
| 546 | set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP") |
| 547 | else () |
| 548 | set (PACKAGE_GENERATOR "ZIP") |
| 549 | set (PACKAGE_SOURCE_GENERATOR "ZIP") |
| 550 | endif () |
| 551 | |
| 552 | # used package generators |
| 553 | set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).") |
| 554 | set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).") |
| 555 | mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR) |
| 556 | |
Andreas Schuh | 64ac2e3 | 2015-03-24 16:21:44 +0000 | [diff] [blame] | 557 | # some package generators (e.g., PackageMaker) do not allow .md extension |
| 558 | configure_file ("${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_BINARY_DIR}/README.txt" COPYONLY) |
| 559 | |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 560 | # common package information |
Andreas Schuh | fc6e079 | 2014-03-20 04:09:02 +0000 | [diff] [blame] | 561 | set (CPACK_PACKAGE_VENDOR "Andreas Schuh") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 562 | set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com") |
| 563 | set (CPACK_PACKAGE_NAME "${PACKAGE_NAME}") |
| 564 | set (CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}") |
| 565 | set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}") |
| 566 | set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}") |
| 567 | set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}") |
| 568 | set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A commandline flags library that allows for distributed flags.") |
Andreas Schuh | a819f0f | 2015-03-24 16:29:31 +0000 | [diff] [blame] | 569 | set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}/README.txt") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 570 | set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt") |
Andreas Schuh | a819f0f | 2015-03-24 16:29:31 +0000 | [diff] [blame] | 571 | set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/README.txt") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 572 | set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") |
| 573 | set (CPACK_OUTPUT_FILE_PREFIX packages) |
| 574 | set (CPACK_PACKAGE_RELOCATABLE TRUE) |
| 575 | set (CPACK_MONOLITHIC_INSTALL TRUE) |
| 576 | |
Andreas Schuh | e8890f2 | 2014-03-20 04:20:15 +0000 | [diff] [blame] | 577 | # RPM package information -- used in cmake/package.cmake.in also for DEB |
Andreas Schuh | 37a9a90 | 2014-03-20 03:27:13 +0000 | [diff] [blame] | 578 | set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries") |
| 579 | set (CPACK_RPM_PACKAGE_LICENSE "BSD") |
Andreas Schuh | abe4b10 | 2016-03-01 16:01:45 +0000 | [diff] [blame] | 580 | set (CPACK_RPM_PACKAGE_URL "http://gflags.github.io/gflags") |
Andreas Schuh | 37a9a90 | 2014-03-20 03:27:13 +0000 | [diff] [blame] | 581 | set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt") |
| 582 | |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 583 | if (INSTALL_HEADERS) |
Andreas Schuh | 2b8deaa | 2015-03-24 14:41:52 +0000 | [diff] [blame] | 584 | set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 585 | else () |
| 586 | set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt") |
| 587 | endif () |
| 588 | |
Andreas Schuh | d699559 | 2014-03-20 20:21:30 +0000 | [diff] [blame] | 589 | # system/architecture |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 590 | if (WINDOWS) |
| 591 | if (CMAKE_CL_64) |
| 592 | set (CPACK_SYSTEM_NAME "win64") |
| 593 | else () |
| 594 | set (CPACK_SYSTEM_NAME "win32") |
| 595 | endif () |
Andreas Schuh | d699559 | 2014-03-20 20:21:30 +0000 | [diff] [blame] | 596 | set (CPACK_PACKAGE_ARCHITECTURE) |
Andreas Schuh | ef5c547 | 2014-03-30 15:34:13 +0100 | [diff] [blame] | 597 | elseif (APPLE) |
| 598 | set (CPACK_PACKAGE_ARCHITECTURE darwin) |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 599 | else () |
| 600 | string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME) |
Andreas Schuh | cf40f73 | 2014-03-20 20:56:05 +0000 | [diff] [blame] | 601 | if (CMAKE_CXX_FLAGS MATCHES "-m32") |
| 602 | set (CPACK_PACKAGE_ARCHITECTURE i386) |
| 603 | else () |
| 604 | execute_process ( |
| 605 | COMMAND dpkg --print-architecture |
| 606 | RESULT_VARIABLE RV |
| 607 | OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE |
| 608 | ) |
| 609 | if (RV EQUAL 0) |
| 610 | string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE) |
| 611 | else () |
| 612 | execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE) |
| 613 | if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64") |
| 614 | set (CPACK_PACKAGE_ARCHITECTURE amd64) |
| 615 | else () |
| 616 | set (CPACK_PACKAGE_ARCHITECTURE i386) |
| 617 | endif () |
| 618 | endif () |
| 619 | endif () |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 620 | endif () |
| 621 | |
| 622 | # source package settings |
| 623 | set (CPACK_SOURCE_TOPLEVEL_TAG "source") |
| 624 | set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") |
| 625 | set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/") |
| 626 | |
| 627 | # default binary package settings |
Andreas Schuh | d699559 | 2014-03-20 20:21:30 +0000 | [diff] [blame] | 628 | set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE) |
| 629 | set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}") |
| 630 | if (CPACK_PACKAGE_ARCHITECTURE) |
| 631 | set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}") |
Andreas Schuh | 9ecc4ca | 2014-03-20 02:11:44 +0000 | [diff] [blame] | 632 | endif () |
| 633 | |
| 634 | # generator specific configuration file |
| 635 | # |
| 636 | # allow package maintainers to use their own configuration file |
| 637 | # $ cmake -DCPACK_PROJECT_CONFIG_FILE:FILE=/path/to/package/config |
| 638 | if (NOT CPACK_PROJECT_CONFIG_FILE) |
| 639 | configure_file ( |
| 640 | "${CMAKE_CURRENT_LIST_DIR}/cmake/package.cmake.in" |
| 641 | "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake" @ONLY |
| 642 | ) |
| 643 | set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake") |
| 644 | endif () |
| 645 | |
| 646 | include (CPack) |
| 647 | |
| 648 | endif () # BUILD_PACKAGING |