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