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