github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/3rd_party/build_option_bak/CMakeLists.txt-gflags (about)

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