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