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