Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR) |
| 2 | |
| 3 | if (POLICY CMP0042) |
| 4 | cmake_policy (SET CMP0042 NEW) |
| 5 | endif () |
| 6 | |
| 7 | # ---------------------------------------------------------------------------- |
| 8 | # includes |
| 9 | set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 10 | include (utils) |
| 11 | |
| 12 | # ---------------------------------------------------------------------------- |
| 13 | # package information |
| 14 | set (PACKAGE_NAME "gflags") |
| 15 | set (PACKAGE_VERSION "2.2.0") |
| 16 | set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 17 | set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") |
| 18 | set (PACKAGE_BUGREPORT "https://github.com/schuhschuh/gflags/issues") |
| 19 | |
| 20 | project (${PACKAGE_NAME} CXX) |
| 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 () |
| 29 | |
| 30 | version_numbers ( |
| 31 | ${PACKAGE_VERSION} |
| 32 | PACKAGE_VERSION_MAJOR |
| 33 | PACKAGE_VERSION_MINOR |
| 34 | PACKAGE_VERSION_PATCH |
| 35 | ) |
| 36 | |
| 37 | set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}") |
| 38 | |
| 39 | # ---------------------------------------------------------------------------- |
| 40 | # options |
| 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 |
| 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) |
| 46 | endif () |
| 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 \";\").") |
| 51 | endif () |
| 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) |
| 59 | |
| 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) |
| 66 | option (INSTALL_HEADERS "Request packaging of headers and other development files." ON) |
| 67 | |
| 68 | mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX) |
| 69 | mark_as_advanced (CMAKE_CONFIGURATION_TYPES |
| 70 | BUILD_STATIC_LIBS |
| 71 | INSTALL_HEADERS) |
| 72 | if (APPLE) |
| 73 | mark_as_advanced(CMAKE_OSX_ARCHITECTURES |
| 74 | CMAKE_OSX_DEPLOYMENT_TARGET |
| 75 | CMAKE_OSX_SYSROOT) |
| 76 | endif () |
| 77 | |
| 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 | |
| 89 | if (NOT GFLAGS_INCLUDE_DIR) |
| 90 | set (GFLAGS_INCLUDE_DIR "${PACKAGE_NAME}" CACHE STRING "Name of include directory of installed header files") |
| 91 | mark_as_advanced (GFLAGS_INCLUDE_DIR) |
| 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 | |
| 101 | # ---------------------------------------------------------------------------- |
| 102 | # system checks |
| 103 | include (CheckTypeSize) |
| 104 | include (CheckIncludeFileCXX) |
| 105 | include (CheckCXXSymbolExists) |
| 106 | |
| 107 | if (WIN32 AND NOT CYGWIN) |
| 108 | set (OS_WINDOWS 1) |
| 109 | else () |
| 110 | set (OS_WINDOWS 0) |
| 111 | endif () |
| 112 | |
| 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) |
| 120 | set (HAVE_SHLWAPI_H 1) |
| 121 | else () |
| 122 | foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch) |
| 123 | string (TOUPPER "${fname}" FNAME) |
| 124 | string (REPLACE "/" "_" FNAME "${FNAME}") |
| 125 | if (NOT HAVE_${FNAME}_H) |
| 126 | check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H) |
| 127 | endif () |
| 128 | endforeach () |
| 129 | # the following are used in #if directives not #ifdef |
| 130 | bool_to_int (HAVE_STDINT_H) |
| 131 | bool_to_int (HAVE_SYS_TYPES_H) |
| 132 | bool_to_int (HAVE_INTTYPES_H) |
| 133 | if (NOT HAVE_FNMATCH_H AND OS_WINDOWS) |
| 134 | check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H) |
| 135 | endif () |
| 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 () |
| 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 () |
| 185 | endif () |
| 186 | |
| 187 | set (CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 188 | find_package (Threads) |
| 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 | |
| 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 | |
| 228 | set (PRIVATE_HDRS |
| 229 | "config.h" |
| 230 | "util.h" |
| 231 | "mutex.h" |
| 232 | ) |
| 233 | |
| 234 | set (GFLAGS_SRCS |
| 235 | "gflags.cc" |
| 236 | "gflags_reporting.cc" |
| 237 | "gflags_completions.cc" |
| 238 | ) |
| 239 | |
| 240 | if (OS_WINDOWS) |
| 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 | |
| 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 | |
| 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 | # ---------------------------------------------------------------------------- |
| 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 | # ---------------------------------------------------------------------------- |
| 296 | # add library targets |
| 297 | set (TARGETS) |
| 298 | # static vs. shared |
| 299 | foreach (TYPE IN ITEMS STATIC SHARED) |
| 300 | if (BUILD_${TYPE}_LIBS) |
| 301 | # whether or not targets are a DLL |
| 302 | if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$") |
| 303 | set (GFLAGS_IS_A_DLL 1) |
| 304 | else () |
| 305 | set (GFLAGS_IS_A_DLL 0) |
| 306 | endif () |
| 307 | string (TOLOWER "${TYPE}" type) |
| 308 | # multi-threaded vs. single-threaded |
| 309 | foreach (opts IN ITEMS "" _nothreads) |
| 310 | if (BUILD_gflags${opts}_LIB) |
| 311 | add_library (gflags${opts}-${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS}) |
| 312 | set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>") |
| 313 | if (INSTALL_HEADERS) |
| 314 | list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>") |
| 315 | endif () |
| 316 | target_include_directories (gflags${opts}-${type} |
| 317 | PUBLIC "${include_dirs}" |
| 318 | PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}" |
| 319 | ) |
| 320 | if (opts MATCHES "nothreads") |
| 321 | set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL};NOTHREADS") |
| 322 | else () |
| 323 | set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL}") |
| 324 | if (CMAKE_USE_PTHREADS_INIT) |
| 325 | target_link_libraries (gflags${opts}-${type} ${CMAKE_THREAD_LIBS_INIT}) |
| 326 | endif () |
| 327 | endif () |
| 328 | set_target_properties ( |
| 329 | gflags${opts}-${type} PROPERTIES COMPILE_DEFINITIONS "${defines}" |
| 330 | OUTPUT_NAME "gflags${opts}" |
| 331 | VERSION "${PACKAGE_VERSION}" |
| 332 | SOVERSION "${PACKAGE_SOVERSION}" |
| 333 | ) |
| 334 | if (HAVE_SHLWAPI_H) |
| 335 | target_link_libraries (gflags${opts}-${type} shlwapi.lib) |
| 336 | endif () |
| 337 | if (NOT TARGET gflags${opts}) |
| 338 | add_custom_target (gflags${opts}) |
| 339 | endif () |
| 340 | add_dependencies (gflags${opts} gflags${opts}-${type}) |
| 341 | list (APPEND TARGETS gflags${opts}-${type}) |
| 342 | endif () |
| 343 | endforeach () |
| 344 | endif () |
| 345 | endforeach () |
| 346 | |
| 347 | # ---------------------------------------------------------------------------- |
| 348 | # installation rules |
| 349 | file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}") |
| 350 | configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY) |
| 351 | configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY) |
| 352 | |
| 353 | install (TARGETS ${TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib) |
| 354 | if (INSTALL_HEADERS) |
| 355 | install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR}) |
| 356 | install ( |
| 357 | FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" |
| 358 | RENAME ${PACKAGE_NAME}-config.cmake |
| 359 | DESTINATION ${CONFIG_INSTALL_DIR} |
| 360 | ) |
| 361 | install ( |
| 362 | FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" |
| 363 | DESTINATION ${CONFIG_INSTALL_DIR} |
| 364 | ) |
| 365 | install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake) |
| 366 | if (UNIX) |
| 367 | install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR}) |
| 368 | endif () |
| 369 | endif () |
| 370 | |
| 371 | # ---------------------------------------------------------------------------- |
| 372 | # support direct use of build tree |
| 373 | set (INSTALL_PREFIX_REL2CONFIG_DIR .) |
| 374 | export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake") |
| 375 | export (PACKAGE gflags) |
| 376 | configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY) |
| 377 | |
| 378 | # ---------------------------------------------------------------------------- |
| 379 | # testing - MUST follow the generation of the build tree config file |
| 380 | if (BUILD_TESTING) |
| 381 | include (CTest) |
| 382 | enable_testing () |
| 383 | add_subdirectory (test) |
| 384 | endif () |
| 385 | |
| 386 | # ---------------------------------------------------------------------------- |
| 387 | # packaging |
| 388 | if (BUILD_PACKAGING) |
| 389 | |
| 390 | if (NOT BUILD_SHARED_LIBS AND NOT INSTALL_HEADERS) |
| 391 | message (WARNING "Package will contain static libraries without headers!" |
| 392 | "\nRecommended options for generation of runtime package:" |
| 393 | "\n BUILD_SHARED_LIBS=ON" |
| 394 | "\n BUILD_STATIC_LIBS=OFF" |
| 395 | "\n INSTALL_HEADERS=OFF" |
| 396 | "\nRecommended options for generation of development package:" |
| 397 | "\n BUILD_SHARED_LIBS=ON" |
| 398 | "\n BUILD_STATIC_LIBS=ON" |
| 399 | "\n INSTALL_HEADERS=ON") |
| 400 | endif () |
| 401 | |
| 402 | # default package generators |
| 403 | if (APPLE) |
| 404 | set (PACKAGE_GENERATOR "PackageMaker") |
| 405 | set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP") |
| 406 | elseif (UNIX) |
| 407 | set (PACKAGE_GENERATOR "DEB;RPM") |
| 408 | set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP") |
| 409 | else () |
| 410 | set (PACKAGE_GENERATOR "ZIP") |
| 411 | set (PACKAGE_SOURCE_GENERATOR "ZIP") |
| 412 | endif () |
| 413 | |
| 414 | # used package generators |
| 415 | set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).") |
| 416 | set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).") |
| 417 | mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR) |
| 418 | |
| 419 | # some package generators (e.g., PackageMaker) do not allow .md extension |
| 420 | configure_file ("${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_BINARY_DIR}/README.txt" COPYONLY) |
| 421 | |
| 422 | # common package information |
| 423 | set (CPACK_PACKAGE_VENDOR "Andreas Schuh") |
| 424 | set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com") |
| 425 | set (CPACK_PACKAGE_NAME "${PACKAGE_NAME}") |
| 426 | set (CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}") |
| 427 | set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}") |
| 428 | set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}") |
| 429 | set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}") |
| 430 | set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A commandline flags library that allows for distributed flags.") |
| 431 | set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}/README.txt") |
| 432 | set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt") |
| 433 | set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/README.txt") |
| 434 | set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") |
| 435 | set (CPACK_OUTPUT_FILE_PREFIX packages) |
| 436 | set (CPACK_PACKAGE_RELOCATABLE TRUE) |
| 437 | set (CPACK_MONOLITHIC_INSTALL TRUE) |
| 438 | |
| 439 | # RPM package information -- used in cmake/package.cmake.in also for DEB |
| 440 | set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries") |
| 441 | set (CPACK_RPM_PACKAGE_LICENSE "BSD") |
| 442 | set (CPACK_RPM_PACKAGE_URL "http://schuhschuh.github.com/gflags") |
| 443 | set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt") |
| 444 | |
| 445 | if (INSTALL_HEADERS) |
| 446 | set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html") |
| 447 | else () |
| 448 | set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt") |
| 449 | endif () |
| 450 | |
| 451 | # system/architecture |
| 452 | if (WINDOWS) |
| 453 | if (CMAKE_CL_64) |
| 454 | set (CPACK_SYSTEM_NAME "win64") |
| 455 | else () |
| 456 | set (CPACK_SYSTEM_NAME "win32") |
| 457 | endif () |
| 458 | set (CPACK_PACKAGE_ARCHITECTURE) |
| 459 | elseif (APPLE) |
| 460 | set (CPACK_PACKAGE_ARCHITECTURE darwin) |
| 461 | else () |
| 462 | string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME) |
| 463 | if (CMAKE_CXX_FLAGS MATCHES "-m32") |
| 464 | set (CPACK_PACKAGE_ARCHITECTURE i386) |
| 465 | else () |
| 466 | execute_process ( |
| 467 | COMMAND dpkg --print-architecture |
| 468 | RESULT_VARIABLE RV |
| 469 | OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE |
| 470 | ) |
| 471 | if (RV EQUAL 0) |
| 472 | string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE) |
| 473 | else () |
| 474 | execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE) |
| 475 | if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64") |
| 476 | set (CPACK_PACKAGE_ARCHITECTURE amd64) |
| 477 | else () |
| 478 | set (CPACK_PACKAGE_ARCHITECTURE i386) |
| 479 | endif () |
| 480 | endif () |
| 481 | endif () |
| 482 | endif () |
| 483 | |
| 484 | # source package settings |
| 485 | set (CPACK_SOURCE_TOPLEVEL_TAG "source") |
| 486 | set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") |
| 487 | set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/") |
| 488 | |
| 489 | # default binary package settings |
| 490 | set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE) |
| 491 | set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}") |
| 492 | if (CPACK_PACKAGE_ARCHITECTURE) |
| 493 | set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}") |
| 494 | endif () |
| 495 | |
| 496 | # generator specific configuration file |
| 497 | # |
| 498 | # allow package maintainers to use their own configuration file |
| 499 | # $ cmake -DCPACK_PROJECT_CONFIG_FILE:FILE=/path/to/package/config |
| 500 | if (NOT CPACK_PROJECT_CONFIG_FILE) |
| 501 | configure_file ( |
| 502 | "${CMAKE_CURRENT_LIST_DIR}/cmake/package.cmake.in" |
| 503 | "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake" @ONLY |
| 504 | ) |
| 505 | set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake") |
| 506 | endif () |
| 507 | |
| 508 | include (CPack) |
| 509 | |
| 510 | endif () # BUILD_PACKAGING |