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