mirror of
https://github.com/gflags/gflags.git
synced 2025-04-15 01:18:12 +00:00
Compare commits
No commits in common. "master" and "v2.1.0" have entirely different histories.
57 changed files with 1745 additions and 2368 deletions
51
.github/workflows/test.yml
vendored
51
.github/workflows/test.yml
vendored
|
@ -1,51 +0,0 @@
|
||||||
name: Build and Run Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: test-${{ github.event.pull_request.number || github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Test on ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
# - macos-latest
|
|
||||||
# - windows-latest
|
|
||||||
cmake:
|
|
||||||
- '4.0'
|
|
||||||
- '3.31'
|
|
||||||
fail-fast: false
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- name: Checkout Project
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Setup cmake
|
|
||||||
uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be # v2.0.2
|
|
||||||
with:
|
|
||||||
cmake-version: ${{ matrix.cmake }}
|
|
||||||
- name: Setup Ninja
|
|
||||||
uses: seanmiddleditch/gha-setup-ninja@3b1f8f94a2f8254bd26914c4ab9474d4f0015f67 # v6
|
|
||||||
- name: Configure CMake
|
|
||||||
run: |
|
|
||||||
cmake -B build -G Ninja \
|
|
||||||
-D CMAKE_CXX_COMPILER=clang++ \
|
|
||||||
-D CMAKE_BUILD_TYPE=Release \
|
|
||||||
-D GFLAGS_BUILD_SHARED_LIBS=ON \
|
|
||||||
-D GFLAGS_BUILD_STATIC_LIBS=ON \
|
|
||||||
-D GFLAGS_BUILD_TESTING=ON
|
|
||||||
- name: Build Tests
|
|
||||||
run: cmake --build build --config Release
|
|
||||||
- name: Run Tests
|
|
||||||
run: cd build && ctest
|
|
11
.gitignore
vendored
11
.gitignore
vendored
|
@ -1,8 +1,3 @@
|
||||||
/xcode/
|
|
||||||
/build/
|
|
||||||
/builds/
|
|
||||||
/build-*/
|
|
||||||
/_build/
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
DartConfiguration.tcl
|
DartConfiguration.tcl
|
||||||
|
@ -17,9 +12,3 @@ CMakeFiles/
|
||||||
/test/gflags_unittest_main.cc
|
/test/gflags_unittest_main.cc
|
||||||
/test/gflags_unittest-main.cc
|
/test/gflags_unittest-main.cc
|
||||||
/packages/
|
/packages/
|
||||||
CMakeLists.txt.user
|
|
||||||
/bazel-bin
|
|
||||||
/bazel-genfiles
|
|
||||||
/bazel-gflags
|
|
||||||
/bazel-out
|
|
||||||
/bazel-testlogs
|
|
||||||
|
|
26
BUILD
26
BUILD
|
@ -1,26 +0,0 @@
|
||||||
# Bazel (http://bazel.io/) BUILD file for gflags.
|
|
||||||
#
|
|
||||||
# See INSTALL.md for instructions for adding gflags to a Bazel workspace.
|
|
||||||
|
|
||||||
licenses(["notice"])
|
|
||||||
|
|
||||||
exports_files([
|
|
||||||
"src/gflags_completions.sh",
|
|
||||||
"COPYING.txt",
|
|
||||||
])
|
|
||||||
|
|
||||||
config_setting(
|
|
||||||
name = "x64_windows",
|
|
||||||
values = {"cpu": "x64_windows"},
|
|
||||||
)
|
|
||||||
|
|
||||||
config_setting(
|
|
||||||
name = "android",
|
|
||||||
values = {"crosstool_top": "//external:android/crosstool"},
|
|
||||||
)
|
|
||||||
|
|
||||||
load(":bazel/gflags.bzl", "gflags_library", "gflags_sources")
|
|
||||||
|
|
||||||
(hdrs, srcs) = gflags_sources(namespace=["google", "gflags"])
|
|
||||||
gflags_library(hdrs=hdrs, srcs=srcs, threads=0)
|
|
||||||
gflags_library(hdrs=hdrs, srcs=srcs, threads=1)
|
|
600
CMakeLists.txt
600
CMakeLists.txt
|
@ -1,112 +1,19 @@
|
||||||
## CMake configuration file of gflags project
|
cmake_minimum_required (VERSION 2.8.4 FATAL_ERROR)
|
||||||
##
|
|
||||||
## This CMakeLists.txt defines some gflags specific configuration variables
|
|
||||||
## using the "gflags_define" utility macro. The default values of these variables
|
|
||||||
## can be overridden either on the CMake command-line using the -D option of
|
|
||||||
## the cmake command or in a super-project which includes the gflags source
|
|
||||||
## tree by setting the GFLAGS_<varname> CMake variables before adding the
|
|
||||||
## gflags source directory via CMake's "add_subdirectory" command. Only when
|
|
||||||
## the non-cached variable GFLAGS_IS_SUBPROJECT has a value equivalent to FALSE,
|
|
||||||
## these configuration variables are added to the CMake cache so they can be
|
|
||||||
## edited in the CMake GUI. By default, GFLAGS_IS_SUBPROJECT is set to TRUE when
|
|
||||||
## the CMAKE_SOURCE_DIR is not identical to the directory of this CMakeLists.txt
|
|
||||||
## file, i.e., the top-level directory of the gflags project source tree.
|
|
||||||
##
|
|
||||||
## When this project is a subproject (GFLAGS_IS_SUBPROJECT is TRUE), the default
|
|
||||||
## settings are such that only the static single-threaded library is built without
|
|
||||||
## installation of the gflags files. The "gflags::gflags" target is in this case an ALIAS
|
|
||||||
## library target for the "gflags_nothreads_static" library target. Targets which
|
|
||||||
## depend on the gflags library should link to the "gflags::gflags" library target.
|
|
||||||
##
|
|
||||||
## Example CMakeLists.txt of user project which requires separate gflags installation:
|
|
||||||
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
|
||||||
##
|
|
||||||
## project(Foo)
|
|
||||||
##
|
|
||||||
## find_package(gflags REQUIRED)
|
|
||||||
##
|
|
||||||
## add_executable(foo src/foo.cc)
|
|
||||||
## target_link_libraries(foo gflags::gflags)
|
|
||||||
##
|
|
||||||
## Example CMakeLists.txt of user project which requires separate single-threaded static gflags installation:
|
|
||||||
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
|
||||||
##
|
|
||||||
## project(Foo)
|
|
||||||
##
|
|
||||||
## find_package(gflags COMPONENTS nothreads_static)
|
|
||||||
##
|
|
||||||
## add_executable(foo src/foo.cc)
|
|
||||||
## target_link_libraries(foo gflags::gflags)
|
|
||||||
##
|
|
||||||
## Example CMakeLists.txt of super-project which contains gflags source tree:
|
|
||||||
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
|
||||||
##
|
|
||||||
## project(Foo)
|
|
||||||
##
|
|
||||||
## add_subdirectory(gflags)
|
|
||||||
##
|
|
||||||
## add_executable(foo src/foo.cc)
|
|
||||||
## target_link_libraries(foo gflags::gflags)
|
|
||||||
##
|
|
||||||
## Variables to configure the source files:
|
|
||||||
## - GFLAGS_IS_A_DLL
|
|
||||||
## - GFLAGS_NAMESPACE
|
|
||||||
## - GFLAGS_ATTRIBUTE_UNUSED
|
|
||||||
## - GFLAGS_INTTYPES_FORMAT
|
|
||||||
##
|
|
||||||
## Variables to configure the build:
|
|
||||||
## - GFLAGS_SOVERSION
|
|
||||||
## - GFLAGS_BUILD_SHARED_LIBS
|
|
||||||
## - GFLAGS_BUILD_STATIC_LIBS
|
|
||||||
## - GFLAGS_BUILD_gflags_LIB
|
|
||||||
## - GFLAGS_BUILD_gflags_nothreads_LIB
|
|
||||||
## - GFLAGS_BUILD_TESTING
|
|
||||||
## - GFLAGS_BUILD_PACKAGING
|
|
||||||
##
|
|
||||||
## Variables to configure the installation:
|
|
||||||
## - GFLAGS_INCLUDE_DIR
|
|
||||||
## - GFLAGS_LIBRARY_INSTALL_DIR or LIB_INSTALL_DIR or LIB_SUFFIX
|
|
||||||
## - GFLAGS_INSTALL_HEADERS
|
|
||||||
## - GFLAGS_INSTALL_SHARED_LIBS
|
|
||||||
## - GFLAGS_INSTALL_STATIC_LIBS
|
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
|
|
||||||
|
|
||||||
if (POLICY CMP0042)
|
|
||||||
cmake_policy (SET CMP0042 NEW)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (POLICY CMP0048)
|
|
||||||
cmake_policy (SET CMP0048 NEW)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (POLICY CMP0063)
|
|
||||||
cmake_policy (SET CMP0063 NEW)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# includes
|
# includes
|
||||||
include ("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
|
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
|
include (utils)
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# package information
|
# package information
|
||||||
set (PACKAGE_NAME "gflags")
|
set (PACKAGE_NAME "gflags")
|
||||||
set (PACKAGE_VERSION "2.2.2")
|
set (PACKAGE_VERSION "2.1.0")
|
||||||
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
||||||
set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
|
set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
|
||||||
set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues")
|
set (PACKAGE_BUGREPORT "https://code.google.com/p/gflags/issues/")
|
||||||
set (PACKAGE_DESCRIPTION "A commandline flags library that allows for distributed flags.")
|
|
||||||
set (PACKAGE_URL "http://gflags.github.io/gflags")
|
|
||||||
|
|
||||||
project (${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES CXX)
|
project (${PACKAGE_NAME} CXX)
|
||||||
if (CMAKE_VERSION VERSION_LESS 3.4)
|
|
||||||
# C language still needed because the following required CMake modules
|
|
||||||
# (or their dependencies, respectively) are not correctly handling
|
|
||||||
# the case where only CXX is enabled
|
|
||||||
# - CheckTypeSize.cmake (fixed in CMake 3.1, cf. https://cmake.org/Bug/view.php?id=14056)
|
|
||||||
# - FindThreads.cmake (fixed in CMake 3.4, cf. https://cmake.org/Bug/view.php?id=14905)
|
|
||||||
enable_language (C)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
version_numbers (
|
version_numbers (
|
||||||
${PACKAGE_VERSION}
|
${PACKAGE_VERSION}
|
||||||
|
@ -115,110 +22,41 @@ version_numbers (
|
||||||
PACKAGE_VERSION_PATCH
|
PACKAGE_VERSION_PATCH
|
||||||
)
|
)
|
||||||
|
|
||||||
# shared library ABI version number, can be overridden by package maintainers
|
|
||||||
# using -DGFLAGS_SOVERSION=XXX on the command-line
|
|
||||||
if (GFLAGS_SOVERSION)
|
|
||||||
set (PACKAGE_SOVERSION "${GFLAGS_SOVERSION}")
|
|
||||||
else ()
|
|
||||||
# TODO: Change default SOVERSION back to PACKAGE_VERSION_MAJOR with the
|
|
||||||
# next increase of major version number (i.e., 3.0.0 -> SOVERSION 3)
|
|
||||||
# The <major>.<minor> SOVERSION should be used for the 2.x releases
|
|
||||||
# versions only which temporarily broke the API by changing the default
|
|
||||||
# namespace from "google" to "gflags".
|
|
||||||
set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# when gflags is included as subproject (e.g., as Git submodule/subtree) in the source
|
|
||||||
# tree of a project that uses it, no variables should be added to the CMake cache;
|
|
||||||
# users may set the non-cached variable GFLAGS_IS_SUBPROJECT before add_subdirectory(gflags)
|
|
||||||
if (NOT DEFINED GFLAGS_IS_SUBPROJECT)
|
|
||||||
if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
|
|
||||||
set (GFLAGS_IS_SUBPROJECT FALSE)
|
|
||||||
else ()
|
|
||||||
set (GFLAGS_IS_SUBPROJECT TRUE)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# prefix for package variables in CMake configuration file
|
|
||||||
string (TOUPPER "${PACKAGE_NAME}" PACKAGE_PREFIX)
|
|
||||||
|
|
||||||
# convert file path on Windows with back slashes to path with forward slashes
|
|
||||||
# otherwise this causes an issue with the cmake_install.cmake script
|
|
||||||
file (TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# options
|
# options
|
||||||
|
set (GFLAGS_NAMESPACE "${PACKAGE_NAME}" CACHE STRING "C++ namespace identifier of gflags library.")
|
||||||
|
|
||||||
# maintain binary backwards compatibility with gflags library version <= 2.0,
|
option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
|
||||||
# but at the same time enable the use of the preferred new "gflags" namespace
|
option (BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF)
|
||||||
gflags_define (STRING NAMESPACE "Name(s) of library namespace (separate multiple options by semicolon)" "google;${PACKAGE_NAME}" "${PACKAGE_NAME}")
|
option (BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON)
|
||||||
gflags_property (NAMESPACE ADVANCED TRUE)
|
option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON)
|
||||||
set (GFLAGS_NAMESPACE_SECONDARY "${NAMESPACE}")
|
option (BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF)
|
||||||
list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY)
|
option (BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF)
|
||||||
if (NOT GFLAGS_NAMESPACE_SECONDARY)
|
option (BUILD_NC_TESTS "Request addition of negative compilation tests." OFF)
|
||||||
message (FATAL_ERROR "GFLAGS_NAMESPACE must be set to one (or more) valid C++ namespace identifier(s separated by semicolon \";\").")
|
option (INSTALL_HEADERS "Request packaging of headers and other development files." ON)
|
||||||
|
|
||||||
|
mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)
|
||||||
|
mark_as_advanced (CMAKE_CONFIGURATION_TYPES
|
||||||
|
GFLAGS_NAMESPACE
|
||||||
|
BUILD_STATIC_LIBS
|
||||||
|
BUILD_NC_TESTS
|
||||||
|
INSTALL_HEADERS)
|
||||||
|
if (APPLE)
|
||||||
|
mark_as_advanced(CMAKE_OSX_ARCHITECTURES
|
||||||
|
CMAKE_OSX_DEPLOYMENT_TARGET
|
||||||
|
CMAKE_OSX_SYSROOT)
|
||||||
endif ()
|
endif ()
|
||||||
foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
|
|
||||||
if (NOT ns MATCHES "^[a-zA-Z][a-zA-Z0-9_]*$")
|
|
||||||
message (FATAL_ERROR "GFLAGS_NAMESPACE contains invalid namespace identifier: ${ns}")
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
list (GET GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE)
|
|
||||||
list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0)
|
|
||||||
|
|
||||||
# cached build options when gflags is not a subproject, otherwise non-cached CMake variables
|
|
||||||
# usage: gflags_define(BOOL <name> <doc> <default> [<subproject default>])
|
|
||||||
gflags_define (BOOL BUILD_SHARED_LIBS "Request build of shared libraries." OFF OFF)
|
|
||||||
gflags_define (BOOL BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF ON)
|
|
||||||
gflags_define (BOOL BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON OFF)
|
|
||||||
gflags_define (BOOL BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON ON)
|
|
||||||
gflags_define (BOOL BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF OFF)
|
|
||||||
gflags_define (BOOL BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF OFF)
|
|
||||||
gflags_define (BOOL INSTALL_HEADERS "Request installation of headers and other development files." ON OFF)
|
|
||||||
gflags_define (BOOL INSTALL_SHARED_LIBS "Request installation of shared libraries." ON ON)
|
|
||||||
gflags_define (BOOL INSTALL_STATIC_LIBS "Request installation of static libraries." ON OFF)
|
|
||||||
gflags_define (BOOL REGISTER_BUILD_DIR "Request entry of build directory in CMake's package registry." OFF OFF)
|
|
||||||
gflags_define (BOOL REGISTER_INSTALL_PREFIX "Request entry of installed package in CMake's package registry." ON OFF)
|
|
||||||
gflags_define (BOOL EXPORT_NAMESPACE_SET "Request export namespace targets set." ON ON)
|
|
||||||
gflags_define (BOOL EXPORT_NONAMESPACE_SET "Request export nonamespace targets set." ON OFF)
|
|
||||||
|
|
||||||
gflags_property (BUILD_STATIC_LIBS ADVANCED TRUE)
|
|
||||||
gflags_property (INSTALL_HEADERS ADVANCED TRUE)
|
|
||||||
gflags_property (INSTALL_SHARED_LIBS ADVANCED TRUE)
|
|
||||||
gflags_property (INSTALL_STATIC_LIBS ADVANCED TRUE)
|
|
||||||
|
|
||||||
if (NOT GFLAGS_IS_SUBPROJECT)
|
|
||||||
foreach (varname IN ITEMS CMAKE_INSTALL_PREFIX)
|
|
||||||
gflags_property (${varname} ADVANCED FALSE)
|
|
||||||
endforeach ()
|
|
||||||
foreach (varname IN ITEMS CMAKE_CONFIGURATION_TYPES CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
|
||||||
gflags_property (${varname} ADVANCED TRUE)
|
|
||||||
endforeach ()
|
|
||||||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
|
|
||||||
gflags_set (CMAKE_BUILD_TYPE Release)
|
|
||||||
endif ()
|
|
||||||
if (CMAKE_CONFIGURATION_TYPES)
|
|
||||||
gflags_property (CMAKE_BUILD_TYPE STRINGS "${CMAKE_CONFIGURATION_TYPES}")
|
|
||||||
endif ()
|
|
||||||
endif () # NOT GFLAGS_IS_SUBPROJECT
|
|
||||||
|
|
||||||
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
|
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
|
||||||
set (BUILD_STATIC_LIBS ON)
|
set (BUILD_STATIC_LIBS ON)
|
||||||
endif ()
|
endif ()
|
||||||
if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
|
if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
|
||||||
message (FATAL_ERROR "At least one of [GFLAGS_]BUILD_gflags_LIB and [GFLAGS_]BUILD_gflags_nothreads_LIB must be ON.")
|
message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
gflags_define (STRING INCLUDE_DIR "Name of include directory of installed header files relative to CMAKE_INSTALL_PREFIX/include/" "${PACKAGE_NAME}")
|
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
|
||||||
gflags_property (INCLUDE_DIR ADVANCED TRUE)
|
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
|
||||||
file (TO_CMAKE_PATH "${INCLUDE_DIR}" INCLUDE_DIR)
|
|
||||||
if (IS_ABSOLUTE INCLUDE_DIR)
|
|
||||||
message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include/")
|
|
||||||
endif ()
|
endif ()
|
||||||
if (INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
|
|
||||||
message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must not start with parent directory reference (../)")
|
|
||||||
endif ()
|
|
||||||
set (GFLAGS_INCLUDE_DIR "${INCLUDE_DIR}")
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# system checks
|
# system checks
|
||||||
|
@ -234,22 +72,12 @@ endif ()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set (HAVE_SYS_TYPES_H 1)
|
set (HAVE_SYS_TYPES_H 1)
|
||||||
|
set (HAVE_STDINT_H 1)
|
||||||
set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
|
set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
|
||||||
|
set (HAVE_INTTYPES_H 0)
|
||||||
set (HAVE_UNISTD_H 0)
|
set (HAVE_UNISTD_H 0)
|
||||||
set (HAVE_SYS_STAT_H 1)
|
set (HAVE_SYS_STAT_H 1)
|
||||||
set (HAVE_SHLWAPI_H 1)
|
set (HAVE_SHLWAPI_H 1)
|
||||||
if (MSVC_VERSION VERSION_LESS 1600)
|
|
||||||
check_include_file_cxx ("stdint.h" HAVE_STDINT_H)
|
|
||||||
bool_to_int (HAVE_STDINT_H) # used in #if directive
|
|
||||||
else ()
|
|
||||||
set (HAVE_STDINT_H 1)
|
|
||||||
endif ()
|
|
||||||
if (MSVC_VERSION VERSION_LESS 1800)
|
|
||||||
check_include_file_cxx ("inttypes.h" HAVE_INTTYPES_H)
|
|
||||||
bool_to_int (HAVE_INTTYPES_H) # used in #if directive
|
|
||||||
else ()
|
|
||||||
set (HAVE_INTTYPES_H 1)
|
|
||||||
endif ()
|
|
||||||
else ()
|
else ()
|
||||||
foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
|
foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
|
||||||
string (TOUPPER "${fname}" FNAME)
|
string (TOUPPER "${fname}" FNAME)
|
||||||
|
@ -258,19 +86,19 @@ else ()
|
||||||
check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
|
check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
|
||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
if (NOT HAVE_FNMATCH_H AND OS_WINDOWS)
|
|
||||||
check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H)
|
|
||||||
endif ()
|
|
||||||
# the following are used in #if directives not #ifdef
|
# the following are used in #if directives not #ifdef
|
||||||
bool_to_int (HAVE_STDINT_H)
|
bool_to_int (HAVE_STDINT_H)
|
||||||
bool_to_int (HAVE_SYS_TYPES_H)
|
bool_to_int (HAVE_SYS_TYPES_H)
|
||||||
bool_to_int (HAVE_INTTYPES_H)
|
bool_to_int (HAVE_INTTYPES_H)
|
||||||
|
if (NOT HAVE_FNMATCH_H AND OS_WINDOWS)
|
||||||
|
check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H)
|
||||||
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
gflags_define (STRING INTTYPES_FORMAT "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "")
|
set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
|
||||||
gflags_property (INTTYPES_FORMAT STRINGS "C99;BSD;VC7")
|
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")
|
||||||
gflags_property (INTTYPES_FORMAT ADVANCED TRUE)
|
mark_as_advanced (GFLAGS_INTTYPES_FORMAT)
|
||||||
if (NOT INTTYPES_FORMAT)
|
if (NOT GFLAGS_INTTYPES_FORMAT)
|
||||||
set (TYPES uint32_t u_int32_t)
|
set (TYPES uint32_t u_int32_t)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
list (INSERT TYPES 0 __int32)
|
list (INSERT TYPES 0 __int32)
|
||||||
|
@ -282,30 +110,29 @@ if (NOT INTTYPES_FORMAT)
|
||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
if (HAVE_uint32_t)
|
if (HAVE_uint32_t)
|
||||||
gflags_set (INTTYPES_FORMAT C99)
|
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)
|
||||||
elseif (HAVE_u_int32_t)
|
elseif (HAVE_u_int32_t)
|
||||||
gflags_set (INTTYPES_FORMAT BSD)
|
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)
|
||||||
elseif (HAVE___int32)
|
elseif (HAVE___int32)
|
||||||
gflags_set (INTTYPES_FORMAT VC7)
|
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
|
||||||
else ()
|
else ()
|
||||||
gflags_property (INTTYPES_FORMAT ADVANCED FALSE)
|
mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)
|
||||||
message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
|
message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
|
||||||
" Neither uint32_t, u_int32_t, nor __int32 seem to be available."
|
" Neither uint32_t, u_int32_t, nor __int32 seem to be available."
|
||||||
" Set [GFLAGS_]INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
|
" Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
# use of special characters in strings to circumvent bug #0008226
|
# use of special characters in strings to circumvent bug #0008226
|
||||||
if ("^${INTTYPES_FORMAT}$" STREQUAL "^WIN$")
|
if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")
|
||||||
gflags_set (INTTYPES_FORMAT VC7)
|
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
|
||||||
endif ()
|
endif ()
|
||||||
if (NOT INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
|
if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
|
||||||
message (FATAL_ERROR "Invalid value for [GFLAGS_]INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
|
message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
|
||||||
endif ()
|
endif ()
|
||||||
set (GFLAGS_INTTYPES_FORMAT "${INTTYPES_FORMAT}")
|
|
||||||
set (GFLAGS_INTTYPES_FORMAT_C99 0)
|
set (GFLAGS_INTTYPES_FORMAT_C99 0)
|
||||||
set (GFLAGS_INTTYPES_FORMAT_BSD 0)
|
set (GFLAGS_INTTYPES_FORMAT_BSD 0)
|
||||||
set (GFLAGS_INTTYPES_FORMAT_VC7 0)
|
set (GFLAGS_INTTYPES_FORMAT_VC7 0)
|
||||||
set ("GFLAGS_INTTYPES_FORMAT_${INTTYPES_FORMAT}" 1)
|
set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set (HAVE_strtoll 0)
|
set (HAVE_strtoll 0)
|
||||||
|
@ -317,29 +144,26 @@ else ()
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (BUILD_gflags_LIB)
|
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||||
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
find_package (ThreadsCXX)
|
||||||
find_package (Threads)
|
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
|
||||||
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
|
set (HAVE_PTHREAD 1)
|
||||||
set (HAVE_PTHREAD 1)
|
check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
|
||||||
check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
|
|
||||||
else ()
|
|
||||||
set (HAVE_PTHREAD 0)
|
|
||||||
endif ()
|
|
||||||
if (UNIX AND NOT HAVE_PTHREAD)
|
|
||||||
if (CMAKE_HAVE_PTHREAD_H)
|
|
||||||
set (what "library")
|
|
||||||
else ()
|
|
||||||
set (what ".h file")
|
|
||||||
endif ()
|
|
||||||
message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
|
|
||||||
"\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
|
|
||||||
"\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
|
|
||||||
endif ()
|
|
||||||
else ()
|
else ()
|
||||||
set (HAVE_PTHREAD 0)
|
set (HAVE_PTHREAD 0)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (UNIX AND NOT HAVE_PTHREAD AND BUILD_gflags_LIB)
|
||||||
|
if (CMAKE_HAVE_PTHREAD_H)
|
||||||
|
set (what "library")
|
||||||
|
else ()
|
||||||
|
set (what ".h file")
|
||||||
|
endif ()
|
||||||
|
message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
|
||||||
|
"\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
|
||||||
|
"\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
|
||||||
|
endif ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# source files - excluding root subdirectory and/or .in suffix
|
# source files - excluding root subdirectory and/or .in suffix
|
||||||
set (PUBLIC_HDRS
|
set (PUBLIC_HDRS
|
||||||
|
@ -348,21 +172,7 @@ set (PUBLIC_HDRS
|
||||||
"gflags_completions.h"
|
"gflags_completions.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (GFLAGS_NAMESPACE_SECONDARY)
|
|
||||||
set (INCLUDE_GFLAGS_NS_H "// Import gflags library symbols into alternative/deprecated namespace(s)")
|
|
||||||
foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
|
|
||||||
string (TOUPPER "${ns}" NS)
|
|
||||||
set (gflags_ns_h "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/gflags_${ns}.h")
|
|
||||||
configure_file ("${PROJECT_SOURCE_DIR}/src/gflags_ns.h.in" "${gflags_ns_h}" @ONLY)
|
|
||||||
list (APPEND PUBLIC_HDRS "${gflags_ns_h}")
|
|
||||||
set (INCLUDE_GFLAGS_NS_H "${INCLUDE_GFLAGS_NS_H}\n#include \"gflags_${ns}.h\"")
|
|
||||||
endforeach ()
|
|
||||||
else ()
|
|
||||||
set (INCLUDE_GFLAGS_NS_H)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set (PRIVATE_HDRS
|
set (PRIVATE_HDRS
|
||||||
"defines.h"
|
|
||||||
"config.h"
|
"config.h"
|
||||||
"util.h"
|
"util.h"
|
||||||
"mutex.h"
|
"mutex.h"
|
||||||
|
@ -381,64 +191,25 @@ endif ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# configure source files
|
# configure source files
|
||||||
if (NOT DEFINED GFLAGS_ATTRIBUTE_UNUSED)
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
|
||||||
set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
|
else ()
|
||||||
else ()
|
set (GFLAGS_ATTRIBUTE_UNUSED)
|
||||||
set (GFLAGS_ATTRIBUTE_UNUSED)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# whenever we build a shared library (DLL on Windows), configure the public
|
|
||||||
# headers of the API for use of this shared library rather than the optionally
|
|
||||||
# also build statically linked library; users can override GFLAGS_DLL_DECL
|
|
||||||
# in particular, this done by setting the INTERFACE_COMPILE_DEFINITIONS of
|
|
||||||
# static libraries to include an empty definition for GFLAGS_DLL_DECL
|
|
||||||
if (NOT DEFINED GFLAGS_IS_A_DLL)
|
|
||||||
if (BUILD_SHARED_LIBS)
|
|
||||||
set (GFLAGS_IS_A_DLL 1)
|
|
||||||
else ()
|
|
||||||
set (GFLAGS_IS_A_DLL 0)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
|
configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
|
||||||
configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
|
configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
|
||||||
configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
|
configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
include_directories ("${PROJECT_SOURCE_DIR}/src")
|
||||||
# output directories
|
include_directories ("${PROJECT_BINARY_DIR}/include")
|
||||||
if (NOT GFLAGS_IS_SUBPROJECT)
|
include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
|
||||||
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
|
|
||||||
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
|
|
||||||
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
|
|
||||||
endif ()
|
|
||||||
# Set postfixes for generated libraries based on buildtype.
|
|
||||||
set(CMAKE_RELEASE_POSTFIX "")
|
|
||||||
set(CMAKE_DEBUG_POSTFIX "_debug")
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# installation directories
|
# output directories
|
||||||
if (OS_WINDOWS AND NOT MINGW)
|
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
|
||||||
set (RUNTIME_INSTALL_DIR "bin")
|
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
|
||||||
set (LIBRARY_INSTALL_DIR "lib")
|
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
|
||||||
set (INCLUDE_INSTALL_DIR "include")
|
|
||||||
set (CONFIG_INSTALL_DIR "lib/cmake/${PACKAGE_NAME}")
|
|
||||||
set (PKGCONFIG_INSTALL_DIR)
|
|
||||||
else ()
|
|
||||||
set (RUNTIME_INSTALL_DIR bin)
|
|
||||||
# The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora
|
|
||||||
# package maintainers. Also package maintainers of other distribution
|
|
||||||
# packages need to be able to specify the name of the library directory.
|
|
||||||
if (NOT GFLAGS_LIBRARY_INSTALL_DIR AND LIB_INSTALL_DIR)
|
|
||||||
set (GFLAGS_LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}")
|
|
||||||
endif ()
|
|
||||||
gflags_define (PATH LIBRARY_INSTALL_DIR "Directory of installed libraries, e.g., \"lib64\"" "lib${LIB_SUFFIX}")
|
|
||||||
gflags_property (LIBRARY_INSTALL_DIR ADVANCED TRUE)
|
|
||||||
set (INCLUDE_INSTALL_DIR include)
|
|
||||||
set (CONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME})
|
|
||||||
set (PKGCONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/pkgconfig)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# add library targets
|
# add library targets
|
||||||
|
@ -446,112 +217,63 @@ set (TARGETS)
|
||||||
# static vs. shared
|
# static vs. shared
|
||||||
foreach (TYPE IN ITEMS STATIC SHARED)
|
foreach (TYPE IN ITEMS STATIC SHARED)
|
||||||
if (BUILD_${TYPE}_LIBS)
|
if (BUILD_${TYPE}_LIBS)
|
||||||
string (TOLOWER "${TYPE}" type)
|
|
||||||
# whether or not targets are a DLL
|
# whether or not targets are a DLL
|
||||||
if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$")
|
if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$")
|
||||||
set (GFLAGS_IS_A_DLL 1)
|
set (GFLAGS_IS_A_DLL 1)
|
||||||
else ()
|
else ()
|
||||||
set (GFLAGS_IS_A_DLL 0)
|
set (GFLAGS_IS_A_DLL 0)
|
||||||
endif ()
|
endif ()
|
||||||
# filename suffix for static libraries on Windows for MSVC toolchain only
|
string (TOLOWER "${TYPE}" type)
|
||||||
if (OS_WINDOWS AND NOT MINGW AND "^${TYPE}$" STREQUAL "^STATIC$")
|
|
||||||
set (type_suffix "_${type}")
|
|
||||||
else ()
|
|
||||||
set (type_suffix "")
|
|
||||||
endif ()
|
|
||||||
# multi-threaded vs. single-threaded
|
# multi-threaded vs. single-threaded
|
||||||
foreach (opts IN ITEMS "" _nothreads)
|
foreach (opts IN ITEMS "" _nothreads)
|
||||||
if (BUILD_gflags${opts}_LIB)
|
if (BUILD_gflags${opts}_LIB)
|
||||||
set (target_name "gflags${opts}_${type}")
|
add_library (gflags${opts}-${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
|
||||||
add_library (${target_name} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
|
|
||||||
set_target_properties (${target_name} PROPERTIES
|
|
||||||
OUTPUT_NAME "gflags${opts}${type_suffix}"
|
|
||||||
VERSION "${PACKAGE_VERSION}"
|
|
||||||
SOVERSION "${PACKAGE_SOVERSION}"
|
|
||||||
)
|
|
||||||
set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>")
|
|
||||||
if (INSTALL_HEADERS)
|
|
||||||
list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")
|
|
||||||
endif ()
|
|
||||||
target_include_directories (${target_name}
|
|
||||||
PUBLIC "${include_dirs}"
|
|
||||||
PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}"
|
|
||||||
)
|
|
||||||
target_compile_definitions (${target_name} PUBLIC GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL})
|
|
||||||
if (opts MATCHES "nothreads")
|
if (opts MATCHES "nothreads")
|
||||||
target_compile_definitions (${target_name} PRIVATE NO_THREADS)
|
set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL};NOTHREADS")
|
||||||
elseif (CMAKE_USE_PTHREADS_INIT)
|
else ()
|
||||||
target_link_libraries (${target_name} ${CMAKE_THREAD_LIBS_INIT})
|
set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL}")
|
||||||
endif ()
|
if (CMAKE_USE_PTHREADS_INIT)
|
||||||
if (HAVE_SHLWAPI_H)
|
target_link_libraries (gflags${opts}-${type} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (${target_name} shlwapi.lib)
|
|
||||||
endif ()
|
|
||||||
list (APPEND TARGETS ${target_name})
|
|
||||||
# add convenience make target for build of both shared and static libraries
|
|
||||||
if (NOT GFLAGS_IS_SUBPROJECT)
|
|
||||||
if (NOT TARGET gflags${opts})
|
|
||||||
add_custom_target (gflags${opts})
|
|
||||||
endif ()
|
endif ()
|
||||||
add_dependencies (gflags${opts} ${target_name})
|
|
||||||
endif ()
|
endif ()
|
||||||
|
set_target_properties (
|
||||||
|
gflags${opts}-${type} PROPERTIES COMPILE_DEFINITIONS "${defines}"
|
||||||
|
OUTPUT_NAME "gflags${opts}"
|
||||||
|
)
|
||||||
|
if (HAVE_SHLWAPI_H)
|
||||||
|
target_link_libraries (gflags${opts}-${type} shlwapi.lib)
|
||||||
|
endif ()
|
||||||
|
if (NOT TARGET gflags${opts})
|
||||||
|
add_custom_target (gflags${opts})
|
||||||
|
endif ()
|
||||||
|
add_dependencies (gflags${opts} gflags${opts}-${type})
|
||||||
|
list (APPEND TARGETS gflags${opts}-${type})
|
||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
# add ALIAS target for use in super-project, prefer static over shared, single-threaded over multi-threaded
|
# ----------------------------------------------------------------------------
|
||||||
if (GFLAGS_IS_SUBPROJECT)
|
# installation
|
||||||
foreach (type IN ITEMS static shared)
|
if (OS_WINDOWS)
|
||||||
foreach (opts IN ITEMS "_nothreads" "")
|
set (RUNTIME_INSTALL_DIR Bin)
|
||||||
if (TARGET gflags${opts}_${type})
|
set (LIBRARY_INSTALL_DIR Lib)
|
||||||
# Define "gflags" alias for super-projects treating targets of this library as part of their own project
|
set (INCLUDE_INSTALL_DIR Include)
|
||||||
# (also for backwards compatibility with gflags 2.2.1 which only defined this alias)
|
set (CONFIG_INSTALL_DIR CMake)
|
||||||
add_library (gflags ALIAS gflags${opts}_${type})
|
else ()
|
||||||
# Define "gflags::gflags" alias for projects that support both find_package(gflags) and add_subdirectory(gflags)
|
set (RUNTIME_INSTALL_DIR bin)
|
||||||
add_library (gflags::gflags ALIAS gflags${opts}_${type})
|
set (LIBRARY_INSTALL_DIR lib)
|
||||||
break ()
|
set (INCLUDE_INSTALL_DIR include)
|
||||||
endif ()
|
set (CONFIG_INSTALL_DIR lib/cmake/${PACKAGE_NAME})
|
||||||
endforeach ()
|
|
||||||
if (TARGET gflags::gflags)
|
|
||||||
break ()
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# installation rules
|
|
||||||
set (EXPORT_NAME ${PACKAGE_NAME}-targets)
|
|
||||||
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
|
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
|
||||||
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
|
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
|
||||||
configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
|
configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
|
||||||
|
|
||||||
if (BUILD_SHARED_LIBS AND INSTALL_SHARED_LIBS)
|
install (TARGETS ${TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
|
||||||
foreach (opts IN ITEMS "" _nothreads)
|
|
||||||
if (BUILD_gflags${opts}_LIB)
|
|
||||||
install (TARGETS gflags${opts}_shared
|
|
||||||
EXPORT ${EXPORT_NAME}
|
|
||||||
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
|
|
||||||
LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
|
|
||||||
ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
endif ()
|
|
||||||
if (BUILD_STATIC_LIBS AND INSTALL_STATIC_LIBS)
|
|
||||||
foreach (opts IN ITEMS "" _nothreads)
|
|
||||||
if (BUILD_gflags${opts}_LIB)
|
|
||||||
install (TARGETS gflags${opts}_static
|
|
||||||
EXPORT ${EXPORT_NAME}
|
|
||||||
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
|
|
||||||
LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
|
|
||||||
ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (INSTALL_HEADERS)
|
if (INSTALL_HEADERS)
|
||||||
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR})
|
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})
|
||||||
install (
|
install (
|
||||||
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
|
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
|
||||||
RENAME ${PACKAGE_NAME}-config.cmake
|
RENAME ${PACKAGE_NAME}-config.cmake
|
||||||
|
@ -561,57 +283,24 @@ if (INSTALL_HEADERS)
|
||||||
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
|
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
|
||||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||||
)
|
)
|
||||||
if (EXPORT_NAMESPACE_SET)
|
install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
|
||||||
install (
|
|
||||||
EXPORT ${EXPORT_NAME}
|
|
||||||
NAMESPACE ${PACKAGE_NAME}::
|
|
||||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
if (EXPORT_NONAMESPACE_SET)
|
|
||||||
install (
|
|
||||||
EXPORT ${EXPORT_NAME}
|
|
||||||
FILE ${PACKAGE_NAME}-nonamespace-targets.cmake
|
|
||||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
|
install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
|
||||||
endif ()
|
endif ()
|
||||||
if (PKGCONFIG_INSTALL_DIR)
|
|
||||||
configure_file ("cmake/package.pc.in" "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}.pc" @ONLY)
|
|
||||||
install (FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# support direct use of build tree
|
# support direct use of build tree
|
||||||
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
|
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
|
||||||
if (EXPORT_NAMESPACE_SET)
|
export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
|
||||||
export (
|
export (PACKAGE gflags)
|
||||||
TARGETS ${TARGETS}
|
|
||||||
NAMESPACE ${PACKAGE_NAME}::
|
|
||||||
FILE "${PROJECT_BINARY_DIR}/${EXPORT_NAME}.cmake"
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
if (EXPORT_NONAMESPACE_SET)
|
|
||||||
export (
|
|
||||||
TARGETS ${TARGETS}
|
|
||||||
FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-nonamespace-targets.cmake"
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
if (REGISTER_BUILD_DIR)
|
|
||||||
export (PACKAGE ${PACKAGE_NAME})
|
|
||||||
endif ()
|
|
||||||
if (REGISTER_INSTALL_PREFIX)
|
|
||||||
register_gflags_package(${CONFIG_INSTALL_DIR})
|
|
||||||
endif ()
|
|
||||||
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
|
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# testing - MUST follow the generation of the build tree config file
|
# testing - MUST follow the generation of the build tree config file
|
||||||
if (BUILD_TESTING)
|
if (BUILD_TESTING)
|
||||||
include (CTest)
|
include (CTest)
|
||||||
|
enable_testing ()
|
||||||
add_subdirectory (test)
|
add_subdirectory (test)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
@ -625,14 +314,10 @@ if (BUILD_PACKAGING)
|
||||||
"\n BUILD_SHARED_LIBS=ON"
|
"\n BUILD_SHARED_LIBS=ON"
|
||||||
"\n BUILD_STATIC_LIBS=OFF"
|
"\n BUILD_STATIC_LIBS=OFF"
|
||||||
"\n INSTALL_HEADERS=OFF"
|
"\n INSTALL_HEADERS=OFF"
|
||||||
"\n INSTALL_SHARED_LIBS=ON"
|
|
||||||
"\nRecommended options for generation of development package:"
|
"\nRecommended options for generation of development package:"
|
||||||
"\n BUILD_SHARED_LIBS=ON"
|
"\n BUILD_SHARED_LIBS=ON"
|
||||||
"\n BUILD_STATIC_LIBS=ON"
|
"\n BUILD_STATIC_LIBS=ON"
|
||||||
"\n INSTALL_HEADERS=ON"
|
"\n INSTALL_HEADERS=ON")
|
||||||
"\n INSTALL_SHARED_LIBS=ON"
|
|
||||||
"\n INSTALL_STATIC_LIBS=ON"
|
|
||||||
)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# default package generators
|
# default package generators
|
||||||
|
@ -652,9 +337,6 @@ if (BUILD_PACKAGING)
|
||||||
set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
|
set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
|
||||||
mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR)
|
mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR)
|
||||||
|
|
||||||
# some package generators (e.g., PackageMaker) do not allow .md extension
|
|
||||||
configure_file ("${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_BINARY_DIR}/README.txt" COPYONLY)
|
|
||||||
|
|
||||||
# common package information
|
# common package information
|
||||||
set (CPACK_PACKAGE_VENDOR "Andreas Schuh")
|
set (CPACK_PACKAGE_VENDOR "Andreas Schuh")
|
||||||
set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com")
|
set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com")
|
||||||
|
@ -663,10 +345,10 @@ if (BUILD_PACKAGING)
|
||||||
set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
|
set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
|
||||||
set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
|
set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
|
||||||
set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
|
set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
|
||||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE_DESCRIPTION}")
|
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A commandline flags library that allows for distributed flags.")
|
||||||
set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
|
set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_LIST_DIR}/README.txt")
|
||||||
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt")
|
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt")
|
||||||
set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
|
set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_LIST_DIR}/README.txt")
|
||||||
set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||||
set (CPACK_OUTPUT_FILE_PREFIX packages)
|
set (CPACK_OUTPUT_FILE_PREFIX packages)
|
||||||
set (CPACK_PACKAGE_RELOCATABLE TRUE)
|
set (CPACK_PACKAGE_RELOCATABLE TRUE)
|
||||||
|
@ -675,46 +357,24 @@ if (BUILD_PACKAGING)
|
||||||
# RPM package information -- used in cmake/package.cmake.in also for DEB
|
# RPM package information -- used in cmake/package.cmake.in also for DEB
|
||||||
set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
|
set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
|
||||||
set (CPACK_RPM_PACKAGE_LICENSE "BSD")
|
set (CPACK_RPM_PACKAGE_LICENSE "BSD")
|
||||||
set (CPACK_RPM_PACKAGE_URL "${PACKAGE_URL}")
|
set (CPACK_RPM_PACKAGE_URL "http://code.google.com/p/gflags")
|
||||||
set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
|
set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
|
||||||
|
|
||||||
if (INSTALL_HEADERS)
|
if (INSTALL_HEADERS)
|
||||||
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html")
|
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/gflags.html")
|
||||||
else ()
|
else ()
|
||||||
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt")
|
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# system/architecture
|
# system name used for binary package file name
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
if (CMAKE_CL_64)
|
if (CMAKE_CL_64)
|
||||||
set (CPACK_SYSTEM_NAME "win64")
|
set (CPACK_SYSTEM_NAME "win64")
|
||||||
else ()
|
else ()
|
||||||
set (CPACK_SYSTEM_NAME "win32")
|
set (CPACK_SYSTEM_NAME "win32")
|
||||||
endif ()
|
endif ()
|
||||||
set (CPACK_PACKAGE_ARCHITECTURE)
|
|
||||||
elseif (APPLE)
|
|
||||||
set (CPACK_PACKAGE_ARCHITECTURE darwin)
|
|
||||||
else ()
|
else ()
|
||||||
string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
|
string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
|
||||||
if (CMAKE_CXX_FLAGS MATCHES "-m32")
|
|
||||||
set (CPACK_PACKAGE_ARCHITECTURE i386)
|
|
||||||
else ()
|
|
||||||
execute_process (
|
|
||||||
COMMAND dpkg --print-architecture
|
|
||||||
RESULT_VARIABLE RV
|
|
||||||
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
|
|
||||||
)
|
|
||||||
if (RV EQUAL 0)
|
|
||||||
string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
|
|
||||||
else ()
|
|
||||||
execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
|
|
||||||
if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
|
|
||||||
set (CPACK_PACKAGE_ARCHITECTURE amd64)
|
|
||||||
else ()
|
|
||||||
set (CPACK_PACKAGE_ARCHITECTURE i386)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# source package settings
|
# source package settings
|
||||||
|
@ -723,10 +383,10 @@ if (BUILD_PACKAGING)
|
||||||
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
|
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
|
||||||
|
|
||||||
# default binary package settings
|
# default binary package settings
|
||||||
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
|
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
|
||||||
if (CPACK_PACKAGE_ARCHITECTURE)
|
if (CMAKE_SYSTEM_PROCESSOR)
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# generator specific configuration file
|
# generator specific configuration file
|
||||||
|
@ -744,11 +404,3 @@ if (BUILD_PACKAGING)
|
||||||
include (CPack)
|
include (CPack)
|
||||||
|
|
||||||
endif () # BUILD_PACKAGING
|
endif () # BUILD_PACKAGING
|
||||||
|
|
||||||
if (NOT GFLAGS_IS_SUBPROJECT AND NOT TARGET uninstall)
|
|
||||||
configure_file (
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" @ONLY
|
|
||||||
)
|
|
||||||
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
|
||||||
endif ()
|
|
||||||
|
|
|
@ -1,78 +1,3 @@
|
||||||
* Sun Nov 11 2018 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
|
||||||
|
|
||||||
- gflags: version 2.2.2
|
|
||||||
Fixed 267: Support build with GCC option "-fvisibility=hidden".
|
|
||||||
Fixed 262: Declare FLAGS_no##name variables as static to avoid "previous extern" warning.
|
|
||||||
Fixed 261: Declare FlagRegisterer c’tor explicit template instanations as extern in header
|
|
||||||
Fixed 257: Build with _UNICODE support on Windows.
|
|
||||||
Fixed 233/234/235: Move CMake defines that are unused by Bazel to separate header; makes config.h private again
|
|
||||||
Fixed 228: Build with recent MinGW versions that define setenv.
|
|
||||||
Fixed 226: Remove obsolete and unused CleanFileName code
|
|
||||||
Merged 266: Various PVS Studio and GCC warnings.
|
|
||||||
Merged 258: Fix build with some Clang variants that define "restrict" macro.
|
|
||||||
Merged 252: Update documentation on how to use Bazel.
|
|
||||||
Merged 249: Use "_debug" postfix for debug libraries.
|
|
||||||
Merged 247: CMake "project" VERSION; no enable_testing(); "gflags::" import target prefix.
|
|
||||||
Merged 246: Add Bazel-on-Windows support.
|
|
||||||
Merged 239: Use GFLAGS_NAMESPACE instead of "gflags" in test executable.
|
|
||||||
Merged 237: Removed unused functions; fixes compilation with -Werror compiler option.
|
|
||||||
Merged 232: Fix typo in Bazel's BUILD definition
|
|
||||||
Merged 230: Remove using ::fLS::clstring.
|
|
||||||
Merged 221: Add convenience 'uninstall' target
|
|
||||||
|
|
||||||
* Tue Jul 11 2017 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
|
||||||
|
|
||||||
- gflags: version 2.2.1
|
|
||||||
- Link to online documentation in README
|
|
||||||
- Merged 194: Include utils by file instead of CMAKE_MODULE_PATH search
|
|
||||||
- Merged 195: Remove unused program_name variable
|
|
||||||
- Merged 196: Enable language C for older CMake versions when needed
|
|
||||||
- Merged 202: Changed include directory in bazel build
|
|
||||||
- Merged 207: Mark single argument constructors in mutex.h as explicit
|
|
||||||
- Merged 209: Use inttypes.h on VC++ 2013 and later
|
|
||||||
- Merged 212: Fix statically linked gflags library with MSVC
|
|
||||||
- Merged 213: Modify installation paths on Windows for vcpkg
|
|
||||||
- Merged 215: Fix static initialization order fiasco caused by global registry lock
|
|
||||||
- Merged 216: Fix use of ARGC in CMake macros
|
|
||||||
- Merged 222: Static code analyzer error regarding strncmp with empty kRootDir
|
|
||||||
- Merged 224: Check HAVE_STDINT_H or HAVE_INTTYPES_H for older MSVC versions
|
|
||||||
|
|
||||||
* Fri Nov 25 2016 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
|
||||||
|
|
||||||
- gflags: version 2.2.0
|
|
||||||
- Merged 178: Implicitly convert dashes in option names to underscores
|
|
||||||
- Merged 159: CI builds and automatic tests with Travis CI and AppVeyor
|
|
||||||
- Merged 158: Use enum for flag value types
|
|
||||||
- Merged 126: File name postfix for static libraries on Windows
|
|
||||||
- Closed issue 120: Configure and install gflags.pc file for pkg-config users
|
|
||||||
- Fixed issue 127: snprintf already defined when building with MSVC 2015
|
|
||||||
- Fixed issue 51/138: Memory leaks reported by valgrind
|
|
||||||
- Fixed issue 173: Validate flags only once
|
|
||||||
- Fixed issue 168: Unsigned and signed comparison in gflags_reporting.cc
|
|
||||||
- Fixed issues 176/153: Add -lpthread link argument to Bazel build, refactor BUILD rules
|
|
||||||
- Fixed issue 89: Add GFLAGS_IS_A_DLL to imported CMake target INTERFACE_COMPILE_DEFINITIONS
|
|
||||||
- Fixed issue 104: Set INTERFACE_INCLUDE_DIRECTORIES of exported CMake targets
|
|
||||||
- Fixed issue 174: Missing gflags-targets.cmake file after installation
|
|
||||||
- Fixed issue 186: Error linking to gflags IMPLIB with MSVC using CMake
|
|
||||||
- Closed issue 106: Add example project to test use of gflags library
|
|
||||||
|
|
||||||
* Tue Mar 24 2014 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
|
||||||
|
|
||||||
- gflags: version 2.1.2
|
|
||||||
- Moved project to GitHub
|
|
||||||
- Added GFLAGS_NAMESPACE definition to gflags_declare.h
|
|
||||||
- Fixed issue 94: Keep "google" as primary namespace and import symbols into "gflags" namespace
|
|
||||||
- Fixed issue 96: Fix binary ABI compatibility with gflags 2.0 using "google" as primary namespace
|
|
||||||
- Fixed issue 97/101: Removed (patched) CMake modules and enabled C language instead
|
|
||||||
- Fixed issue 103: Set CMake policy CMP0042 to silence warning regarding MACOS_RPATH setting
|
|
||||||
|
|
||||||
* Sun Mar 20 2014 - Andreas Schuh <google-gflags@googlegroups.com>
|
|
||||||
|
|
||||||
- gflags: version 2.1.1
|
|
||||||
- Fixed issue 77: GFLAGS_IS_A_DLL expands to empty string in gflags_declare.h
|
|
||||||
- Fixed issue 79: GFLAGS_NAMESPACE not expanded to actual namespace in gflags_declare.h
|
|
||||||
- Fixed issue 80: Allow include path to differ from GFLAGS_NAMESPACE
|
|
||||||
|
|
||||||
* Thu Mar 20 2014 - Andreas Schuh <google-gflags@googlegroups.com>
|
* Thu Mar 20 2014 - Andreas Schuh <google-gflags@googlegroups.com>
|
||||||
|
|
||||||
- gflags: version 2.1.0
|
- gflags: version 2.1.0
|
||||||
|
@ -166,8 +91,8 @@ Merged 221: Add convenience 'uninstall' target
|
||||||
- BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo)
|
- BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo)
|
||||||
- BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo)
|
- BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo)
|
||||||
- PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers)
|
- PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers)
|
||||||
- PORTABILITY: Update deb.sh for more recently debuilds (csilvers)
|
- PORTABILITY: Update deb.sh for more recenty debuilds (csilvers)
|
||||||
- PORTABILITY: #include more headers to satisfy new gcc's (csilvers)
|
- PORTABILITY: #include more headers to satify new gcc's (csilvers)
|
||||||
- INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers)
|
- INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers)
|
||||||
|
|
||||||
* Fri Oct 3 2008 - Google Inc. <opensource@google.com>
|
* Fri Oct 3 2008 - Google Inc. <opensource@google.com>
|
||||||
|
@ -247,7 +172,7 @@ Merged 221: Add convenience 'uninstall' target
|
||||||
- google-gflags: version 0.5
|
- google-gflags: version 0.5
|
||||||
- Include all m4 macros in the distribution (csilvers)
|
- Include all m4 macros in the distribution (csilvers)
|
||||||
- Python: Fix broken data_files field in setup.py (sidlon)
|
- Python: Fix broken data_files field in setup.py (sidlon)
|
||||||
- Python: better string serializing and unparsing (abo, csimmons)
|
- Python: better string serliaizing and unparsing (abo, csimmons)
|
||||||
- Fix checks for NaN and inf to work with Mac OS X (csilvers)
|
- Fix checks for NaN and inf to work with Mac OS X (csilvers)
|
||||||
|
|
||||||
* Thu Apr 19 2007 - Google Inc. <opensource@google.com>
|
* Thu Apr 19 2007 - Google Inc. <opensource@google.com>
|
||||||
|
|
97
INSTALL.md
97
INSTALL.md
|
@ -1,97 +0,0 @@
|
||||||
# Installing a binary distribution package
|
|
||||||
|
|
||||||
No official binary distribution packages are provided by the gflags developers.
|
|
||||||
There may, however, be binary packages available for your operating system.
|
|
||||||
Please consult also the package repositories of your Linux distribution.
|
|
||||||
|
|
||||||
On Debian/Ubuntu Linux, gflags can be installed using the following command:
|
|
||||||
|
|
||||||
sudo apt-get install libgflags-dev
|
|
||||||
|
|
||||||
On macOS, [Homebrew](https://brew.sh/) includes a formula for gflags:
|
|
||||||
|
|
||||||
brew install gflags
|
|
||||||
|
|
||||||
|
|
||||||
# Compiling the source code with Bazel
|
|
||||||
|
|
||||||
To use gflags in a [Bazel](http://bazel.io) project, map it in as an external
|
|
||||||
dependency by editing your WORKSPACE file:
|
|
||||||
|
|
||||||
git_repository(
|
|
||||||
name = "com_github_gflags_gflags",
|
|
||||||
commit = "<INSERT COMMIT SHA HERE>",
|
|
||||||
remote = "https://github.com/gflags/gflags.git",
|
|
||||||
)
|
|
||||||
|
|
||||||
You can then add `@com_github_gflags_gflags//:gflags` to the `deps` section of a
|
|
||||||
`cc_binary` or `cc_library` rule, and `#include <gflags/gflags.h>` to include it
|
|
||||||
in your source code.
|
|
||||||
|
|
||||||
|
|
||||||
# Compiling the source code with vcpkg
|
|
||||||
|
|
||||||
You can download and install gflags using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
|
||||||
|
|
||||||
git clone https://github.com/Microsoft/vcpkg.git
|
|
||||||
cd vcpkg
|
|
||||||
./bootstrap-vcpkg.sh
|
|
||||||
./vcpkg integrate install
|
|
||||||
vcpkg install gflags
|
|
||||||
|
|
||||||
The gflags port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
|
||||||
|
|
||||||
|
|
||||||
# Compiling the source code with CMake
|
|
||||||
|
|
||||||
The build system of gflags is since version 2.1 based on [CMake](http://cmake.org).
|
|
||||||
The common steps to build, test, and install software are therefore:
|
|
||||||
|
|
||||||
1. Extract source files.
|
|
||||||
2. Create build directory and change to it.
|
|
||||||
3. Run CMake to configure the build tree.
|
|
||||||
4. Build the software using selected build tool.
|
|
||||||
5. Test the built software.
|
|
||||||
6. Install the built files.
|
|
||||||
|
|
||||||
On Unix-like systems with GNU Make as build tool, these build steps can be
|
|
||||||
summarized by the following sequence of commands executed in a shell,
|
|
||||||
where ```$package``` and ```$version``` are shell variables which represent
|
|
||||||
the name of this package and the obtained version of the software.
|
|
||||||
|
|
||||||
$ tar xzf gflags-$version-source.tar.gz
|
|
||||||
$ cd gflags-$version
|
|
||||||
$ mkdir build && cd build
|
|
||||||
$ ccmake ..
|
|
||||||
|
|
||||||
- Press 'c' to configure the build system and 'e' to ignore warnings.
|
|
||||||
- Set CMAKE_INSTALL_PREFIX and other CMake variables and options.
|
|
||||||
- Continue pressing 'c' until the option 'g' is available.
|
|
||||||
- Then press 'g' to generate the configuration files for GNU Make.
|
|
||||||
|
|
||||||
$ make
|
|
||||||
$ make test (optional)
|
|
||||||
$ make install (optional)
|
|
||||||
|
|
||||||
In the following, only gflags-specific CMake settings available to
|
|
||||||
configure the build and installation are documented. Note that most of these
|
|
||||||
variables are for advanced users and binary package maintainers only.
|
|
||||||
They usually do not have to be modified.
|
|
||||||
|
|
||||||
|
|
||||||
CMake Option | Description
|
|
||||||
--------------------------- | -------------------------------------------------------
|
|
||||||
CMAKE_INSTALL_PREFIX | Installation directory, e.g., "/usr/local" on Unix and "C:\Program Files\gflags" on Windows.
|
|
||||||
BUILD_SHARED_LIBS | Request build of dynamic link libraries.
|
|
||||||
BUILD_STATIC_LIBS | Request build of static link libraries. Implied if BUILD_SHARED_LIBS is OFF.
|
|
||||||
BUILD_PACKAGING | Enable binary package generation using CPack.
|
|
||||||
BUILD_TESTING | Build tests for execution by CTest.
|
|
||||||
BUILD_NC_TESTS | Request inclusion of negative compilation tests (requires Python).
|
|
||||||
BUILD_CONFIG_TESTS | Request inclusion of package configuration tests (requires Python).
|
|
||||||
BUILD_gflags_LIBS | Request build of multi-threaded gflags libraries (if threading library found).
|
|
||||||
BUILD_gflags_nothreads_LIBS | Request build of single-threaded gflags libraries.
|
|
||||||
GFLAGS_NAMESPACE | Name of the C++ namespace to be used by the gflags library. Note that the public source header files are installed in a subdirectory named after this namespace. To maintain backwards compatibility with the Google Commandline Flags, set this variable to "google". The default is "gflags".
|
|
||||||
GFLAGS_INTTYPES_FORMAT | String identifying format of built-in integer types.
|
|
||||||
GFLAGS_INCLUDE_DIR | Name of headers installation directory relative to CMAKE_INSTALL_PREFIX.
|
|
||||||
LIBRARY_INSTALL_DIR | Name of library installation directory relative to CMAKE_INSTALL_PREFIX.
|
|
||||||
INSTALL_HEADERS | Request installation of public header files.
|
|
70
INSTALL.txt
Normal file
70
INSTALL.txt
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
INSTALLING A BINARY DISTRIBUTION PACKAGE
|
||||||
|
========================================
|
||||||
|
|
||||||
|
No official binary distribution packages are provided by the gflags developers.
|
||||||
|
There may, however, be binary packages available for your OS at
|
||||||
|
https://code.google.com/p/gflags/downloads/list. Please consult also the
|
||||||
|
package repositories of your Linux distribution.
|
||||||
|
|
||||||
|
For example on Debian/Ubuntu Linux, gflags can be installed using the
|
||||||
|
following command:
|
||||||
|
|
||||||
|
$ sudo apt-get install gflags
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BUILDING THE SOFTWARE FROM SOURCES
|
||||||
|
==================================
|
||||||
|
|
||||||
|
Build Steps
|
||||||
|
-----------
|
||||||
|
|
||||||
|
The build system of gflags is since version 2.1 based on CMake (cmake.org).
|
||||||
|
The common steps to build, test, and install software based on CMake are:
|
||||||
|
|
||||||
|
1. Extract source files.
|
||||||
|
2. Create build directory and change to it.
|
||||||
|
3. Run CMake to configure the build tree.
|
||||||
|
4. Build the software using selected build tool.
|
||||||
|
5. Test the built software.
|
||||||
|
6. Install the built files.
|
||||||
|
|
||||||
|
On Unix-like systems with GNU Make as build tool, these build steps can be
|
||||||
|
summarized by the following sequence of commands executed in a shell,
|
||||||
|
where $package and $version are shell variables which represent the name
|
||||||
|
of this package and the obtained version of the software.
|
||||||
|
|
||||||
|
$ tar xzf gflags-$version-source.tar.gz
|
||||||
|
$ cd gflags-$version
|
||||||
|
$ mkdir build && cd build
|
||||||
|
$ ccmake ..
|
||||||
|
|
||||||
|
- Press 'c' to configure the build system and 'e' to ignore warnings.
|
||||||
|
- Set CMAKE_INSTALL_PREFIX and other CMake variables and options.
|
||||||
|
- Continue pressing 'c' until the option 'g' is available.
|
||||||
|
- Then press 'g' to generate the configuration files for GNU Make.
|
||||||
|
|
||||||
|
$ make
|
||||||
|
$ make test (optional)
|
||||||
|
$ make install (optional)
|
||||||
|
|
||||||
|
In the following, only gflags-specific CMake settings available to
|
||||||
|
configure the build and installation are documented.
|
||||||
|
|
||||||
|
|
||||||
|
CMake Options
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- CMAKE_INSTALL_PREFIX Installation directory, e.g., "/usr/local" on Unix
|
||||||
|
and "C:\Program Files\gflags" on Windows.
|
||||||
|
|
||||||
|
|
||||||
|
Advanced CMake Options
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
- GFLAGS_NAMESPACE Name of the C++ namespace to be used by the gflags library.
|
||||||
|
Note that the public source header files are installed in
|
||||||
|
a subdirectory named after this namespace. To maintain
|
||||||
|
backwards compatibility with the Google Commandline Flags,
|
||||||
|
set this variable to "google". The default is "gflags".
|
|
@ -1,4 +0,0 @@
|
||||||
module(
|
|
||||||
name = "gflags",
|
|
||||||
compatibility_level = 1,
|
|
||||||
)
|
|
|
@ -1,101 +1,12 @@
|
||||||
[](https://github.com/gflags/gflags/actions/workflows/test.yml)
|
=== 20 March 2014 ===
|
||||||
|
|
||||||
The documentation of the gflags library is available online at https://gflags.github.io/gflags/.
|
I've just released gflags 2.1.0.
|
||||||
|
|
||||||
|
|
||||||
11 November 2018
|
|
||||||
----------------
|
|
||||||
|
|
||||||
I've just released gflags 2.2.2.
|
|
||||||
|
|
||||||
This maintenance release improves life of Bazel users (no more "config.h" leaking into global include paths),
|
|
||||||
fixes build with recent MinGW versions, and silences a number of static code analyzer and compiler warnings.
|
|
||||||
The build targets exported by the CMake configuration of this library are now also prefixed by the package
|
|
||||||
name "gflags::" following a more recent (unwritten) CMake convention. The unprefixed target names are still
|
|
||||||
supported to avoid that dependent projects have to be modified due to this change in imported target names.
|
|
||||||
|
|
||||||
Please report any further issues with this release using the GitHub issue tracker.
|
|
||||||
|
|
||||||
|
|
||||||
11 July 2017
|
|
||||||
------------
|
|
||||||
|
|
||||||
I've just released gflags 2.2.1.
|
|
||||||
|
|
||||||
This maintenance release primarily fixes build issues on Windows and
|
|
||||||
false alarms reported by static code analyzers.
|
|
||||||
|
|
||||||
Please report any further issues with this release using the GitHub issue tracker.
|
|
||||||
|
|
||||||
|
|
||||||
25 November 2016
|
|
||||||
----------------
|
|
||||||
|
|
||||||
I've finally released gflags 2.2.0.
|
|
||||||
|
|
||||||
This release adds support for use of the gflags library as external dependency
|
|
||||||
not only in projects using CMake, but also [Bazel](https://bazel.build/),
|
|
||||||
or [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/).
|
|
||||||
One new minor feature is added in this release: when a command flag argument
|
|
||||||
contains dashes, these are implicitly converted to underscores.
|
|
||||||
This is to allow those used to separate words of the flag name by dashes
|
|
||||||
to do so, while the flag variable names are required to use underscores.
|
|
||||||
|
|
||||||
Memory leaks reported by valgrind should be resolved by this release.
|
|
||||||
This release fixes build errors with MS Visual Studio 2015.
|
|
||||||
|
|
||||||
Please report any further issues with this release using the GitHub issue tracker.
|
|
||||||
|
|
||||||
|
|
||||||
24 March 2015
|
|
||||||
-------------
|
|
||||||
|
|
||||||
I've just released gflags 2.1.2.
|
|
||||||
|
|
||||||
This release completes the namespace change fixes. In particular,
|
|
||||||
it restores binary ABI compatibility with release version 2.0.
|
|
||||||
The deprecated "google" namespace is by default still kept as
|
|
||||||
primary namespace while symbols are imported into the new "gflags" namespace.
|
|
||||||
This can be overridden using the CMake variable GFLAGS_NAMESPACE.
|
|
||||||
|
|
||||||
Other fixes of the build configuration are related to the (patched)
|
|
||||||
CMake modules FindThreads.cmake and CheckTypeSize.cmake. These have
|
|
||||||
been removed and instead the C language is enabled again even though
|
|
||||||
gflags is written in C++ only.
|
|
||||||
|
|
||||||
This release also marks the complete move of the gflags project
|
|
||||||
from Google Code to GitHub. Email addresses of original issue
|
|
||||||
reporters got lost in the process. Given the age of most issue reports,
|
|
||||||
this should be negligible.
|
|
||||||
|
|
||||||
Please report any further issues using the GitHub issue tracker.
|
|
||||||
|
|
||||||
|
|
||||||
30 March 2014
|
|
||||||
-------------
|
|
||||||
|
|
||||||
I've just released gflags 2.1.1.
|
|
||||||
|
|
||||||
This release fixes a few bugs in the configuration of gflags\_declare.h
|
|
||||||
and adds a separate GFLAGS\_INCLUDE\_DIR CMake variable to the build configuration.
|
|
||||||
Setting GFLAGS\_NAMESPACE to "google" no longer changes also the include
|
|
||||||
path of the public header files. This allows the use of the library with
|
|
||||||
other Google projects such as glog which still use the deprecated "google"
|
|
||||||
namespace for the gflags library, but include it as "gflags/gflags.h".
|
|
||||||
|
|
||||||
20 March 2014
|
|
||||||
-------------
|
|
||||||
|
|
||||||
I've just released gflags 2.1.
|
|
||||||
|
|
||||||
The major changes are the use of CMake for the build configuration instead
|
The major changes are the use of CMake for the build configuration instead
|
||||||
of the autotools and packaging support through CPack. The default namespace
|
of the autotools and packaging support through CPack. This release compiles
|
||||||
of all C++ symbols is now "gflags" instead of "google". This can be
|
with all major compilers without warnings and passed the unit tests on
|
||||||
configured via the GFLAGS\_NAMESPACE variable.
|
Ubuntu 12.04, Windows 7 (Visual Studio 2008 and 2010, Cygwin, MinGW), and
|
||||||
|
Mac OS X (Xcode 5.1).
|
||||||
This release compiles with all major compilers without warnings and passed
|
|
||||||
the unit tests on Ubuntu 12.04, Windows 7 (Visual Studio 2008 and 2010,
|
|
||||||
Cygwin, MinGW), and Mac OS X (Xcode 5.1).
|
|
||||||
|
|
||||||
The SVN repository on Google Code is now frozen and replaced by a Git
|
The SVN repository on Google Code is now frozen and replaced by a Git
|
||||||
repository such that it can be used as Git submodule by projects. The main
|
repository such that it can be used as Git submodule by projects. The main
|
||||||
|
@ -103,36 +14,36 @@ hosting of this project remains at Google Code. Thanks to the distributed
|
||||||
character of Git, I can push (and pull) changes from both GitHub and Google Code
|
character of Git, I can push (and pull) changes from both GitHub and Google Code
|
||||||
in order to keep the two public repositories in sync.
|
in order to keep the two public repositories in sync.
|
||||||
When fixing an issue for a pull request through either of these hosting
|
When fixing an issue for a pull request through either of these hosting
|
||||||
platforms, please reference the issue number as
|
platforms, please reference the issue number as
|
||||||
[described here](https://code.google.com/p/support/wiki/IssueTracker#Integration_with_version_control).
|
[https://code.google.com/p/support/wiki/IssueTracker#Integration_with_version_control described here].
|
||||||
For the further development, I am following the
|
For the further development, I am following the
|
||||||
[Git branching model](http://nvie.com/posts/a-successful-git-branching-model/)
|
[http://nvie.com/posts/a-successful-git-branching-model/ Git branching model]
|
||||||
with feature branch names prefixed by "feature/" and bugfix branch names
|
with feature branch names prefixed by "feature/" and bugfix branch names
|
||||||
prefixed by "bugfix/", respectively.
|
prefixed by "bugfix/", respectively.
|
||||||
|
|
||||||
Binary and source [packages](https://github.com/schuhschuh/gflags/releases) are available on GitHub.
|
Binary and source distribution packages can be downloaded from
|
||||||
|
[https://github.com/schuhschuh/gflags GitHub] as Google Code no longer
|
||||||
|
permits the upload of such download packages.
|
||||||
|
|
||||||
|
|
||||||
14 January 2014
|
=== 14 January 2013 ===
|
||||||
---------------
|
|
||||||
|
|
||||||
The migration of the build system to CMake is almost complete.
|
The migration of the build system to CMake is almost complete.
|
||||||
What remains to be done is rewriting the tests in Python such they can be
|
What remains to be done is rewriting the tests in Python such they can be
|
||||||
executed on non-Unix platforms and splitting them up into separate CTest tests.
|
executed on non-Unix platforms and splitting them up into separate CTest tests.
|
||||||
Though merging these changes into the master branch yet remains to be done,
|
Though merging these changes into the master branch yet remains to be done,
|
||||||
it is recommended to already start using the
|
it is recommended to already start using the
|
||||||
[cmake-migration](https://github.com/schuhschuh/gflags/tree/cmake-migration) branch.
|
[https://github.com/schuhschuh/gflags/tree/cmake-migration cmake-migration] branch.
|
||||||
|
|
||||||
|
|
||||||
20 April 2013
|
=== 20 April 2013 ===
|
||||||
-------------
|
|
||||||
|
|
||||||
More than a year has past since I (Andreas) took over the maintenance for
|
More than a year has past since I (Andreas) took over the maintenance for
|
||||||
`gflags`. Only few minor changes have been made since then, much to my regret.
|
`gflags`. Only few minor changes have been made since then, much to my regret.
|
||||||
To get more involved and stimulate participation in the further
|
To get more involved and stimulate participation in the further
|
||||||
development of the library, I moved the project source code today to
|
development of the library, I moved the project source code today to
|
||||||
[GitHub](https://github.com/schuhschuh/gflags).
|
[https://github.com/schuhschuh/gflags GitHub].
|
||||||
I believe that the strengths of [Git](http://git-scm.com/) will allow for better community collaboration
|
I believe that the strengths of [http://git-scm.com/ Git] will allow for better community collaboration
|
||||||
as well as ease the integration of changes made by others. I encourage everyone
|
as well as ease the integration of changes made by others. I encourage everyone
|
||||||
who would like to contribute to send me pull requests.
|
who would like to contribute to send me pull requests.
|
||||||
Git's lightweight feature branches will also provide the right tool for more
|
Git's lightweight feature branches will also provide the right tool for more
|
||||||
|
@ -151,14 +62,13 @@ Please continue to report any issues with gflags on Google Code. The GitHub proj
|
||||||
only be used to host the Git repository.
|
only be used to host the Git repository.
|
||||||
|
|
||||||
One major change of the project structure I have in mind for the next weeks
|
One major change of the project structure I have in mind for the next weeks
|
||||||
is the migration from autotools to [CMake](http://www.cmake.org/).
|
is the migration from autotools to [http://www.cmake.org/ CMake].
|
||||||
Check out the (unstable!)
|
Check out the (unstable!)
|
||||||
[cmake-migration](https://github.com/schuhschuh/gflags/tree/cmake-migration)
|
[https://github.com/schuhschuh/gflags/tree/cmake-migration cmake-migration]
|
||||||
branch on GitHub for details.
|
branch on GitHub for details.
|
||||||
|
|
||||||
|
|
||||||
25 January 2012
|
=== 25 January 2012 ===
|
||||||
---------------
|
|
||||||
|
|
||||||
I've just released gflags 2.0.
|
I've just released gflags 2.0.
|
||||||
|
|
||||||
|
@ -169,7 +79,8 @@ around gflags and the ideas you have for the project going forward,
|
||||||
and look forward to having you on the team.
|
and look forward to having you on the team.
|
||||||
|
|
||||||
I bumped the major version number up to 2 to reflect the new community
|
I bumped the major version number up to 2 to reflect the new community
|
||||||
ownership of the project. All the [changes](ChangeLog.txt)
|
ownership of the project. All the
|
||||||
|
[http://gflags.googlecode.com/svn/tags/gflags-2.0/ChangeLog changes]
|
||||||
are related to the renaming. There are no functional changes from
|
are related to the renaming. There are no functional changes from
|
||||||
gflags 1.7. In particular, I've kept the code in the namespace
|
gflags 1.7. In particular, I've kept the code in the namespace
|
||||||
`google`, though in a future version it should be renamed to `gflags`.
|
`google`, though in a future version it should be renamed to `gflags`.
|
||||||
|
@ -178,8 +89,7 @@ synonym of `/usr/local/include/gflags/`, though the former name has
|
||||||
been obsolete for some time now.
|
been obsolete for some time now.
|
||||||
|
|
||||||
|
|
||||||
18 January 2011
|
=== 18 January 2011 ===
|
||||||
---------------
|
|
||||||
|
|
||||||
The `google-gflags` Google Code page has been renamed to
|
The `google-gflags` Google Code page has been renamed to
|
||||||
`gflags`, in preparation for the project being renamed to
|
`gflags`, in preparation for the project being renamed to
|
||||||
|
@ -189,16 +99,15 @@ relinquishing ownership of the project; it will now be entirely
|
||||||
community run. The name change reflects that shift.
|
community run. The name change reflects that shift.
|
||||||
|
|
||||||
|
|
||||||
20 December 2011
|
=== 20 December 2011 ===
|
||||||
----------------
|
|
||||||
|
|
||||||
I've just released gflags 1.7. This is a minor release; the major
|
I've just released gflags 1.7. This is a minor release; the major
|
||||||
change is that `CommandLineFlagInfo` now exports the address in memory
|
change is that `CommandLineFlagInfo` now exports the address in memory
|
||||||
where the flag is located. There has also been a bugfix involving
|
where the flag is located. There has also been a bugfix involving
|
||||||
very long --help strings, and some other minor [changes](ChangeLog.txt).
|
very long --help strings, and some other minor
|
||||||
|
[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.7/ChangeLog changes].
|
||||||
|
|
||||||
29 July 2011
|
=== 29 July 2011 ===
|
||||||
------------
|
|
||||||
|
|
||||||
I've just released gflags 1.6. The major new feature in this release
|
I've just released gflags 1.6. The major new feature in this release
|
||||||
is support for setting version info, so that --version does something
|
is support for setting version info, so that --version does something
|
||||||
|
@ -217,10 +126,11 @@ frequent updates with better change descriptions. They will also
|
||||||
result in future `ChangeLog` entries being much more verbose (for better
|
result in future `ChangeLog` entries being much more verbose (for better
|
||||||
or for worse).
|
or for worse).
|
||||||
|
|
||||||
See the [ChangeLog](ChangeLog.txt) for a full list of changes for this release.
|
See the
|
||||||
|
[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.6/ChangeLog ChangeLog]
|
||||||
|
for a full list of changes for this release.
|
||||||
|
|
||||||
24 January 2011
|
=== 24 January 2011 ===
|
||||||
---------------
|
|
||||||
|
|
||||||
I've just released gflags 1.5. This release has only minor changes
|
I've just released gflags 1.5. This release has only minor changes
|
||||||
from 1.4, including some slightly better reporting in --help, and
|
from 1.4, including some slightly better reporting in --help, and
|
||||||
|
@ -230,30 +140,28 @@ libraries under valgrind. The major change is to fix up the macros
|
||||||
|
|
||||||
If you have not had a problem with these macros, and don't need any of
|
If you have not had a problem with these macros, and don't need any of
|
||||||
the other changes described, there is no need to upgrade. See the
|
the other changes described, there is no need to upgrade. See the
|
||||||
[ChangeLog](ChangeLog.txt) for a full list of changes for this release.
|
[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.5/ChangeLog ChangeLog]
|
||||||
|
for a full list of changes for this release.
|
||||||
|
|
||||||
11 October 2010
|
=== 11 October 2010 ===
|
||||||
---------------
|
|
||||||
|
|
||||||
I've just released gflags 1.4. This release has only minor changes
|
I've just released gflags 1.4. This release has only minor changes
|
||||||
from 1.3, including some documentation tweaks and some work to make
|
from 1.3, including some documentation tweaks and some work to make
|
||||||
the library smaller. If 1.3 is working well for you, there's no
|
the library smaller. If 1.3 is working well for you, there's no
|
||||||
particular reason to upgrade.
|
particular reason to upgrade.
|
||||||
|
|
||||||
4 January 2010
|
=== 4 January 2010 ===
|
||||||
--------------
|
|
||||||
|
|
||||||
I've just released gflags 1.3. gflags now compiles under MSVC, and
|
I've just released gflags 1.3. gflags now compiles under MSVC, and
|
||||||
all tests pass. I **really** never thought non-unix-y Windows folks
|
all tests pass. I *really* never thought non-unix-y Windows folks
|
||||||
would want gflags, but at least some of them do.
|
would want gflags, but at least some of them do.
|
||||||
|
|
||||||
The major news, though, is that I've separated out the python package
|
The major news, though, is that I've separated out the python package
|
||||||
into its own library, [python-gflags](http://code.google.com/p/python-gflags).
|
into its own library, [http://code.google.com/p/python-gflags python-gflags].
|
||||||
If you're interested in the Python version of gflags, that's the place to
|
If you're interested in the Python version of gflags, that's the place to
|
||||||
get it now.
|
get it now.
|
||||||
|
|
||||||
10 September 2009
|
=== 10 September 2009 ==
|
||||||
-----------------
|
|
||||||
|
|
||||||
I've just released gflags 1.2. The major change from gflags 1.1 is it
|
I've just released gflags 1.2. The major change from gflags 1.1 is it
|
||||||
now compiles under MinGW (as well as cygwin), and all tests pass. I
|
now compiles under MinGW (as well as cygwin), and all tests pass. I
|
||||||
|
@ -264,13 +172,14 @@ wrong!
|
||||||
The other changes are minor, such as support for --htmlxml in the
|
The other changes are minor, such as support for --htmlxml in the
|
||||||
python version of gflags.
|
python version of gflags.
|
||||||
|
|
||||||
15 April 2009
|
=== 15 April 2009 ===
|
||||||
-------------
|
|
||||||
|
|
||||||
I've just released gflags 1.1. It has only minor changes fdrom gflags
|
I've just released gflags 1.1. It has only minor changes fdrom gflags
|
||||||
1.0 (see the [ChangeLog](ChangeLog.txt) for details).
|
1.0 (see the
|
||||||
The major change is that I moved to a new system for creating .deb and .rpm files.
|
[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.1/ChangeLog ChangeLog]
|
||||||
This allows me to create x86\_64 deb and rpm files.
|
for details). The major change is that I moved to a new
|
||||||
|
system for creating .deb and .rpm files. This allows me to create
|
||||||
|
x86_64 deb and rpm files.
|
||||||
|
|
||||||
In the process of moving to this new system, I noticed an
|
In the process of moving to this new system, I noticed an
|
||||||
inconsistency: the tar.gz and .rpm files created libraries named
|
inconsistency: the tar.gz and .rpm files created libraries named
|
||||||
|
@ -278,7 +187,7 @@ libgflags.so, but the deb file created libgoogle-gflags.so. I have
|
||||||
fixed the deb file to create libraries like the others. I'm no expert
|
fixed the deb file to create libraries like the others. I'm no expert
|
||||||
in debian packaging, but I believe this has caused the package name to
|
in debian packaging, but I believe this has caused the package name to
|
||||||
change as well. Please let me know (at
|
change as well. Please let me know (at
|
||||||
[[mailto:google-gflags@googlegroups.com](mailto:google-gflags@googlegroups.com)
|
[mailto:google-gflags@googlegroups.com
|
||||||
google-gflags@googlegroups.com]) if this causes problems for you --
|
google-gflags@googlegroups.com]) if this causes problems for you --
|
||||||
especially if you know of a fix! I would be happy to change the deb
|
especially if you know of a fix! I would be happy to change the deb
|
||||||
packages to add symlinks from the old library name to the new
|
packages to add symlinks from the old library name to the new
|
||||||
|
@ -289,21 +198,20 @@ If you've tried to install a .rpm or .deb and it doesn't work for you,
|
||||||
let me know. I'm excited to finally have 64-bit package files, but
|
let me know. I'm excited to finally have 64-bit package files, but
|
||||||
there may still be some wrinkles in the new system to iron out.
|
there may still be some wrinkles in the new system to iron out.
|
||||||
|
|
||||||
1 October 2008
|
=== 1 October 2008 ===
|
||||||
--------------
|
|
||||||
|
|
||||||
gflags 1.0rc2 was out for a few weeks without any issues, so gflags
|
gflags 1.0rc2 was out for a few weeks without any issues, so gflags
|
||||||
1.0 is now released. This is much like gflags 0.9. The major change
|
1.0 is now released. This is much like gflags 0.9. The major change
|
||||||
is that the .h files have been moved from `/usr/include/google` to
|
is that the .h files have been moved from `/usr/include/google` to
|
||||||
`/usr/include/gflags`. While I have backwards-compatibility
|
`/usr/include/gflags`. While I have backwards-compatibility
|
||||||
forwarding headeds in place, please rewrite existing code to say
|
forwarding headeds in place, please rewrite existing code to say
|
||||||
```
|
{{{
|
||||||
#include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
```
|
}}}
|
||||||
instead of
|
instead of
|
||||||
```
|
{{{
|
||||||
#include <google/gflags.h>
|
#include <google/gflags.h>
|
||||||
```
|
}}}
|
||||||
|
|
||||||
I've kept the default namespace to google. You can still change with
|
I've kept the default namespace to google. You can still change with
|
||||||
with the appropriate flag to the configure script (`./configure
|
with the appropriate flag to the configure script (`./configure
|
||||||
|
@ -313,7 +221,8 @@ non-backwards-compatible change, send mail to
|
||||||
`google-gflags@googlegroups.com`!
|
`google-gflags@googlegroups.com`!
|
||||||
|
|
||||||
Version 1.0 also has some neat new features, like support for bash
|
Version 1.0 also has some neat new features, like support for bash
|
||||||
commandline-completion of help flags. See the [ChangeLog](ChangeLog.txt)
|
commandline-completion of help flags. See the
|
||||||
for more details.
|
[http://code.google.com/p/google-gflags/source/browse/tags/gflags-1.0rc2/ChangeLog
|
||||||
|
ChangeLog] for more details.
|
||||||
|
|
||||||
If I don't hear any bad news for a few weeks, I'll release 1.0-final.
|
If I don't hear any bad news for a few weeks, I'll release 1.0-final.
|
6
README.txt
Normal file
6
README.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
This package contains a library that implements commandline flags
|
||||||
|
processing. As such it's a replacement for getopt(). It has increased
|
||||||
|
flexibility, including built-in support for C++ types like string, and
|
||||||
|
the ability to define flags in the source file in which they're used.
|
||||||
|
The devel package contains static and debug libraries and header files
|
||||||
|
for developing applications that use the gflags package.
|
|
@ -1,6 +0,0 @@
|
||||||
# Copyright 2006 Google Inc. All Rights Reserved.
|
|
||||||
# Use of this source code is governed by a BSD-style
|
|
||||||
# license that can be found in the COPYING.txt file.
|
|
||||||
|
|
||||||
# Bazel (http://bazel.io/) WORKSPACE file for gflags.
|
|
||||||
workspace(name="com_github_gflags_gflags")
|
|
|
@ -1,5 +0,0 @@
|
||||||
cc_binary(
|
|
||||||
name = "expand_template",
|
|
||||||
srcs = ["expand_template.cc"],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
|
@ -1,63 +0,0 @@
|
||||||
#include <fstream>
|
|
||||||
#include <regex>
|
|
||||||
#include <streambuf>
|
|
||||||
#include <string>
|
|
||||||
#include <string.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
struct Substitution {
|
|
||||||
std::basic_regex<char> regex;
|
|
||||||
std::string replacement;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Simple app that does a regex search-and-replace on a template
|
|
||||||
// and outputs the result.
|
|
||||||
//
|
|
||||||
// To invoke:
|
|
||||||
// expand_template
|
|
||||||
// --template PATH
|
|
||||||
// --output PATH
|
|
||||||
// regex0;replacement0
|
|
||||||
// regex1;replacement1
|
|
||||||
// ...
|
|
||||||
//
|
|
||||||
// Since it's only used as a private implementation detail of a rule and not
|
|
||||||
// user invoked we don't bother with error checking.
|
|
||||||
int main(int argc, const char** argv) {
|
|
||||||
// Parse args.
|
|
||||||
const char* template_path = nullptr;
|
|
||||||
const char* output_path = nullptr;
|
|
||||||
std::vector<Substitution> substitutions;
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
|
||||||
const char* arg = argv[i];
|
|
||||||
if (strcmp(arg, "--template") == 0) {
|
|
||||||
template_path = argv[++i];
|
|
||||||
} else if (strcmp(arg, "--output") == 0) {
|
|
||||||
output_path = argv[++i];
|
|
||||||
} else {
|
|
||||||
const char* mid = strchr(arg, ';');
|
|
||||||
if (mid != nullptr) {
|
|
||||||
substitutions.push_back(Substitution{
|
|
||||||
std::basic_regex<char>(arg, mid - arg),
|
|
||||||
std::string(mid + 1),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read template.
|
|
||||||
std::ifstream ifs(template_path);
|
|
||||||
std::string str(std::istreambuf_iterator<char>(ifs),
|
|
||||||
(std::istreambuf_iterator<char>()));
|
|
||||||
|
|
||||||
// Apply regexes.
|
|
||||||
for (const auto& subst : substitutions) {
|
|
||||||
str = std::regex_replace(str, subst.regex, subst.replacement);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output file.
|
|
||||||
std::ofstream file(output_path);
|
|
||||||
file << str;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
def _impl(ctx):
|
|
||||||
args = ctx.actions.args()
|
|
||||||
args.add("--template", ctx.file.template)
|
|
||||||
args.add("--output", ctx.outputs.out)
|
|
||||||
args.add_all([k + ';' + v for k, v in ctx.attr.substitutions.items()])
|
|
||||||
ctx.actions.run(
|
|
||||||
executable = ctx.executable._bin,
|
|
||||||
arguments = [args],
|
|
||||||
inputs = [ctx.file.template],
|
|
||||||
outputs = [ctx.outputs.out],
|
|
||||||
)
|
|
||||||
return [
|
|
||||||
DefaultInfo(
|
|
||||||
files = depset(direct = [ctx.outputs.out]),
|
|
||||||
runfiles = ctx.runfiles(files = [ctx.outputs.out]),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
expanded_template = rule(
|
|
||||||
implementation = _impl,
|
|
||||||
attrs = {
|
|
||||||
"out": attr.output(mandatory = True),
|
|
||||||
"template": attr.label(
|
|
||||||
allow_single_file = True,
|
|
||||||
mandatory = True,
|
|
||||||
),
|
|
||||||
"substitutions": attr.string_dict(),
|
|
||||||
"_bin": attr.label(
|
|
||||||
default = "//bazel/expanded_template:expand_template",
|
|
||||||
executable = True,
|
|
||||||
allow_single_file = True,
|
|
||||||
cfg = "host",
|
|
||||||
),
|
|
||||||
},
|
|
||||||
)
|
|
108
bazel/gflags.bzl
108
bazel/gflags.bzl
|
@ -1,108 +0,0 @@
|
||||||
load("//bazel/expanded_template:expanded_template.bzl", "expanded_template")
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Add native rules to configure source files
|
|
||||||
def gflags_sources(namespace = ["google", "gflags"]):
|
|
||||||
expanded_template(
|
|
||||||
name = "gflags_declare_h",
|
|
||||||
template = "src/gflags_declare.h.in",
|
|
||||||
out = "gflags_declare.h",
|
|
||||||
substitutions = {
|
|
||||||
"@GFLAGS_NAMESPACE@": namespace[0],
|
|
||||||
"@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@": "1",
|
|
||||||
"@([A-Z0-9_]+)@": "0",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
gflags_ns_h_files = []
|
|
||||||
for ns in namespace[1:]:
|
|
||||||
gflags_ns_h_file = "gflags_{}.h".format(ns)
|
|
||||||
expanded_template(
|
|
||||||
name = gflags_ns_h_file.replace(".", "_"),
|
|
||||||
template = "src/gflags_ns.h.in",
|
|
||||||
out = gflags_ns_h_file,
|
|
||||||
substitutions = {
|
|
||||||
"@ns@": ns,
|
|
||||||
"@NS@": ns.upper(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
gflags_ns_h_files.append(gflags_ns_h_file)
|
|
||||||
expanded_template(
|
|
||||||
name = "gflags_h",
|
|
||||||
template = "src/gflags.h.in",
|
|
||||||
out = "gflags.h",
|
|
||||||
substitutions = {
|
|
||||||
"@GFLAGS_ATTRIBUTE_UNUSED@": "",
|
|
||||||
"@INCLUDE_GFLAGS_NS_H@": "\n".join(["#include \"gflags/{}\"".format(hdr) for hdr in gflags_ns_h_files]),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
expanded_template(
|
|
||||||
name = "gflags_completions_h",
|
|
||||||
template = "src/gflags_completions.h.in",
|
|
||||||
out = "gflags_completions.h",
|
|
||||||
substitutions = {
|
|
||||||
"@GFLAGS_NAMESPACE@": namespace[0],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
hdrs = [":gflags_h", ":gflags_declare_h", ":gflags_completions_h"]
|
|
||||||
hdrs.extend([":" + hdr.replace(".", "_") for hdr in gflags_ns_h_files])
|
|
||||||
srcs = [
|
|
||||||
"src/config.h",
|
|
||||||
"src/gflags.cc",
|
|
||||||
"src/gflags_completions.cc",
|
|
||||||
"src/gflags_reporting.cc",
|
|
||||||
"src/mutex.h",
|
|
||||||
"src/util.h",
|
|
||||||
] + select({
|
|
||||||
"//:x64_windows": [
|
|
||||||
"src/windows_port.cc",
|
|
||||||
"src/windows_port.h",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
})
|
|
||||||
return [hdrs, srcs]
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Add native rule to build gflags library
|
|
||||||
def gflags_library(hdrs = [], srcs = [], threads = 1):
|
|
||||||
name = "gflags"
|
|
||||||
copts = [
|
|
||||||
"-DGFLAGS_BAZEL_BUILD",
|
|
||||||
"-DGFLAGS_INTTYPES_FORMAT_C99",
|
|
||||||
"-DGFLAGS_IS_A_DLL=0",
|
|
||||||
# macros otherwise defined by CMake configured defines.h file
|
|
||||||
"-DHAVE_STDINT_H",
|
|
||||||
"-DHAVE_SYS_TYPES_H",
|
|
||||||
"-DHAVE_INTTYPES_H",
|
|
||||||
"-DHAVE_SYS_STAT_H",
|
|
||||||
"-DHAVE_STRTOLL",
|
|
||||||
"-DHAVE_STRTOQ",
|
|
||||||
"-DHAVE_RWLOCK",
|
|
||||||
] + select({
|
|
||||||
"//:x64_windows": [
|
|
||||||
"-DOS_WINDOWS",
|
|
||||||
],
|
|
||||||
"//conditions:default": [
|
|
||||||
"-DHAVE_UNISTD_H",
|
|
||||||
"-DHAVE_FNMATCH_H",
|
|
||||||
"-DHAVE_PTHREAD",
|
|
||||||
],
|
|
||||||
})
|
|
||||||
linkopts = []
|
|
||||||
if threads:
|
|
||||||
linkopts += select({
|
|
||||||
"//:android": [],
|
|
||||||
"//:x64_windows": [],
|
|
||||||
"//conditions:default": ["-lpthread"],
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
name += "_nothreads"
|
|
||||||
copts += ["-DNO_THREADS"]
|
|
||||||
native.cc_library(
|
|
||||||
name = name,
|
|
||||||
hdrs = hdrs,
|
|
||||||
srcs = srcs,
|
|
||||||
copts = copts,
|
|
||||||
linkopts = linkopts,
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
include_prefix = "gflags",
|
|
||||||
)
|
|
300
cmake/CMakeCXXInformation.cmake
Normal file
300
cmake/CMakeCXXInformation.cmake
Normal file
|
@ -0,0 +1,300 @@
|
||||||
|
# Copied from master branch of CMake (commit SHA 34a49dea) before release of
|
||||||
|
# this newer version which seems to fix a bug of the one coming with CMake 2.8-12.
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2004-2011 Kitware, Inc.
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
# This file sets the basic flags for the C++ language in CMake.
|
||||||
|
# It also loads the available platform file for the system-compiler
|
||||||
|
# if it exists.
|
||||||
|
# It also loads a system - compiler - processor (or target hardware)
|
||||||
|
# specific file, which is mainly useful for crosscompiling and embedded systems.
|
||||||
|
|
||||||
|
# some compilers use different extensions (e.g. sdcc uses .rel)
|
||||||
|
# so set the extension here first so it can be overridden by the compiler specific file
|
||||||
|
if(UNIX)
|
||||||
|
set(CMAKE_CXX_OUTPUT_EXTENSION .o)
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_OUTPUT_EXTENSION .obj)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(_INCLUDED_FILE 0)
|
||||||
|
|
||||||
|
# Load compiler-specific information.
|
||||||
|
if(CMAKE_CXX_COMPILER_ID)
|
||||||
|
include(Compiler/${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_BASE_NAME)
|
||||||
|
get_filename_component(CMAKE_BASE_NAME "${CMAKE_CXX_COMPILER}" NAME_WE)
|
||||||
|
# since the gnu compiler has several names force g++
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
set(CMAKE_BASE_NAME g++)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# load a hardware specific file, mostly useful for embedded compilers
|
||||||
|
if(CMAKE_SYSTEM_PROCESSOR)
|
||||||
|
if(CMAKE_CXX_COMPILER_ID)
|
||||||
|
include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
|
||||||
|
endif()
|
||||||
|
if (NOT _INCLUDED_FILE)
|
||||||
|
include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
|
||||||
|
endif ()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# load the system- and compiler specific files
|
||||||
|
if(CMAKE_CXX_COMPILER_ID)
|
||||||
|
include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
|
||||||
|
endif()
|
||||||
|
if (NOT _INCLUDED_FILE)
|
||||||
|
include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
|
||||||
|
RESULT_VARIABLE _INCLUDED_FILE)
|
||||||
|
endif ()
|
||||||
|
# We specify the compiler information in the system file for some
|
||||||
|
# platforms, but this language may not have been enabled when the file
|
||||||
|
# was first included. Include it again to get the language info.
|
||||||
|
# Remove this when all compiler info is removed from system files.
|
||||||
|
if (NOT _INCLUDED_FILE)
|
||||||
|
include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_SIZEOF_DATA_PTR)
|
||||||
|
foreach(f ${CMAKE_CXX_ABI_FILES})
|
||||||
|
include(${f})
|
||||||
|
endforeach()
|
||||||
|
unset(CMAKE_CXX_ABI_FILES)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# This should be included before the _INIT variables are
|
||||||
|
# used to initialize the cache. Since the rule variables
|
||||||
|
# have if blocks on them, users can still define them here.
|
||||||
|
# But, it should still be after the platform file so changes can
|
||||||
|
# be made to those values.
|
||||||
|
|
||||||
|
if(CMAKE_USER_MAKE_RULES_OVERRIDE)
|
||||||
|
# Save the full path of the file so try_compile can use it.
|
||||||
|
include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
|
||||||
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
|
||||||
|
# Save the full path of the file so try_compile can use it.
|
||||||
|
include(${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} RESULT_VARIABLE _override)
|
||||||
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX "${_override}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# Create a set of shared library variable specific to C++
|
||||||
|
# For 90% of the systems, these are the same flags as the C versions
|
||||||
|
# so if these are not set just copy the flags from the c version
|
||||||
|
if(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC)
|
||||||
|
set(CMAKE_CXX_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
||||||
|
set(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_CXX_COMPILE_OPTIONS_DLL)
|
||||||
|
set(CMAKE_CXX_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT DEFINED CMAKE_EXE_EXPORTS_CXX_FLAG)
|
||||||
|
set(CMAKE_EXE_EXPORTS_CXX_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG)
|
||||||
|
set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP)
|
||||||
|
set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG)
|
||||||
|
set(CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_INCLUDE_FLAG_CXX)
|
||||||
|
set(CMAKE_INCLUDE_FLAG_CXX ${CMAKE_INCLUDE_FLAG_C})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
|
||||||
|
set(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# for most systems a module is the same as a shared library
|
||||||
|
# so unless the variable CMAKE_MODULE_EXISTS is set just
|
||||||
|
# copy the values from the LIBRARY variables
|
||||||
|
if(NOT CMAKE_MODULE_EXISTS)
|
||||||
|
set(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
|
||||||
|
set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# repeat for modules
|
||||||
|
if(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
|
||||||
|
set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
|
||||||
|
set(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Initialize CXX link type selection flags from C versions.
|
||||||
|
foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
|
||||||
|
if(NOT CMAKE_${type}_LINK_STATIC_CXX_FLAGS)
|
||||||
|
set(CMAKE_${type}_LINK_STATIC_CXX_FLAGS
|
||||||
|
${CMAKE_${type}_LINK_STATIC_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
if(NOT CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS)
|
||||||
|
set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS
|
||||||
|
${CMAKE_${type}_LINK_DYNAMIC_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# add the flags to the cache based
|
||||||
|
# on the initial values computed in the platform/*.cmake files
|
||||||
|
# use _INIT variables so that this only happens the first time
|
||||||
|
# and you can set these flags in the cmake cache
|
||||||
|
set(CMAKE_CXX_FLAGS_INIT "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}")
|
||||||
|
# avoid just having a space as the initial value for the cache
|
||||||
|
if(CMAKE_CXX_FLAGS_INIT STREQUAL " ")
|
||||||
|
set(CMAKE_CXX_FLAGS_INIT)
|
||||||
|
endif()
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT}" CACHE STRING
|
||||||
|
"Flags used by the compiler during all build types.")
|
||||||
|
|
||||||
|
if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
|
||||||
|
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING
|
||||||
|
"Flags used by the compiler during debug builds.")
|
||||||
|
set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}" CACHE STRING
|
||||||
|
"Flags used by the compiler during release builds for minimum size.")
|
||||||
|
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING
|
||||||
|
"Flags used by the compiler during release builds.")
|
||||||
|
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
|
||||||
|
"Flags used by the compiler during release builds with debug info.")
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
|
||||||
|
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}"
|
||||||
|
CACHE STRING "Libraries linked by default with all C++ applications.")
|
||||||
|
mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CMakeCommonLanguageInclude)
|
||||||
|
|
||||||
|
# now define the following rules:
|
||||||
|
# CMAKE_CXX_CREATE_SHARED_LIBRARY
|
||||||
|
# CMAKE_CXX_CREATE_SHARED_MODULE
|
||||||
|
# CMAKE_CXX_COMPILE_OBJECT
|
||||||
|
# CMAKE_CXX_LINK_EXECUTABLE
|
||||||
|
|
||||||
|
# variables supplied by the generator at use time
|
||||||
|
# <TARGET>
|
||||||
|
# <TARGET_BASE> the target without the suffix
|
||||||
|
# <OBJECTS>
|
||||||
|
# <OBJECT>
|
||||||
|
# <LINK_LIBRARIES>
|
||||||
|
# <FLAGS>
|
||||||
|
# <LINK_FLAGS>
|
||||||
|
|
||||||
|
# CXX compiler information
|
||||||
|
# <CMAKE_CXX_COMPILER>
|
||||||
|
# <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
|
||||||
|
# <CMAKE_CXX_SHARED_MODULE_CREATE_FLAGS>
|
||||||
|
# <CMAKE_CXX_LINK_FLAGS>
|
||||||
|
|
||||||
|
# Static library tools
|
||||||
|
# <CMAKE_AR>
|
||||||
|
# <CMAKE_RANLIB>
|
||||||
|
|
||||||
|
|
||||||
|
# create a shared C++ library
|
||||||
|
if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
|
||||||
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
|
||||||
|
"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# create a c++ shared module copy the shared library rule by default
|
||||||
|
if(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
|
||||||
|
set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# Create a static archive incrementally for large object file counts.
|
||||||
|
# If CMAKE_CXX_CREATE_STATIC_LIBRARY is set it will override these.
|
||||||
|
if(NOT DEFINED CMAKE_CXX_ARCHIVE_CREATE)
|
||||||
|
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED CMAKE_CXX_ARCHIVE_APPEND)
|
||||||
|
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED CMAKE_CXX_ARCHIVE_FINISH)
|
||||||
|
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# compile a C++ file into an object file
|
||||||
|
if(NOT CMAKE_CXX_COMPILE_OBJECT)
|
||||||
|
set(CMAKE_CXX_COMPILE_OBJECT
|
||||||
|
"<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_CXX_LINK_EXECUTABLE)
|
||||||
|
set(CMAKE_CXX_LINK_EXECUTABLE
|
||||||
|
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
mark_as_advanced(
|
||||||
|
CMAKE_VERBOSE_MAKEFILE
|
||||||
|
CMAKE_CXX_FLAGS
|
||||||
|
CMAKE_CXX_FLAGS_RELEASE
|
||||||
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||||
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
||||||
|
CMAKE_CXX_FLAGS_DEBUG)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_INFORMATION_LOADED 1)
|
||||||
|
|
80
cmake/CheckCXXLibraryExists.cmake
Normal file
80
cmake/CheckCXXLibraryExists.cmake
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
#.rst:
|
||||||
|
# CheckLibraryExists
|
||||||
|
# ------------------
|
||||||
|
#
|
||||||
|
# Check if the function exists.
|
||||||
|
#
|
||||||
|
# CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# LIBRARY - the name of the library you are looking for
|
||||||
|
# FUNCTION - the name of the function
|
||||||
|
# LOCATION - location where the library should be found
|
||||||
|
# VARIABLE - variable to store the result
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# The following variables may be set before calling this macro to modify
|
||||||
|
# the way the check is run:
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
||||||
|
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
||||||
|
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2002-2009 Kitware, Inc.
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
macro(CHECK_CXX_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
|
||||||
|
if("${VARIABLE}" MATCHES "^${VARIABLE}$")
|
||||||
|
set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
|
||||||
|
"-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
|
||||||
|
message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
|
||||||
|
set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
|
||||||
|
if(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
set(CHECK_LIBRARY_EXISTS_LIBRARIES
|
||||||
|
${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c
|
||||||
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx COPYONLY)
|
||||||
|
try_compile(${VARIABLE}
|
||||||
|
${CMAKE_BINARY_DIR}
|
||||||
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx
|
||||||
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||||
|
LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
|
||||||
|
CMAKE_FLAGS
|
||||||
|
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
|
||||||
|
-DLINK_DIRECTORIES:STRING=${LOCATION}
|
||||||
|
OUTPUT_VARIABLE OUTPUT)
|
||||||
|
|
||||||
|
if(${VARIABLE})
|
||||||
|
message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
|
||||||
|
set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
|
||||||
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||||
|
"Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
|
||||||
|
"passed with the following output:\n"
|
||||||
|
"${OUTPUT}\n\n")
|
||||||
|
else()
|
||||||
|
message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
|
||||||
|
set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
|
||||||
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||||
|
"Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
|
||||||
|
"failed with the following output:\n"
|
||||||
|
"${OUTPUT}\n\n")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endmacro()
|
38
cmake/CheckForPthreads.cxx
Normal file
38
cmake/CheckForPthreads.cxx
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void* runner(void*);
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
#ifdef __CLASSIC_C__
|
||||||
|
int main(){
|
||||||
|
int ac;
|
||||||
|
char*av[];
|
||||||
|
#else
|
||||||
|
int main(int ac, char*av[]){
|
||||||
|
#endif
|
||||||
|
pthread_t tid[2];
|
||||||
|
pthread_create(&tid[0], 0, runner, (void*)1);
|
||||||
|
pthread_create(&tid[1], 0, runner, (void*)2);
|
||||||
|
|
||||||
|
#if defined(__BEOS__) && !defined(__ZETA__) // (no usleep on BeOS 5.)
|
||||||
|
usleep(1); // for strange behavior on single-processor sun
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pthread_join(tid[0], 0);
|
||||||
|
pthread_join(tid[1], 0);
|
||||||
|
if(ac > 1000){return *av[0];}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* runner(void* args)
|
||||||
|
{
|
||||||
|
int cc;
|
||||||
|
for ( cc = 0; cc < 10; cc ++ )
|
||||||
|
{
|
||||||
|
printf("%p CC: %d\n", args, cc);
|
||||||
|
}
|
||||||
|
res ++;
|
||||||
|
return 0;
|
||||||
|
}
|
37
cmake/CheckTypeSize.c.in
Normal file
37
cmake/CheckTypeSize.c.in
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
@headers@
|
||||||
|
|
||||||
|
#undef KEY
|
||||||
|
#if defined(__i386)
|
||||||
|
# define KEY '_','_','i','3','8','6'
|
||||||
|
#elif defined(__x86_64)
|
||||||
|
# define KEY '_','_','x','8','6','_','6','4'
|
||||||
|
#elif defined(__ppc__)
|
||||||
|
# define KEY '_','_','p','p','c','_','_'
|
||||||
|
#elif defined(__ppc64__)
|
||||||
|
# define KEY '_','_','p','p','c','6','4','_','_'
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SIZE (sizeof(@type@))
|
||||||
|
char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
|
||||||
|
('0' + ((SIZE / 10000)%10)),
|
||||||
|
('0' + ((SIZE / 1000)%10)),
|
||||||
|
('0' + ((SIZE / 100)%10)),
|
||||||
|
('0' + ((SIZE / 10)%10)),
|
||||||
|
('0' + (SIZE % 10)),
|
||||||
|
']',
|
||||||
|
#ifdef KEY
|
||||||
|
' ','k','e','y','[', KEY, ']',
|
||||||
|
#endif
|
||||||
|
'\0'};
|
||||||
|
|
||||||
|
#ifdef __CLASSIC_C__
|
||||||
|
int main(argc, argv) int argc; char *argv[];
|
||||||
|
#else
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int require = 0;
|
||||||
|
require += info_size[argc];
|
||||||
|
(void)argv;
|
||||||
|
return require;
|
||||||
|
}
|
268
cmake/CheckTypeSize.cmake
Normal file
268
cmake/CheckTypeSize.cmake
Normal file
|
@ -0,0 +1,268 @@
|
||||||
|
# Copied from master branch of CMake (commit SHA 34a49dea) and
|
||||||
|
# modified to use CheckIncludeFileCXX instead of CheckIncludeFile
|
||||||
|
# when the LANGUAGE is CXX. Modified the try_compile call to
|
||||||
|
# not pass any LINK_LIBRARIES as this option is only supported by
|
||||||
|
# CMake since version 2.8.11
|
||||||
|
# -andreas
|
||||||
|
|
||||||
|
#.rst:
|
||||||
|
# CheckTypeSize
|
||||||
|
# -------------
|
||||||
|
#
|
||||||
|
# Check sizeof a type
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY]
|
||||||
|
# [LANGUAGE <language>])
|
||||||
|
#
|
||||||
|
# Check if the type exists and determine its size. On return,
|
||||||
|
# "HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}"
|
||||||
|
# holds one of the following:
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# <size> = type has non-zero size <size>
|
||||||
|
# "0" = type has arch-dependent size (see below)
|
||||||
|
# "" = type does not exist
|
||||||
|
#
|
||||||
|
# Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code
|
||||||
|
# to define the macro "${VARIABLE}" to the size of the type, or leave
|
||||||
|
# the macro undefined if the type does not exist.
|
||||||
|
#
|
||||||
|
# The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has
|
||||||
|
# multiple architectures for building OS X universal binaries. This
|
||||||
|
# indicates that the type size varies across architectures. In this
|
||||||
|
# case "${VARIABLE}_CODE" contains C preprocessor tests mapping from
|
||||||
|
# each architecture macro to the corresponding type size. The list of
|
||||||
|
# architecture macros is stored in "${VARIABLE}_KEYS", and the value for
|
||||||
|
# each key is stored in "${VARIABLE}-${KEY}".
|
||||||
|
#
|
||||||
|
# If the BUILTIN_TYPES_ONLY option is not given, the macro checks for
|
||||||
|
# headers <sys/types.h>, <stdint.h>, and <stddef.h>, and saves results
|
||||||
|
# in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size
|
||||||
|
# check automatically includes the available headers, thus supporting
|
||||||
|
# checks of types defined in the headers.
|
||||||
|
#
|
||||||
|
# If LANGUAGE is set, the specified compiler will be used to perform the
|
||||||
|
# check. Acceptable values are C and CXX
|
||||||
|
#
|
||||||
|
# Despite the name of the macro you may use it to check the size of more
|
||||||
|
# complex expressions, too. To check e.g. for the size of a struct
|
||||||
|
# member you can do something like this:
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# check_type_size("((struct something*)0)->member" SIZEOF_MEMBER)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# The following variables may be set before calling this macro to modify
|
||||||
|
# the way the check is run:
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
||||||
|
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
||||||
|
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
||||||
|
# CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2002-2009 Kitware, Inc.
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
include(CheckIncludeFile)
|
||||||
|
include(CheckIncludeFileCXX)
|
||||||
|
|
||||||
|
cmake_policy(PUSH)
|
||||||
|
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
||||||
|
|
||||||
|
get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Helper function. DO NOT CALL DIRECTLY.
|
||||||
|
function(__check_type_size_impl type var map builtin language)
|
||||||
|
message(STATUS "Check size of ${type}")
|
||||||
|
|
||||||
|
# Include header files.
|
||||||
|
set(headers)
|
||||||
|
if(builtin)
|
||||||
|
if(HAVE_SYS_TYPES_H)
|
||||||
|
set(headers "${headers}#include <sys/types.h>\n")
|
||||||
|
endif()
|
||||||
|
if(HAVE_STDINT_H)
|
||||||
|
set(headers "${headers}#include <stdint.h>\n")
|
||||||
|
endif()
|
||||||
|
if(HAVE_STDDEF_H)
|
||||||
|
set(headers "${headers}#include <stddef.h>\n")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
foreach(h ${CMAKE_EXTRA_INCLUDE_FILES})
|
||||||
|
set(headers "${headers}#include \"${h}\"\n")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Perform the check.
|
||||||
|
|
||||||
|
if("${language}" STREQUAL "C")
|
||||||
|
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c)
|
||||||
|
elseif("${language}" STREQUAL "CXX")
|
||||||
|
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n")
|
||||||
|
endif()
|
||||||
|
set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin)
|
||||||
|
configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY)
|
||||||
|
try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src}
|
||||||
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||||
|
CMAKE_FLAGS
|
||||||
|
"-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
|
||||||
|
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
|
||||||
|
OUTPUT_VARIABLE output
|
||||||
|
COPY_FILE ${bin}
|
||||||
|
)
|
||||||
|
|
||||||
|
if(HAVE_${var})
|
||||||
|
# The check compiled. Load information from the binary.
|
||||||
|
file(STRINGS ${bin} strings LIMIT_COUNT 10 REGEX "INFO:size")
|
||||||
|
|
||||||
|
# Parse the information strings.
|
||||||
|
set(regex_size ".*INFO:size\\[0*([^]]*)\\].*")
|
||||||
|
set(regex_key " key\\[([^]]*)\\]")
|
||||||
|
set(keys)
|
||||||
|
set(code)
|
||||||
|
set(mismatch)
|
||||||
|
set(first 1)
|
||||||
|
foreach(info ${strings})
|
||||||
|
if("${info}" MATCHES "${regex_size}")
|
||||||
|
# Get the type size.
|
||||||
|
string(REGEX REPLACE "${regex_size}" "\\1" size "${info}")
|
||||||
|
if(first)
|
||||||
|
set(${var} ${size})
|
||||||
|
elseif(NOT "${size}" STREQUAL "${${var}}")
|
||||||
|
set(mismatch 1)
|
||||||
|
endif()
|
||||||
|
set(first 0)
|
||||||
|
|
||||||
|
# Get the architecture map key.
|
||||||
|
string(REGEX MATCH "${regex_key}" key "${info}")
|
||||||
|
string(REGEX REPLACE "${regex_key}" "\\1" key "${key}")
|
||||||
|
if(key)
|
||||||
|
set(code "${code}\nset(${var}-${key} \"${size}\")")
|
||||||
|
list(APPEND keys ${key})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Update the architecture-to-size map.
|
||||||
|
if(mismatch AND keys)
|
||||||
|
configure_file(${__check_type_size_dir}/CheckTypeSizeMap.cmake.in ${map} @ONLY)
|
||||||
|
set(${var} 0)
|
||||||
|
else()
|
||||||
|
file(REMOVE ${map})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(mismatch AND NOT keys)
|
||||||
|
message(SEND_ERROR "CHECK_TYPE_SIZE found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Check size of ${type} - done")
|
||||||
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||||
|
"Determining size of ${type} passed with the following output:\n${output}\n\n")
|
||||||
|
set(${var} "${${var}}" CACHE INTERNAL "CHECK_TYPE_SIZE: sizeof(${type})")
|
||||||
|
else()
|
||||||
|
# The check failed to compile.
|
||||||
|
message(STATUS "Check size of ${type} - failed")
|
||||||
|
file(READ ${src} content)
|
||||||
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||||
|
"Determining size of ${type} failed with the following output:\n${output}\n${src}:\n${content}\n\n")
|
||||||
|
set(${var} "" CACHE INTERNAL "CHECK_TYPE_SIZE: ${type} unknown")
|
||||||
|
file(REMOVE ${map})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
macro(CHECK_TYPE_SIZE TYPE VARIABLE)
|
||||||
|
# parse arguments
|
||||||
|
unset(doing)
|
||||||
|
foreach(arg ${ARGN})
|
||||||
|
if("x${arg}" STREQUAL "xBUILTIN_TYPES_ONLY")
|
||||||
|
set(_CHECK_TYPE_SIZE_${arg} 1)
|
||||||
|
unset(doing)
|
||||||
|
elseif("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys
|
||||||
|
set(doing "${arg}")
|
||||||
|
set(_CHECK_TYPE_SIZE_${doing} "")
|
||||||
|
elseif("x${doing}" STREQUAL "xLANGUAGE")
|
||||||
|
set(_CHECK_TYPE_SIZE_${doing} "${arg}")
|
||||||
|
unset(doing)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
if("x${doing}" MATCHES "^x(LANGUAGE)$")
|
||||||
|
message(FATAL_ERROR "Missing argument:\n ${doing} arguments requires a value\n")
|
||||||
|
endif()
|
||||||
|
if(DEFINED _CHECK_TYPE_SIZE_LANGUAGE)
|
||||||
|
if(NOT "x${_CHECK_TYPE_SIZE_LANGUAGE}" MATCHES "^x(C|CXX)$")
|
||||||
|
message(FATAL_ERROR "Unknown language:\n ${_CHECK_TYPE_SIZE_LANGUAGE}.\nSupported languages: C, CXX.\n")
|
||||||
|
endif()
|
||||||
|
set(_language ${_CHECK_TYPE_SIZE_LANGUAGE})
|
||||||
|
else()
|
||||||
|
set(_language C)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Optionally check for standard headers.
|
||||||
|
if(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
|
||||||
|
set(_builtin 0)
|
||||||
|
else()
|
||||||
|
set(_builtin 1)
|
||||||
|
if ("x${_CHECK_TYPE_SIZE_LANGUAGE}" STREQUAL "xCXX")
|
||||||
|
check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
|
||||||
|
check_include_file_cxx(stdint.h HAVE_STDINT_H)
|
||||||
|
check_include_file_cxx(stddef.h HAVE_STDDEF_H)
|
||||||
|
else ()
|
||||||
|
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||||
|
check_include_file(stdint.h HAVE_STDINT_H)
|
||||||
|
check_include_file(stddef.h HAVE_STDDEF_H)
|
||||||
|
endif ()
|
||||||
|
endif()
|
||||||
|
unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
|
||||||
|
unset(_CHECK_TYPE_SIZE_LANGUAGE)
|
||||||
|
|
||||||
|
# Compute or load the size or size map.
|
||||||
|
set(${VARIABLE}_KEYS)
|
||||||
|
set(_map_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${VARIABLE}.cmake)
|
||||||
|
if(NOT DEFINED HAVE_${VARIABLE})
|
||||||
|
__check_type_size_impl(${TYPE} ${VARIABLE} ${_map_file} ${_builtin} ${_language})
|
||||||
|
endif()
|
||||||
|
include(${_map_file} OPTIONAL)
|
||||||
|
set(_map_file)
|
||||||
|
set(_builtin)
|
||||||
|
|
||||||
|
# Create preprocessor code.
|
||||||
|
if(${VARIABLE}_KEYS)
|
||||||
|
set(${VARIABLE}_CODE)
|
||||||
|
set(_if if)
|
||||||
|
foreach(key ${${VARIABLE}_KEYS})
|
||||||
|
set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#${_if} defined(${key})\n# define ${VARIABLE} ${${VARIABLE}-${key}}\n")
|
||||||
|
set(_if elif)
|
||||||
|
endforeach()
|
||||||
|
set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#else\n# error ${VARIABLE} unknown\n#endif")
|
||||||
|
set(_if)
|
||||||
|
elseif(${VARIABLE})
|
||||||
|
set(${VARIABLE}_CODE "#define ${VARIABLE} ${${VARIABLE}}")
|
||||||
|
else()
|
||||||
|
set(${VARIABLE}_CODE "/* #undef ${VARIABLE} */")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
cmake_policy(POP)
|
1
cmake/CheckTypeSizeMap.cmake.in
Normal file
1
cmake/CheckTypeSizeMap.cmake.in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
set(@var@_KEYS "@keys@")@code@
|
181
cmake/FindThreadsCXX.cmake
Normal file
181
cmake/FindThreadsCXX.cmake
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
#.rst:
|
||||||
|
# FindThreads
|
||||||
|
# -----------
|
||||||
|
#
|
||||||
|
# This module determines the thread library of the system.
|
||||||
|
#
|
||||||
|
# The following variables are set
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# CMAKE_THREAD_LIBS_INIT - the thread library
|
||||||
|
# CMAKE_USE_SPROC_INIT - are we using sproc?
|
||||||
|
# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads?
|
||||||
|
# CMAKE_USE_PTHREADS_INIT - are we using pthreads
|
||||||
|
# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads
|
||||||
|
#
|
||||||
|
# For systems with multiple thread libraries, caller can set
|
||||||
|
#
|
||||||
|
# ::
|
||||||
|
#
|
||||||
|
# CMAKE_THREAD_PREFER_PTHREAD
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2002-2009 Kitware, Inc.
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
include (CheckIncludeFileCXX)
|
||||||
|
include (CheckCXXLibraryExists)
|
||||||
|
include (CheckCXXSymbolExists)
|
||||||
|
set(Threads_FOUND FALSE)
|
||||||
|
|
||||||
|
|
||||||
|
# Do we have sproc?
|
||||||
|
if(CMAKE_SYSTEM MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD)
|
||||||
|
CHECK_INCLUDE_FILES_CXX("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD)
|
||||||
|
# We have sproc
|
||||||
|
set(CMAKE_USE_SPROC_INIT 1)
|
||||||
|
else()
|
||||||
|
# Do we have pthreads?
|
||||||
|
CHECK_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H)
|
||||||
|
if(CMAKE_HAVE_PTHREAD_H)
|
||||||
|
|
||||||
|
#
|
||||||
|
# We have pthread.h
|
||||||
|
# Let's check for the library now.
|
||||||
|
#
|
||||||
|
set(CMAKE_HAVE_THREADS_LIBRARY)
|
||||||
|
if(NOT THREADS_HAVE_PTHREAD_ARG)
|
||||||
|
# Check if pthread functions are in normal C library
|
||||||
|
CHECK_CXX_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE)
|
||||||
|
if(CMAKE_HAVE_LIBC_CREATE)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "")
|
||||||
|
set(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_HAVE_THREADS_LIBRARY)
|
||||||
|
# Do we have -lpthreads
|
||||||
|
CHECK_CXX_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
|
||||||
|
if(CMAKE_HAVE_PTHREADS_CREATE)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "-lpthreads")
|
||||||
|
set(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Ok, how about -lpthread
|
||||||
|
CHECK_CXX_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
|
||||||
|
if(CMAKE_HAVE_PTHREAD_CREATE)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
|
||||||
|
set(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM MATCHES "SunOS.*")
|
||||||
|
# On sun also check for -lthread
|
||||||
|
CHECK_CXX_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
|
||||||
|
if(CMAKE_HAVE_THR_CREATE)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "-lthread")
|
||||||
|
set(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_HAVE_THREADS_LIBRARY)
|
||||||
|
# If we did not found -lpthread, -lpthreads, or -lthread, look for -pthread
|
||||||
|
if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
|
||||||
|
message(STATUS "Check if compiler accepts -pthread")
|
||||||
|
configure_file ("${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.cxx"
|
||||||
|
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx" COPYONLY)
|
||||||
|
try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
|
||||||
|
${CMAKE_BINARY_DIR}
|
||||||
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx
|
||||||
|
CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=-pthread;-DCMAKE_CXX_FLAGS:STRING=-fpermissive"
|
||||||
|
COMPILE_OUTPUT_VARIABLE OUTPUT)
|
||||||
|
|
||||||
|
if(THREADS_HAVE_PTHREAD_ARG)
|
||||||
|
if(THREADS_PTHREAD_ARG STREQUAL "2")
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
message(STATUS "Check if compiler accepts -pthread - yes")
|
||||||
|
else()
|
||||||
|
message(STATUS "Check if compiler accepts -pthread - no")
|
||||||
|
file(APPEND
|
||||||
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||||
|
"Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS "Check if compiler accepts -pthread - no")
|
||||||
|
file(APPEND
|
||||||
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||||
|
"Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(THREADS_HAVE_PTHREAD_ARG)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "-pthread")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE)
|
||||||
|
set(CMAKE_USE_PTHREADS_INIT 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM MATCHES "Windows")
|
||||||
|
set(CMAKE_USE_WIN32_THREADS_INIT 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_USE_PTHREADS_INIT)
|
||||||
|
if(CMAKE_SYSTEM MATCHES "HP-UX-*")
|
||||||
|
# Use libcma if it exists and can be used. It provides more
|
||||||
|
# symbols than the plain pthread library. CMA threads
|
||||||
|
# have actually been deprecated:
|
||||||
|
# http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395
|
||||||
|
# http://docs.hp.com/en/947/d8.html
|
||||||
|
# but we need to maintain compatibility here.
|
||||||
|
# The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads
|
||||||
|
# are available.
|
||||||
|
CHECK_CXX_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA)
|
||||||
|
if(CMAKE_HAVE_HP_CMA)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "-lcma")
|
||||||
|
set(CMAKE_HP_PTHREADS_INIT 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
set(CMAKE_USE_PTHREADS_INIT 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM MATCHES "OSF1-V*")
|
||||||
|
set(CMAKE_USE_PTHREADS_INIT 0)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM MATCHES "CYGWIN_NT*")
|
||||||
|
set(CMAKE_USE_PTHREADS_INIT 1)
|
||||||
|
set(Threads_FOUND TRUE)
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT )
|
||||||
|
set(CMAKE_USE_WIN32_THREADS_INIT 0)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)
|
|
@ -1,26 +0,0 @@
|
||||||
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
|
||||||
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
|
||||||
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
|
||||||
|
|
||||||
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
|
|
||||||
set (CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")
|
|
||||||
endif ()
|
|
||||||
message(${CMAKE_INSTALL_PREFIX})
|
|
||||||
|
|
||||||
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
|
|
||||||
string(REGEX REPLACE "\n" ";" files "${files}")
|
|
||||||
foreach(file ${files})
|
|
||||||
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
|
|
||||||
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
|
||||||
exec_program(
|
|
||||||
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
|
||||||
OUTPUT_VARIABLE rm_out
|
|
||||||
RETURN_VALUE rm_retval
|
|
||||||
)
|
|
||||||
if(NOT "${rm_retval}" STREQUAL 0)
|
|
||||||
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
|
|
||||||
endif(NOT "${rm_retval}" STREQUAL 0)
|
|
||||||
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
|
||||||
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
|
|
||||||
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
|
||||||
endforeach(file)
|
|
|
@ -1,183 +1,23 @@
|
||||||
## gflags CMake configuration file
|
## gflags CMake configuration file
|
||||||
|
|
||||||
# library version information
|
# library version information
|
||||||
set (@PACKAGE_PREFIX@_VERSION_STRING "@PACKAGE_VERSION@")
|
set (@PACKAGE_NAME@_VERSION_STRING "@PACKAGE_VERSION@")
|
||||||
set (@PACKAGE_PREFIX@_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@)
|
set (@PACKAGE_NAME@_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@)
|
||||||
set (@PACKAGE_PREFIX@_VERSION_MINOR @PACKAGE_VERSION_MINOR@)
|
set (@PACKAGE_NAME@_VERSION_MINOR @PACKAGE_VERSION_MINOR@)
|
||||||
set (@PACKAGE_PREFIX@_VERSION_PATCH @PACKAGE_VERSION_PATCH@)
|
set (@PACKAGE_NAME@_VERSION_PATCH @PACKAGE_VERSION_PATCH@)
|
||||||
|
|
||||||
# import targets
|
# import targets
|
||||||
if (NOT DEFINED @PACKAGE_PREFIX@_USE_TARGET_NAMESPACE)
|
include ("${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-export.cmake")
|
||||||
set (@PACKAGE_PREFIX@_USE_TARGET_NAMESPACE FALSE)
|
|
||||||
endif ()
|
|
||||||
if (@PACKAGE_PREFIX@_USE_TARGET_NAMESPACE)
|
|
||||||
include ("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_NAME@.cmake")
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET_NAMESPACE @PACKAGE_NAME@)
|
|
||||||
else ()
|
|
||||||
include ("${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-nonamespace-targets.cmake")
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET_NAMESPACE)
|
|
||||||
endif ()
|
|
||||||
if (@PACKAGE_PREFIX@_TARGET_NAMESPACE)
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET_PREFIX ${@PACKAGE_PREFIX@_TARGET_NAMESPACE}::)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET_PREFIX)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# installation prefix
|
# installation prefix
|
||||||
get_filename_component (CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
get_filename_component (CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||||
get_filename_component (_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_PREFIX_REL2CONFIG_DIR@" ABSOLUTE)
|
get_filename_component (_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_PREFIX_REL2CONFIG_DIR@" ABSOLUTE)
|
||||||
|
|
||||||
# include directory
|
# include directory
|
||||||
#
|
set (@PACKAGE_NAME@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
|
||||||
# Newer versions of CMake set the INTERFACE_INCLUDE_DIRECTORIES property
|
|
||||||
# of the imported targets. It is hence not necessary to add this path
|
|
||||||
# manually to the include search path for targets which link to gflags.
|
|
||||||
set (@PACKAGE_PREFIX@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
|
|
||||||
|
|
||||||
if (@PACKAGE_NAME@_FIND_COMPONENTS)
|
# gflags library
|
||||||
foreach (@PACKAGE_NAME@_FIND_COMPONENT IN LISTS @PACKAGE_NAME@_FIND_COMPONENTS)
|
set (@PACKAGE_NAME@_LIBRARIES gflags)
|
||||||
if (@PACKAGE_NAME@_FIND_REQUIRED_${@PACKAGE_NAME@_FIND_COMPONENT} AND NOT TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_${@PACKAGE_NAME@_FIND_COMPONENT})
|
|
||||||
message (FATAL_ERROR "Package @PACKAGE_NAME@ was installed without required component ${@PACKAGE_PREFIX@_TARGET_PREFIX}${@PACKAGE_NAME@_FIND_COMPONENT}!")
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
list (GET @PACKAGE_NAME@_FIND_COMPONENTS 0 @PACKAGE_NAME@_FIND_COMPONENT)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_NAME@_FIND_COMPONENT)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# default settings of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS
|
|
||||||
#
|
|
||||||
# It is recommended to use either one of the following find_package commands
|
|
||||||
# instead of setting the @PACKAGE_PREFIX@_(SHARED|NOTHREADS) variables:
|
|
||||||
# - find_package(@PACKAGE_NAME@ REQUIRED)
|
|
||||||
# - find_package(@PACKAGE_NAME@ COMPONENTS nothreads_static)
|
|
||||||
# - find_package(@PACKAGE_NAME@ COMPONENTS nothreads_shared)
|
|
||||||
# - find_package(@PACKAGE_NAME@ COMPONENTS static)
|
|
||||||
# - find_package(@PACKAGE_NAME@ COMPONENTS shared)
|
|
||||||
if (NOT DEFINED @PACKAGE_PREFIX@_SHARED)
|
|
||||||
if (DEFINED @PACKAGE_NAME@_SHARED)
|
|
||||||
set (@PACKAGE_PREFIX@_SHARED ${@PACKAGE_NAME@_SHARED})
|
|
||||||
elseif (@PACKAGE_NAME@_FIND_COMPONENT)
|
|
||||||
if (@PACKAGE_NAME@_FIND_COMPONENT MATCHES "shared")
|
|
||||||
set (@PACKAGE_PREFIX@_SHARED TRUE)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_SHARED FALSE)
|
|
||||||
endif ()
|
|
||||||
elseif (TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared OR TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_shared)
|
|
||||||
set (@PACKAGE_PREFIX@_SHARED TRUE)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_SHARED FALSE)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
if (NOT DEFINED @PACKAGE_PREFIX@_NOTHREADS)
|
|
||||||
if (DEFINED @PACKAGE_NAME@_NOTHREADS)
|
|
||||||
set (@PACKAGE_PREFIX@_NOTHREADS ${@PACKAGE_NAME@_NOTHREADS})
|
|
||||||
elseif (@PACKAGE_NAME@_FIND_COMPONENT)
|
|
||||||
if (@PACKAGE_NAME@_FIND_COMPONENT MATCHES "nothreads")
|
|
||||||
set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
|
|
||||||
endif ()
|
|
||||||
elseif (TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_static OR TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared)
|
|
||||||
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# choose imported library target
|
|
||||||
if (NOT @PACKAGE_PREFIX@_TARGET)
|
|
||||||
if (@PACKAGE_NAME@_TARGET)
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_NAME@_TARGET})
|
|
||||||
elseif (@PACKAGE_PREFIX@_SHARED)
|
|
||||||
if (@PACKAGE_PREFIX@_NOTHREADS)
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_shared)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared)
|
|
||||||
endif ()
|
|
||||||
else ()
|
|
||||||
if (@PACKAGE_PREFIX@_NOTHREADS)
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_static)
|
|
||||||
else ()
|
|
||||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_static)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET})
|
|
||||||
message (FATAL_ERROR "Your @PACKAGE_NAME@ installation does not contain a ${@PACKAGE_PREFIX@_TARGET} library target!"
|
|
||||||
" Try a different combination of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS.")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# add more convenient "${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@" import target
|
|
||||||
if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@)
|
|
||||||
if (@PACKAGE_PREFIX@_SHARED)
|
|
||||||
add_library (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ SHARED IMPORTED)
|
|
||||||
else ()
|
|
||||||
add_library (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ STATIC IMPORTED)
|
|
||||||
endif ()
|
|
||||||
# copy INTERFACE_* properties
|
|
||||||
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
|
|
||||||
COMPILE_DEFINITIONS
|
|
||||||
COMPILE_FEATURES
|
|
||||||
COMPILE_OPTIONS
|
|
||||||
INCLUDE_DIRECTORIES
|
|
||||||
LINK_LIBRARIES
|
|
||||||
POSITION_INDEPENDENT_CODE
|
|
||||||
)
|
|
||||||
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME})
|
|
||||||
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
|
|
||||||
set_target_properties(${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES
|
|
||||||
INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
# copy IMPORTED_*_<CONFIG> properties
|
|
||||||
get_target_property (_@PACKAGE_PREFIX@_CONFIGURATIONS ${@PACKAGE_PREFIX@_TARGET} IMPORTED_CONFIGURATIONS)
|
|
||||||
set_target_properties (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES IMPORTED_CONFIGURATIONS "${_@PACKAGE_PREFIX@_CONFIGURATIONS}")
|
|
||||||
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
|
|
||||||
IMPLIB
|
|
||||||
LOCATION
|
|
||||||
LINK_DEPENDENT_LIBRARIES
|
|
||||||
LINK_INTERFACE_LIBRARIES
|
|
||||||
LINK_INTERFACE_LANGUAGES
|
|
||||||
LINK_INTERFACE_MULTIPLICITY
|
|
||||||
NO_SONAME
|
|
||||||
SONAME
|
|
||||||
)
|
|
||||||
foreach (_@PACKAGE_PREFIX@_CONFIG IN LISTS _@PACKAGE_PREFIX@_CONFIGURATIONS)
|
|
||||||
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG})
|
|
||||||
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
|
|
||||||
set_target_properties(${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES
|
|
||||||
IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
endforeach ()
|
|
||||||
endforeach ()
|
|
||||||
unset (_@PACKAGE_PREFIX@_CONFIGURATIONS)
|
|
||||||
unset (_@PACKAGE_PREFIX@_CONFIG)
|
|
||||||
unset (_@PACKAGE_PREFIX@_PROPERTY_NAME)
|
|
||||||
unset (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# alias for default import target to be compatible with older CMake package configurations
|
|
||||||
set (@PACKAGE_PREFIX@_LIBRARIES "${@PACKAGE_PREFIX@_TARGET}")
|
|
||||||
|
|
||||||
# set @PACKAGE_NAME@_* variables for backwards compatibility
|
|
||||||
if (NOT "^@PACKAGE_NAME@$" STREQUAL "^@PACKAGE_PREFIX@$")
|
|
||||||
foreach (_@PACKAGE_PREFIX@_VARIABLE IN ITEMS
|
|
||||||
VERSION_STRING
|
|
||||||
VERSION_MAJOR
|
|
||||||
VERSION_MINOR
|
|
||||||
VERSION_PATCH
|
|
||||||
INCLUDE_DIR
|
|
||||||
LIBRARIES
|
|
||||||
TARGET
|
|
||||||
)
|
|
||||||
set (@PACKAGE_NAME@_${_@PACKAGE_PREFIX@_VARIABLE} "${@PACKAGE_PREFIX@_${_@PACKAGE_PREFIX@_VARIABLE}}")
|
|
||||||
endforeach ()
|
|
||||||
unset (_@PACKAGE_PREFIX@_VARIABLE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# unset private variables
|
# unset private variables
|
||||||
unset (@PACKAGE_NAME@_FIND_COMPONENT)
|
|
||||||
unset (_INSTALL_PREFIX)
|
unset (_INSTALL_PREFIX)
|
||||||
|
|
|
@ -27,23 +27,40 @@ elseif (CPACK_GENERATOR MATCHES "DEB")
|
||||||
else ()
|
else ()
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}0")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}0")
|
||||||
endif ()
|
endif ()
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_${CPACK_PACKAGE_VERSION}-1_${CPACK_PACKAGE_ARCHITECTURE}")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_${CPACK_PACKAGE_VERSION}-1_${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
|
||||||
|
execute_process (
|
||||||
|
COMMAND dpkg --print-architecture
|
||||||
|
RESULT_VARIABLE RV
|
||||||
|
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
|
||||||
|
)
|
||||||
|
if (NOT RV EQUAL 0)
|
||||||
|
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set (CPACK_DEBIAN_PACKAGE_DEPENDS)
|
set (CPACK_DEBIAN_PACKAGE_DEPENDS)
|
||||||
set (CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
set (CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
||||||
set (CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
set (CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
||||||
set (CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_RPM_PACKAGE_URL}")
|
set (CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_RPM_PACKAGE_URL}")
|
||||||
set (CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
|
set (CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
|
||||||
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_PACKAGE_ARCHITECTURE}")
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# RPM package
|
# RPM package
|
||||||
elseif (CPACK_GENERATOR MATCHES "RPM")
|
elseif (CPACK_GENERATOR MATCHES "RPM")
|
||||||
|
|
||||||
|
execute_process (
|
||||||
|
COMMAND dpkg --print-architecture
|
||||||
|
RESULT_VARIABLE RV
|
||||||
|
OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
|
||||||
|
)
|
||||||
|
if (NOT RV EQUAL 0)
|
||||||
|
set (CPACK_RPM_PACKAGE_ARCHITECTURE i386)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
||||||
if (DEVEL)
|
if (DEVEL)
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-devel")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-devel")
|
||||||
endif ()
|
endif ()
|
||||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_VERSION}-1.${CPACK_PACKAGE_ARCHITECTURE}")
|
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_VERSION}-1_${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
prefix=@CMAKE_INSTALL_PREFIX@
|
|
||||||
exec_prefix=${prefix}
|
|
||||||
bindir=${exec_prefix}/@RUNTIME_INSTALL_DIR@
|
|
||||||
libdir=${exec_prefix}/@LIBRARY_INSTALL_DIR@
|
|
||||||
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
|
|
||||||
|
|
||||||
Name: @PACKAGE_NAME@
|
|
||||||
Version: @PACKAGE_VERSION@
|
|
||||||
Description: @PACKAGE_DESCRIPTION@
|
|
||||||
URL: @PACKAGE_URL@
|
|
||||||
Requires:
|
|
||||||
Libs: -L${libdir} -lgflags
|
|
||||||
Libs.private: -lpthread
|
|
||||||
Cflags: -I${includedir}
|
|
|
@ -11,7 +11,7 @@ macro (bool_to_int VAR)
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
## Extract version numbers from version string
|
## Extract version numbers from version string.
|
||||||
function (version_numbers version major minor patch)
|
function (version_numbers version major minor patch)
|
||||||
if (version MATCHES "([0-9]+)(\\.[0-9]+)?(\\.[0-9]+)?(rc[1-9][0-9]*|[a-z]+)?")
|
if (version MATCHES "([0-9]+)(\\.[0-9]+)?(\\.[0-9]+)?(rc[1-9][0-9]*|[a-z]+)?")
|
||||||
if (CMAKE_MATCH_1)
|
if (CMAKE_MATCH_1)
|
||||||
|
@ -41,92 +41,17 @@ function (version_numbers version major minor patch)
|
||||||
set ("${patch}" "${_patch}" PARENT_SCOPE)
|
set ("${patch}" "${_patch}" PARENT_SCOPE)
|
||||||
endfunction ()
|
endfunction ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
## Determine if cache entry exists
|
|
||||||
macro (gflags_is_cached retvar varname)
|
|
||||||
if (DEFINED ${varname})
|
|
||||||
get_property (${retvar} CACHE ${varname} PROPERTY TYPE SET)
|
|
||||||
else ()
|
|
||||||
set (${retvar} FALSE)
|
|
||||||
endif ()
|
|
||||||
endmacro ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
## Add gflags configuration variable
|
|
||||||
#
|
|
||||||
# The default value of the (cached) configuration value can be overridden either
|
|
||||||
# on the CMake command-line or the super-project by setting the GFLAGS_<varname>
|
|
||||||
# variable. When gflags is a subproject of another project (GFLAGS_IS_SUBPROJECT),
|
|
||||||
# the variable is not added to the CMake cache. Otherwise it is cached.
|
|
||||||
macro (gflags_define type varname docstring default)
|
|
||||||
# note that ARGC must be expanded here, as it is not a "real" variable
|
|
||||||
# (see the CMake documentation for the macro command)
|
|
||||||
if ("${ARGC}" GREATER 5)
|
|
||||||
message (FATAL_ERROR "gflags_variable: Too many macro arguments")
|
|
||||||
endif ()
|
|
||||||
if (NOT DEFINED GFLAGS_${varname})
|
|
||||||
if (DEFINED ${varname})
|
|
||||||
set (GFLAGS_${varname} "${${varname}}")
|
|
||||||
else ()
|
|
||||||
if (GFLAGS_IS_SUBPROJECT AND "${ARGC}" EQUAL 5)
|
|
||||||
set (GFLAGS_${varname} "${ARGV4}")
|
|
||||||
else ()
|
|
||||||
set (GFLAGS_${varname} "${default}")
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
if (GFLAGS_IS_SUBPROJECT)
|
|
||||||
set (${varname} "${GFLAGS_${varname}}")
|
|
||||||
else ()
|
|
||||||
set (${varname} "${GFLAGS_${varname}}" CACHE ${type} "${docstring}")
|
|
||||||
endif ()
|
|
||||||
endmacro ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
## Set property of cached gflags configuration variable
|
|
||||||
macro (gflags_property varname property value)
|
|
||||||
gflags_is_cached (_cached ${varname})
|
|
||||||
if (_cached)
|
|
||||||
# note that property must be expanded here, as it is not a "real" variable
|
|
||||||
# (see the CMake documentation for the macro command)
|
|
||||||
if ("${property}" STREQUAL "ADVANCED")
|
|
||||||
if (${value})
|
|
||||||
mark_as_advanced (FORCE ${varname})
|
|
||||||
else ()
|
|
||||||
mark_as_advanced (CLEAR ${varname})
|
|
||||||
endif ()
|
|
||||||
else ()
|
|
||||||
set_property (CACHE ${varname} PROPERTY "${property}" "${value}")
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
unset (_cached)
|
|
||||||
endmacro ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
## Modify value of gflags configuration variable
|
|
||||||
macro (gflags_set varname value)
|
|
||||||
gflags_is_cached (_cached ${varname})
|
|
||||||
if (_cached)
|
|
||||||
set_property (CACHE ${varname} PROPERTY VALUE "${value}")
|
|
||||||
else ()
|
|
||||||
set (${varname} "${value}")
|
|
||||||
endif ()
|
|
||||||
unset (_cached)
|
|
||||||
endmacro ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
## Configure public header files
|
## Configure public header files
|
||||||
function (configure_headers out)
|
function (configure_headers out)
|
||||||
set (tmp)
|
set (tmp)
|
||||||
foreach (src IN LISTS ARGN)
|
foreach (src IN LISTS ARGN)
|
||||||
if (IS_ABSOLUTE "${src}")
|
if (EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
|
||||||
list (APPEND tmp "${src}")
|
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}" @ONLY)
|
||||||
elseif (EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
|
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}")
|
||||||
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}" @ONLY)
|
|
||||||
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}")
|
|
||||||
else ()
|
else ()
|
||||||
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}" "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}" COPYONLY)
|
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}" "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}" COPYONLY)
|
||||||
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}")
|
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}")
|
||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
set (${out} "${tmp}" PARENT_SCOPE)
|
set (${out} "${tmp}" PARENT_SCOPE)
|
||||||
|
@ -138,8 +63,8 @@ function (configure_sources out)
|
||||||
set (tmp)
|
set (tmp)
|
||||||
foreach (src IN LISTS ARGN)
|
foreach (src IN LISTS ARGN)
|
||||||
if (src MATCHES ".h$" AND EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
|
if (src MATCHES ".h$" AND EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
|
||||||
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}" @ONLY)
|
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}" @ONLY)
|
||||||
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}")
|
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}")
|
||||||
else ()
|
else ()
|
||||||
list (APPEND tmp "${PROJECT_SOURCE_DIR}/src/${src}")
|
list (APPEND tmp "${PROJECT_SOURCE_DIR}/src/${src}")
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -167,41 +92,3 @@ macro (add_gflags_test name expected_rc expected_output unexpected_output cmd)
|
||||||
WORKING_DIRECTORY "${GFLAGS_FLAGFILES_DIR}"
|
WORKING_DIRECTORY "${GFLAGS_FLAGFILES_DIR}"
|
||||||
)
|
)
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
## Register installed package with CMake
|
|
||||||
#
|
|
||||||
# This function adds an entry to the CMake registry for packages with the
|
|
||||||
# path of the directory where the package configuration file of the installed
|
|
||||||
# package is located in order to help CMake find the package in a custom
|
|
||||||
# installation prefix. This differs from CMake's export(PACKAGE) command
|
|
||||||
# which registers the build directory instead.
|
|
||||||
function (register_gflags_package CONFIG_DIR)
|
|
||||||
if (NOT IS_ABSOLUTE "${CONFIG_DIR}")
|
|
||||||
set (CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_DIR}")
|
|
||||||
endif ()
|
|
||||||
string (MD5 REGISTRY_ENTRY "${CONFIG_DIR}")
|
|
||||||
if (WIN32)
|
|
||||||
install (CODE
|
|
||||||
"execute_process (
|
|
||||||
COMMAND reg add \"HKCU\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\" /v \"${REGISTRY_ENTRY}\" /d \"${CONFIG_DIR}\" /t REG_SZ /f
|
|
||||||
RESULT_VARIABLE RT
|
|
||||||
ERROR_VARIABLE ERR
|
|
||||||
OUTPUT_QUIET
|
|
||||||
)
|
|
||||||
if (RT EQUAL 0)
|
|
||||||
message (STATUS \"Register: Added HKEY_CURRENT_USER\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\\\\${REGISTRY_ENTRY}\")
|
|
||||||
else ()
|
|
||||||
string (STRIP \"\${ERR}\" ERR)
|
|
||||||
message (STATUS \"Register: Failed to add registry entry: \${ERR}\")
|
|
||||||
endif ()"
|
|
||||||
)
|
|
||||||
elseif (IS_DIRECTORY "$ENV{HOME}")
|
|
||||||
file (WRITE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry" "${CONFIG_DIR}")
|
|
||||||
install (
|
|
||||||
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry"
|
|
||||||
DESTINATION "$ENV{HOME}/.cmake/packages/${PACKAGE_NAME}"
|
|
||||||
RENAME "${REGISTRY_ENTRY}"
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
endfunction ()
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
To update the GitHub Pages at http://gflags.github.io/gflags/, use command:
|
|
||||||
```
|
|
||||||
git subtree push --prefix=doc/ origin gh-pages
|
|
||||||
```
|
|
|
@ -38,20 +38,17 @@
|
||||||
<blockquote><dl>
|
<blockquote><dl>
|
||||||
<dt> Table of contents </dt>
|
<dt> Table of contents </dt>
|
||||||
<dd> <a href="#intro">Introduction</a> </dd>
|
<dd> <a href="#intro">Introduction</a> </dd>
|
||||||
<dd> <a href="#download">Download and Installation</a> </dd>
|
<dd> <a href="#cmake">Finding and Linking to gflags using CMake</a></dd>
|
||||||
<dd> <a href="#cmake">Declare dependency on gflags with CMake</a></dd>
|
|
||||||
<dd> <a href="#bazel">Declare dependency on gflags with Bazel</a></dd>
|
|
||||||
<dd> <a href="#define">DEFINE: Defining Flags In Program</A> </dd>
|
<dd> <a href="#define">DEFINE: Defining Flags In Program</A> </dd>
|
||||||
<dd> <a href="#using">Accessing the Flag</A> </dd>
|
<dd> <a href="#using">Accessing the Flag</A> </dd>
|
||||||
<dd> <a href="#declare">DECLARE: Using the Flag in a Different File</a> </dd>
|
<dd> <a href="#declare">DECLARE: Using the Flag in a Different File</a> </dd>
|
||||||
<dd> <a href="#validate">RegisterFlagValidator: Sanity-checking Flag Values</a> </dd>
|
<dd> <a href="#validate">RegisterFlagValidator: Sanity-checking Flag Values</a> </dd>
|
||||||
<dd> <a href="#together">Putting It Together: How to Set Up Flags</a> </dd>
|
<dd> <a href="#together">Putting It Together: How to Set Up Flags</a> </dd>
|
||||||
<dd> <a href="#commandline">Setting Flags on the Command Line</a> </dd>
|
<dd> <a href="#commandline">Setting Flags on the Command Line</a> </dd>
|
||||||
|
<dd> <a href="#varz">Setting Flags at Runtime</a> </dd>
|
||||||
<dd> <a href="#default">Changing the Default Flag Value</a> </dd>
|
<dd> <a href="#default">Changing the Default Flag Value</a> </dd>
|
||||||
<dd> <a href="#special">Special Flags</a> </dd>
|
<dd> <a href="#special">Special Flags</a> </dd>
|
||||||
<dd> <a href="#api">The API</a> </dd>
|
<dd> <a href="#api">The API</a> </dd>
|
||||||
<dd> <a href="#misc">Miscellaneous Notes</a> </dd>
|
|
||||||
<dd> <a href="#issues">Issues and Feature Requests</a> </dd>
|
|
||||||
<dd> <br/> </dd>
|
<dd> <br/> </dd>
|
||||||
</dl></blockquote>
|
</dl></blockquote>
|
||||||
|
|
||||||
|
@ -94,86 +91,16 @@ library. It's a C++ library, so examples are in C++. However, there
|
||||||
is a Python port with the same functionality, and this discussion
|
is a Python port with the same functionality, and this discussion
|
||||||
translates directly to Python.</p>
|
translates directly to Python.</p>
|
||||||
|
|
||||||
<h2> <A NAME=download>Download and Installation</A> </h2>
|
<h2> <A name=cmake>Finding and Linking to gflags </A> using CMake</h2>
|
||||||
|
|
||||||
<p>The gflags library can be downloaded from <A href="https://github.com/gflags/gflags">GitHub</A>.
|
<p> Using gflags within a project which uses <A href="http://www.cmake.org">CMake</A> for its build system is easy. Therefore, simply add the following CMake code to your <code>CMakeLists.txt</code> file.
|
||||||
You can clone the project using the command:</p>
|
|
||||||
<pre>
|
|
||||||
git clone https://github.com/gflags/gflags.git
|
|
||||||
</pre>
|
|
||||||
<p>Build and installation instructions are provided in the
|
|
||||||
<A href="https://github.com/gflags/gflags/blob/master/INSTALL.md">INSTALL</A> file.
|
|
||||||
The installation of the gflags package includes configuration files for popular build systems
|
|
||||||
such as <A href="https://www.freedesktop.org/wiki/Software/pkg-config/">pkg-config</A>,
|
|
||||||
<A href="#cmake">CMake</A>, and <A href="#bazel">Bazel</A>.</p>
|
|
||||||
|
|
||||||
|
|
||||||
<h2> <A name=cmake>Declare dependency on gflags with CMake</A></h2>
|
|
||||||
|
|
||||||
<p>Using gflags within a project which uses <A href="http://www.cmake.org">CMake</A> for its build system is easy.
|
|
||||||
You can either require an external installation of the gflags package and find it using CMake's find_package
|
|
||||||
command, or include the gflags project as subtree or submodule within your project's source tree and add the directory
|
|
||||||
using CMake's add_subdirectory command.
|
|
||||||
|
|
||||||
<p>To use an external gflags installation, add the following CMake code to your <code>CMakeLists.txt</code> file.</p>
|
|
||||||
|
|
||||||
<p>Find gflags installation. The <code>gflags_DIR</code> variable must be set to the <prefix>/lib/cmake/gflags directory
|
|
||||||
containing the gflags-config.cmake file if <prefix> is a non-standard location. Otherwise, CMake should find
|
|
||||||
the gflags installation automatically.</p>
|
|
||||||
<pre>
|
|
||||||
find_package(gflags REQUIRED)
|
|
||||||
</pre>
|
|
||||||
<p>To request a particular imported gflags library target to link against, use the <code>COMPONENTS</code> option of
|
|
||||||
the find_package command. For example, to force the use of the single-threaded static library, use the command</p>
|
|
||||||
<pre>
|
|
||||||
find_package(gflags COMPONENTS nothreads_static)
|
|
||||||
</pre>
|
|
||||||
<p>Note that this will raise a fatal error when the installed gflags package does not contain the requested library.
|
|
||||||
It is therefore recommended to only specify the particular component to look for if a specific library must be used.
|
|
||||||
Otherwise, the gflags-config.cmake module will choose a suitable and available library for you. By default, the
|
|
||||||
multi-threaded gflags library with shared linkage is chosen if available.</p>
|
|
||||||
|
|
||||||
<p>When the source tree of the gflags project is included as subtree or submodule in the "gflags" directory of your project,
|
|
||||||
replace the above find_package command by <code>add_subdirectory(gflags)</code>. See the top of the <code>gflags/CMakeLists.txt</code>
|
|
||||||
file for a listing of available CMake variables that can be set before this command to configure the build of the
|
|
||||||
gflags library. The default build settings are the build of a single-threaded static library which does not require
|
|
||||||
any installation of the gflags subproject products.</p>
|
|
||||||
|
|
||||||
<p>Finally, add your executable build target which uses gflags to parse the command arguments with dependency on the
|
|
||||||
imported gflags library target:</p>
|
|
||||||
<pre>
|
|
||||||
add_executable(foo main.cc)
|
|
||||||
target_link_libraries(foo gflags::gflags)
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<h2> <A name=bazel>Declare dependency on gflags with Bazel</A></h2>
|
|
||||||
|
|
||||||
<p>To use gflags within a project which uses <A href="https://bazel.build/">Bazel</A> as build tool,
|
|
||||||
add the following lines to your <code>WORKSPACE</code> file
|
|
||||||
(see also Bazel documentation of <A href="https://www.bazel.io/versions/master/docs/be/workspace.html#git_repository">git_repository</A>):
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
git_repository(
|
find_package (gflags REQUIRED)
|
||||||
name = "com_github_gflags_gflags",
|
include_directories (${gflags_INCLUDE_DIR})
|
||||||
remote = "https://github.com/gflags/gflags.git",
|
|
||||||
tag = "v2.2.2"
|
add_executable (foo main.cc)
|
||||||
)
|
target_link_libraries (foo gflags)
|
||||||
</pre>
|
|
||||||
|
|
||||||
<p>You can then add <code>@com_github_gflags_gflags//:gflags</code> to the <code>deps</code> section of a
|
|
||||||
<code>cc_binary</code> or <code>cc_library</code> rule, and <code>#include "gflags/gflags.h"</code> to
|
|
||||||
include it in your source code. This uses the shared gflags library with multi-threading enabled.
|
|
||||||
In order to use the single-threaded shared gflags library, use the dependency
|
|
||||||
<code>@com_github_gflags_gflags//:gflags_nothreads</code> instead.</p>
|
|
||||||
|
|
||||||
<p>For example, see the following <code>BUILD</code> rule of the gflags/example project:</p>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
cc_binary(
|
|
||||||
name = "foo",
|
|
||||||
srcs = ["main.cc"],
|
|
||||||
deps = ["@com_github_gflags_gflags//:gflags"],
|
|
||||||
)
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h2> <A name=define>DEFINE: Defining Flags In Program</A> </h2>
|
<h2> <A name=define>DEFINE: Defining Flags In Program</A> </h2>
|
||||||
|
@ -319,20 +246,17 @@ static bool ValidatePort(const char* flagname, int32 value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DEFINE_int32(port, 0, "What port to listen on");
|
DEFINE_int32(port, 0, "What port to listen on");
|
||||||
DEFINE_validator(port, &ValidatePort);
|
static const bool port_dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort);
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>By doing the registration at global initialization time (right
|
<p>By doing the registration at global initialization time (right
|
||||||
after the DEFINE_int32), we ensure that the registration happens before
|
after the DEFINE), we ensure that the registration happens before
|
||||||
the commandline is parsed at the beginning of <code>main()</code>.</p>
|
the commandline is parsed at the beginning of <code>main()</code>.</p>
|
||||||
|
|
||||||
<p>The above used <code>DEFINE_validator</code> macro calls the
|
<p><code>RegisterFlagValidator()</code> returns true if the
|
||||||
<code>RegisterFlagValidator()</code> function which returns true if the
|
registration is successful. It return false if the registration fails
|
||||||
registration is successful. It returns false if the registration fails
|
|
||||||
because a) the first argument does not refer to a commandline flag, or
|
because a) the first argument does not refer to a commandline flag, or
|
||||||
b) a different validator has already been registered for this flag.
|
b) a different validator has already been registered for this flag.</p>
|
||||||
The return value is available as global static boolean variable named
|
|
||||||
<code><flag>_validator_registered</code>.</p>
|
|
||||||
|
|
||||||
|
|
||||||
<h2> <A name=together>Putting It Together: How to Set Up Flags</A> </h2>
|
<h2> <A name=together>Putting It Together: How to Set Up Flags</A> </h2>
|
||||||
|
@ -345,7 +269,7 @@ the getopt library, but has much less overhead to use. In fact, it's
|
||||||
just a single function call:</p>
|
just a single function call:</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>Usually, this code is at the beginning of <code>main()</code>.
|
<p>Usually, this code is at the beginning of <code>main()</code>.
|
||||||
|
@ -469,7 +393,7 @@ the application to print some information about itself and exit.</p>
|
||||||
<td>shows all flags from all files, sorted by file and then by name;
|
<td>shows all flags from all files, sorted by file and then by name;
|
||||||
shows the flagname, its default value, and its help string</td>
|
shows the flagname, its default value, and its help string</td>
|
||||||
</tr><tr valign=top>
|
</tr><tr valign=top>
|
||||||
<td><code>--helpful</code></td>
|
<td><code>--helpfull</code></td>
|
||||||
<td>same as -help, but unambiguously asks for all flags
|
<td>same as -help, but unambiguously asks for all flags
|
||||||
(in case -help changes in the future)</td>
|
(in case -help changes in the future)</td>
|
||||||
</tr><tr valign=top>
|
</tr><tr valign=top>
|
||||||
|
@ -542,7 +466,7 @@ the application.</p>
|
||||||
<p>Note it is still an error to say <code>--tryfromenv=foo</code> if
|
<p>Note it is still an error to say <code>--tryfromenv=foo</code> if
|
||||||
<code>foo</code> is not DEFINED somewhere in the application.</p>
|
<code>foo</code> is not DEFINED somewhere in the application.</p>
|
||||||
|
|
||||||
<h3 id="flagfiles"> <code>--flagfile</code> </h3>
|
<h3> <code>--flagfile</code> </h3>
|
||||||
|
|
||||||
<p><code>--flagfile=f</code> tells the commandlineflags module to read
|
<p><code>--flagfile=f</code> tells the commandlineflags module to read
|
||||||
the file <code>f</code>, and to run all the flag-assignments found in
|
the file <code>f</code>, and to run all the flag-assignments found in
|
||||||
|
@ -605,8 +529,8 @@ access parts of <code>argv</code> outside main, including the program
|
||||||
name (<code>argv[0]</code>).</p>
|
name (<code>argv[0]</code>).</p>
|
||||||
|
|
||||||
<p>For more information about these routines, and other useful helper
|
<p>For more information about these routines, and other useful helper
|
||||||
methods such as <code>gflags::SetUsageMessage()</code> and
|
methods such as <code>google::SetUsageMessage()</code> and
|
||||||
<code>gflags::SetVersionString</code>, see <code>gflags.h</code>.</p>
|
<code>google::SetVersionString</code>, see <code>gflags.h</code>.</p>
|
||||||
|
|
||||||
|
|
||||||
<h2> <A name="misc">Miscellaneous Notes</code> </h2>
|
<h2> <A name="misc">Miscellaneous Notes</code> </h2>
|
||||||
|
@ -620,10 +544,6 @@ methods such as <code>gflags::SetUsageMessage()</code> and
|
||||||
reduce the size of the resulting binary somewhat, and may also be
|
reduce the size of the resulting binary somewhat, and may also be
|
||||||
useful for security reasons.</p>
|
useful for security reasons.</p>
|
||||||
|
|
||||||
<h2> <A name="issues">Issues and Feature Requests</code> </h2>
|
|
||||||
|
|
||||||
<p>Please report any issues or ideas for additional features on <A href="https://github.com/gflags/gflags/issues">GitHub</A>.
|
|
||||||
We would also like to encourage <A href="https://github.com/gflags/gflags/pulls">pull requests</A> for bug fixes and implementations of new features.</p>
|
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<address>
|
<address>
|
59
src/config.h
59
src/config.h
|
@ -1,59 +0,0 @@
|
||||||
// Note: This header file is only used internally. It is not part of public interface!
|
|
||||||
|
|
||||||
#ifndef GFLAGS_CONFIG_H_
|
|
||||||
#define GFLAGS_CONFIG_H_
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// System checks
|
|
||||||
|
|
||||||
// CMake build configuration is written to defines.h file, unused by Bazel build
|
|
||||||
#if !defined(GFLAGS_BAZEL_BUILD)
|
|
||||||
# include "defines.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// gcc requires this to get PRId64, etc.
|
|
||||||
#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
|
|
||||||
# define __STDC_FORMAT_MACROS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Path separator
|
|
||||||
#ifndef PATH_SEPARATOR
|
|
||||||
# ifdef OS_WINDOWS
|
|
||||||
# define PATH_SEPARATOR '\\'
|
|
||||||
# else
|
|
||||||
# define PATH_SEPARATOR '/'
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Windows
|
|
||||||
|
|
||||||
// Always export symbols when compiling a shared library as this file is only
|
|
||||||
// included by internal modules when building the gflags library itself.
|
|
||||||
// The gflags_declare.h header file will set it to import these symbols otherwise.
|
|
||||||
#ifndef GFLAGS_DLL_DECL
|
|
||||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
|
||||||
# define GFLAGS_DLL_DECL __declspec(dllexport)
|
|
||||||
# elif defined(__GNUC__) && __GNUC__ >= 4
|
|
||||||
# define GFLAGS_DLL_DECL __attribute__((visibility("default")))
|
|
||||||
# else
|
|
||||||
# define GFLAGS_DLL_DECL
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
// Flags defined by the gflags library itself must be exported
|
|
||||||
#ifndef GFLAGS_DLL_DEFINE_FLAG
|
|
||||||
# define GFLAGS_DLL_DEFINE_FLAG GFLAGS_DLL_DECL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef OS_WINDOWS
|
|
||||||
// The unittests import the symbols of the shared gflags library
|
|
||||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
|
||||||
# define GFLAGS_DLL_DECL_FOR_UNITTESTS __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
# include "windows_port.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // GFLAGS_CONFIG_H_
|
|
115
src/config.h.in
Normal file
115
src/config.h.in
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/* Generated from config.h.in during build configuration using CMake. */
|
||||||
|
|
||||||
|
// Note: This header file is only used internally. It is not part of public interface!
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// System checks
|
||||||
|
|
||||||
|
// Define if you build this library for a MS Windows OS.
|
||||||
|
#cmakedefine OS_WINDOWS
|
||||||
|
|
||||||
|
// Define if you have the <stdint.h> header file.
|
||||||
|
#cmakedefine HAVE_STDINT_H
|
||||||
|
|
||||||
|
// Define if you have the <sys/types.h> header file.
|
||||||
|
#cmakedefine HAVE_SYS_TYPES_H
|
||||||
|
|
||||||
|
// Define if you have the <inttypes.h> header file.
|
||||||
|
#cmakedefine HAVE_INTTYPES_H
|
||||||
|
|
||||||
|
// Define if you have the <sys/stat.h> header file.
|
||||||
|
#cmakedefine HAVE_SYS_STAT_H
|
||||||
|
|
||||||
|
// Define if you have the <unistd.h> header file.
|
||||||
|
#cmakedefine HAVE_UNISTD_H
|
||||||
|
|
||||||
|
// Define if you have the <fnmatch.h> header file.
|
||||||
|
#cmakedefine HAVE_FNMATCH_H
|
||||||
|
|
||||||
|
// Define if you have the <shlwapi.h> header file (Windows 2000/XP).
|
||||||
|
#cmakedefine HAVE_SHLWAPI_H
|
||||||
|
|
||||||
|
// Define if you have the strtoll function.
|
||||||
|
#cmakedefine HAVE_STRTOLL
|
||||||
|
|
||||||
|
// Define if you have the strtoq function.
|
||||||
|
#cmakedefine HAVE_STRTOQ
|
||||||
|
|
||||||
|
// Define if you have the <pthread.h> header file.
|
||||||
|
#cmakedefine HAVE_PTHREAD
|
||||||
|
|
||||||
|
// Define if your pthread library defines the type pthread_rwlock_t
|
||||||
|
#cmakedefine HAVE_RWLOCK
|
||||||
|
|
||||||
|
// gcc requires this to get PRId64, etc.
|
||||||
|
#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
|
||||||
|
# define __STDC_FORMAT_MACROS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Package information
|
||||||
|
|
||||||
|
// Name of package.
|
||||||
|
#define PACKAGE @PROJECT_NAME@
|
||||||
|
|
||||||
|
// Define to the full name of this package.
|
||||||
|
#define PACKAGE_NAME @PACKAGE_NAME@
|
||||||
|
|
||||||
|
// Define to the full name and version of this package.
|
||||||
|
#define PACKAGE_STRING @PACKAGE_STRING@
|
||||||
|
|
||||||
|
// Define to the one symbol short name of this package.
|
||||||
|
#define PACKAGE_TARNAME @PACKAGE_TARNAME@
|
||||||
|
|
||||||
|
// Define to the version of this package.
|
||||||
|
#define PACKAGE_VERSION @PACKAGE_VERSION@
|
||||||
|
|
||||||
|
// Version number of package.
|
||||||
|
#define VERSION PACKAGE_VERSION
|
||||||
|
|
||||||
|
// Define to the address where bug reports for this package should be sent.
|
||||||
|
#define PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@
|
||||||
|
|
||||||
|
// Namespace of gflags library symbols.
|
||||||
|
#define GFLAGS_NAMESPACE @GFLAGS_NAMESPACE@
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Path separator
|
||||||
|
#ifndef PATH_SEPARATOR
|
||||||
|
# ifdef OS_WINDOWS
|
||||||
|
# define PATH_SEPARATOR '\\'
|
||||||
|
# else
|
||||||
|
# define PATH_SEPARATOR '/'
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Windows
|
||||||
|
|
||||||
|
// Whether gflags library is a DLL.
|
||||||
|
#ifndef GFLAGS_IS_A_DLL
|
||||||
|
# define GFLAGS_IS_A_DLL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Always export symbols when compiling a shared library as this file is only
|
||||||
|
// included by internal modules when building the gflags library itself.
|
||||||
|
// The gflags_declare.h header file will set it to import these symbols otherwise.
|
||||||
|
#ifndef GFLAGS_DLL_DECL
|
||||||
|
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||||
|
# define GFLAGS_DLL_DECL __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# define GFLAGS_DLL_DECL
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
// Flags defined by the gflags library itself must be exported
|
||||||
|
#ifndef GFLAGS_DLL_DEFINE_FLAG
|
||||||
|
# define GFLAGS_DLL_DEFINE_FLAG GFLAGS_DLL_DECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OS_WINDOWS
|
||||||
|
// The unittests import the symbols of the shared gflags library
|
||||||
|
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||||
|
# define GFLAGS_DLL_DECL_FOR_UNITTESTS __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# include "windows_port.h"
|
||||||
|
#endif
|
|
@ -1,48 +0,0 @@
|
||||||
/* Generated from defines.h.in during build configuration using CMake. */
|
|
||||||
|
|
||||||
// Note: This header file is only used internally. It is not part of public interface!
|
|
||||||
// Any cmakedefine is defined using the -D flag instead when Bazel is used.
|
|
||||||
// For Bazel, this file is thus not used to avoid a private file in $(GENDIR).
|
|
||||||
|
|
||||||
#ifndef GFLAGS_DEFINES_H_
|
|
||||||
#define GFLAGS_DEFINES_H_
|
|
||||||
|
|
||||||
|
|
||||||
// Define if you build this library for a MS Windows OS.
|
|
||||||
#cmakedefine OS_WINDOWS
|
|
||||||
|
|
||||||
// Define if you have the <stdint.h> header file.
|
|
||||||
#cmakedefine HAVE_STDINT_H
|
|
||||||
|
|
||||||
// Define if you have the <sys/types.h> header file.
|
|
||||||
#cmakedefine HAVE_SYS_TYPES_H
|
|
||||||
|
|
||||||
// Define if you have the <inttypes.h> header file.
|
|
||||||
#cmakedefine HAVE_INTTYPES_H
|
|
||||||
|
|
||||||
// Define if you have the <sys/stat.h> header file.
|
|
||||||
#cmakedefine HAVE_SYS_STAT_H
|
|
||||||
|
|
||||||
// Define if you have the <unistd.h> header file.
|
|
||||||
#cmakedefine HAVE_UNISTD_H
|
|
||||||
|
|
||||||
// Define if you have the <fnmatch.h> header file.
|
|
||||||
#cmakedefine HAVE_FNMATCH_H
|
|
||||||
|
|
||||||
// Define if you have the <shlwapi.h> header file (Windows 2000/XP).
|
|
||||||
#cmakedefine HAVE_SHLWAPI_H
|
|
||||||
|
|
||||||
// Define if you have the strtoll function.
|
|
||||||
#cmakedefine HAVE_STRTOLL
|
|
||||||
|
|
||||||
// Define if you have the strtoq function.
|
|
||||||
#cmakedefine HAVE_STRTOQ
|
|
||||||
|
|
||||||
// Define if you have the <pthread.h> header file.
|
|
||||||
#cmakedefine HAVE_PTHREAD
|
|
||||||
|
|
||||||
// Define if your pthread library defines the type pthread_rwlock_t
|
|
||||||
#cmakedefine HAVE_RWLOCK
|
|
||||||
|
|
||||||
|
|
||||||
#endif // GFLAGS_DEFINES_H_
|
|
372
src/gflags.cc
372
src/gflags.cc
|
@ -88,20 +88,19 @@
|
||||||
// are, similarly, mostly hooks into the functionality described above.
|
// are, similarly, mostly hooks into the functionality described above.
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gflags/gflags.h"
|
#include "gflags.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <assert.h>
|
||||||
#include <cctype>
|
#include <ctype.h>
|
||||||
#include <cerrno>
|
#include <errno.h>
|
||||||
#if defined(HAVE_FNMATCH_H)
|
#if defined(HAVE_FNMATCH_H)
|
||||||
# include <fnmatch.h>
|
# include <fnmatch.h>
|
||||||
#elif defined(HAVE_SHLWAPI_H)
|
#elif defined(HAVE_SHLWAPI_H)
|
||||||
# define NO_SHLWAPI_ISOS
|
|
||||||
# include <shlwapi.h>
|
# include <shlwapi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <cstdarg> // For va_list and related operations
|
#include <stdarg.h> // For va_list and related operations
|
||||||
#include <cstdio>
|
#include <stdio.h>
|
||||||
#include <cstring>
|
#include <string.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -112,9 +111,6 @@
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using namespace MUTEX_NAMESPACE;
|
|
||||||
|
|
||||||
|
|
||||||
// Special flags, type 1: the 'recursive' flags. They set another flag's val.
|
// Special flags, type 1: the 'recursive' flags. They set another flag's val.
|
||||||
DEFINE_string(flagfile, "", "load flags from file");
|
DEFINE_string(flagfile, "", "load flags from file");
|
||||||
DEFINE_string(fromenv, "", "set flags from the environment"
|
DEFINE_string(fromenv, "", "set flags from the environment"
|
||||||
|
@ -171,10 +167,12 @@ enum DieWhenReporting { DIE, DO_NOT_DIE };
|
||||||
|
|
||||||
// Report Error and exit if requested.
|
// Report Error and exit if requested.
|
||||||
static void ReportError(DieWhenReporting should_die, const char* format, ...) {
|
static void ReportError(DieWhenReporting should_die, const char* format, ...) {
|
||||||
|
char error_message[255];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
vfprintf(stderr, format, ap);
|
vsnprintf(error_message, sizeof(error_message), format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
fprintf(stderr, "%s", error_message);
|
||||||
fflush(stderr); // should be unnecessary, but cygwin's rxvt buffers stderr
|
fflush(stderr); // should be unnecessary, but cygwin's rxvt buffers stderr
|
||||||
if (should_die == DIE) gflags_exitfunc(1);
|
if (should_die == DIE) gflags_exitfunc(1);
|
||||||
}
|
}
|
||||||
|
@ -190,41 +188,34 @@ static void ReportError(DieWhenReporting should_die, const char* format, ...) {
|
||||||
class CommandLineFlag;
|
class CommandLineFlag;
|
||||||
class FlagValue {
|
class FlagValue {
|
||||||
public:
|
public:
|
||||||
enum ValueType {
|
FlagValue(void* valbuf, const char* type, bool transfer_ownership_of_value);
|
||||||
FV_BOOL = 0,
|
|
||||||
FV_INT32 = 1,
|
|
||||||
FV_UINT32 = 2,
|
|
||||||
FV_INT64 = 3,
|
|
||||||
FV_UINT64 = 4,
|
|
||||||
FV_DOUBLE = 5,
|
|
||||||
FV_STRING = 6,
|
|
||||||
FV_MAX_INDEX = 6,
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename FlagType>
|
|
||||||
FlagValue(FlagType* valbuf, bool transfer_ownership_of_value);
|
|
||||||
~FlagValue();
|
~FlagValue();
|
||||||
|
|
||||||
bool ParseFrom(const char* spec);
|
bool ParseFrom(const char* spec);
|
||||||
string ToString() const;
|
string ToString() const;
|
||||||
|
|
||||||
ValueType Type() const { return static_cast<ValueType>(type_); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CommandLineFlag; // for many things, including Validate()
|
friend class CommandLineFlag; // for many things, including Validate()
|
||||||
friend class GFLAGS_NAMESPACE::FlagSaverImpl; // calls New()
|
friend class GFLAGS_NAMESPACE::FlagSaverImpl; // calls New()
|
||||||
friend class FlagRegistry; // checks value_buffer_ for flags_by_ptr_ map
|
friend class FlagRegistry; // checks value_buffer_ for flags_by_ptr_ map
|
||||||
template <typename T> friend T GetFromEnv(const char*, T);
|
template <typename T> friend T GetFromEnv(const char*, const char*, T);
|
||||||
friend bool TryParseLocked(const CommandLineFlag*, FlagValue*,
|
friend bool TryParseLocked(const CommandLineFlag*, FlagValue*,
|
||||||
const char*, string*); // for New(), CopyFrom()
|
const char*, string*); // for New(), CopyFrom()
|
||||||
|
|
||||||
template <typename FlagType>
|
enum ValueType {
|
||||||
struct FlagValueTraits;
|
FV_BOOL = 0,
|
||||||
|
FV_INT32 = 1,
|
||||||
|
FV_INT64 = 2,
|
||||||
|
FV_UINT64 = 3,
|
||||||
|
FV_DOUBLE = 4,
|
||||||
|
FV_STRING = 5,
|
||||||
|
FV_MAX_INDEX = 5,
|
||||||
|
};
|
||||||
const char* TypeName() const;
|
const char* TypeName() const;
|
||||||
bool Equal(const FlagValue& x) const;
|
bool Equal(const FlagValue& x) const;
|
||||||
FlagValue* New() const; // creates a new one with default value
|
FlagValue* New() const; // creates a new one with default value
|
||||||
void CopyFrom(const FlagValue& x);
|
void CopyFrom(const FlagValue& x);
|
||||||
|
int ValueSize() const;
|
||||||
|
|
||||||
// Calls the given validate-fn on value_buffer_, and returns
|
// Calls the given validate-fn on value_buffer_, and returns
|
||||||
// whatever it returns. But first casts validate_fn_proto to a
|
// whatever it returns. But first casts validate_fn_proto to a
|
||||||
|
@ -232,33 +223,14 @@ class FlagValue {
|
||||||
// (*validate_fn)(bool) for a bool flag).
|
// (*validate_fn)(bool) for a bool flag).
|
||||||
bool Validate(const char* flagname, ValidateFnProto validate_fn_proto) const;
|
bool Validate(const char* flagname, ValidateFnProto validate_fn_proto) const;
|
||||||
|
|
||||||
void* const value_buffer_; // points to the buffer holding our data
|
void* value_buffer_; // points to the buffer holding our data
|
||||||
const int8 type_; // how to interpret value_
|
int8 type_; // how to interpret value_
|
||||||
const bool owns_value_; // whether to free value on destruct
|
bool owns_value_; // whether to free value on destruct
|
||||||
|
|
||||||
FlagValue(const FlagValue&); // no copying!
|
FlagValue(const FlagValue&); // no copying!
|
||||||
void operator=(const FlagValue&);
|
void operator=(const FlagValue&);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Map the given C++ type to a value of the ValueType enum at compile time.
|
|
||||||
#define DEFINE_FLAG_TRAITS(type, value) \
|
|
||||||
template <> \
|
|
||||||
struct FlagValue::FlagValueTraits<type> { \
|
|
||||||
static const ValueType kValueType = value; \
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define full template specializations of the FlagValueTraits template
|
|
||||||
// for all supported flag types.
|
|
||||||
DEFINE_FLAG_TRAITS(bool, FV_BOOL);
|
|
||||||
DEFINE_FLAG_TRAITS(int32, FV_INT32);
|
|
||||||
DEFINE_FLAG_TRAITS(uint32, FV_UINT32);
|
|
||||||
DEFINE_FLAG_TRAITS(int64, FV_INT64);
|
|
||||||
DEFINE_FLAG_TRAITS(uint64, FV_UINT64);
|
|
||||||
DEFINE_FLAG_TRAITS(double, FV_DOUBLE);
|
|
||||||
DEFINE_FLAG_TRAITS(std::string, FV_STRING);
|
|
||||||
|
|
||||||
#undef DEFINE_FLAG_TRAITS
|
|
||||||
|
|
||||||
|
|
||||||
// This could be a templated method of FlagValue, but doing so adds to the
|
// This could be a templated method of FlagValue, but doing so adds to the
|
||||||
// size of the .o. Since there's no type-safety here anyway, macro is ok.
|
// size of the .o. Since there's no type-safety here anyway, macro is ok.
|
||||||
|
@ -266,12 +238,16 @@ DEFINE_FLAG_TRAITS(std::string, FV_STRING);
|
||||||
#define OTHER_VALUE_AS(fv, type) *reinterpret_cast<type*>(fv.value_buffer_)
|
#define OTHER_VALUE_AS(fv, type) *reinterpret_cast<type*>(fv.value_buffer_)
|
||||||
#define SET_VALUE_AS(type, value) VALUE_AS(type) = (value)
|
#define SET_VALUE_AS(type, value) VALUE_AS(type) = (value)
|
||||||
|
|
||||||
template <typename FlagType>
|
FlagValue::FlagValue(void* valbuf, const char* type,
|
||||||
FlagValue::FlagValue(FlagType* valbuf,
|
|
||||||
bool transfer_ownership_of_value)
|
bool transfer_ownership_of_value)
|
||||||
: value_buffer_(valbuf),
|
: value_buffer_(valbuf),
|
||||||
type_(FlagValueTraits<FlagType>::kValueType),
|
|
||||||
owns_value_(transfer_ownership_of_value) {
|
owns_value_(transfer_ownership_of_value) {
|
||||||
|
for (type_ = 0; type_ <= FV_MAX_INDEX; ++type_) {
|
||||||
|
if (!strcmp(type, TypeName())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(type_ <= FV_MAX_INDEX); // Unknown typename
|
||||||
}
|
}
|
||||||
|
|
||||||
FlagValue::~FlagValue() {
|
FlagValue::~FlagValue() {
|
||||||
|
@ -281,7 +257,6 @@ FlagValue::~FlagValue() {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case FV_BOOL: delete reinterpret_cast<bool*>(value_buffer_); break;
|
case FV_BOOL: delete reinterpret_cast<bool*>(value_buffer_); break;
|
||||||
case FV_INT32: delete reinterpret_cast<int32*>(value_buffer_); break;
|
case FV_INT32: delete reinterpret_cast<int32*>(value_buffer_); break;
|
||||||
case FV_UINT32: delete reinterpret_cast<uint32*>(value_buffer_); break;
|
|
||||||
case FV_INT64: delete reinterpret_cast<int64*>(value_buffer_); break;
|
case FV_INT64: delete reinterpret_cast<int64*>(value_buffer_); break;
|
||||||
case FV_UINT64: delete reinterpret_cast<uint64*>(value_buffer_); break;
|
case FV_UINT64: delete reinterpret_cast<uint64*>(value_buffer_); break;
|
||||||
case FV_DOUBLE: delete reinterpret_cast<double*>(value_buffer_); break;
|
case FV_DOUBLE: delete reinterpret_cast<double*>(value_buffer_); break;
|
||||||
|
@ -330,16 +305,6 @@ bool FlagValue::ParseFrom(const char* value) {
|
||||||
SET_VALUE_AS(int32, static_cast<int32>(r));
|
SET_VALUE_AS(int32, static_cast<int32>(r));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case FV_UINT32: {
|
|
||||||
while (*value == ' ') value++;
|
|
||||||
if (*value == '-') return false; // negative number
|
|
||||||
const uint64 r = strtou64(value, &end, base);
|
|
||||||
if (errno || end != value + strlen(value)) return false; // bad parse
|
|
||||||
if (static_cast<uint32>(r) != r) // worked, but number out of range
|
|
||||||
return false;
|
|
||||||
SET_VALUE_AS(uint32, static_cast<uint32>(r));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case FV_INT64: {
|
case FV_INT64: {
|
||||||
const int64 r = strto64(value, &end, base);
|
const int64 r = strto64(value, &end, base);
|
||||||
if (errno || end != value + strlen(value)) return false; // bad parse
|
if (errno || end != value + strlen(value)) return false; // bad parse
|
||||||
|
@ -375,9 +340,6 @@ string FlagValue::ToString() const {
|
||||||
case FV_INT32:
|
case FV_INT32:
|
||||||
snprintf(intbuf, sizeof(intbuf), "%" PRId32, VALUE_AS(int32));
|
snprintf(intbuf, sizeof(intbuf), "%" PRId32, VALUE_AS(int32));
|
||||||
return intbuf;
|
return intbuf;
|
||||||
case FV_UINT32:
|
|
||||||
snprintf(intbuf, sizeof(intbuf), "%" PRIu32, VALUE_AS(uint32));
|
|
||||||
return intbuf;
|
|
||||||
case FV_INT64:
|
case FV_INT64:
|
||||||
snprintf(intbuf, sizeof(intbuf), "%" PRId64, VALUE_AS(int64));
|
snprintf(intbuf, sizeof(intbuf), "%" PRId64, VALUE_AS(int64));
|
||||||
return intbuf;
|
return intbuf;
|
||||||
|
@ -404,9 +366,6 @@ bool FlagValue::Validate(const char* flagname,
|
||||||
case FV_INT32:
|
case FV_INT32:
|
||||||
return reinterpret_cast<bool (*)(const char*, int32)>(
|
return reinterpret_cast<bool (*)(const char*, int32)>(
|
||||||
validate_fn_proto)(flagname, VALUE_AS(int32));
|
validate_fn_proto)(flagname, VALUE_AS(int32));
|
||||||
case FV_UINT32:
|
|
||||||
return reinterpret_cast<bool (*)(const char*, uint32)>(
|
|
||||||
validate_fn_proto)(flagname, VALUE_AS(uint32));
|
|
||||||
case FV_INT64:
|
case FV_INT64:
|
||||||
return reinterpret_cast<bool (*)(const char*, int64)>(
|
return reinterpret_cast<bool (*)(const char*, int64)>(
|
||||||
validate_fn_proto)(flagname, VALUE_AS(int64));
|
validate_fn_proto)(flagname, VALUE_AS(int64));
|
||||||
|
@ -429,7 +388,6 @@ const char* FlagValue::TypeName() const {
|
||||||
static const char types[] =
|
static const char types[] =
|
||||||
"bool\0xx"
|
"bool\0xx"
|
||||||
"int32\0x"
|
"int32\0x"
|
||||||
"uint32\0"
|
|
||||||
"int64\0x"
|
"int64\0x"
|
||||||
"uint64\0"
|
"uint64\0"
|
||||||
"double\0"
|
"double\0"
|
||||||
|
@ -448,7 +406,6 @@ bool FlagValue::Equal(const FlagValue& x) const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case FV_BOOL: return VALUE_AS(bool) == OTHER_VALUE_AS(x, bool);
|
case FV_BOOL: return VALUE_AS(bool) == OTHER_VALUE_AS(x, bool);
|
||||||
case FV_INT32: return VALUE_AS(int32) == OTHER_VALUE_AS(x, int32);
|
case FV_INT32: return VALUE_AS(int32) == OTHER_VALUE_AS(x, int32);
|
||||||
case FV_UINT32: return VALUE_AS(uint32) == OTHER_VALUE_AS(x, uint32);
|
|
||||||
case FV_INT64: return VALUE_AS(int64) == OTHER_VALUE_AS(x, int64);
|
case FV_INT64: return VALUE_AS(int64) == OTHER_VALUE_AS(x, int64);
|
||||||
case FV_UINT64: return VALUE_AS(uint64) == OTHER_VALUE_AS(x, uint64);
|
case FV_UINT64: return VALUE_AS(uint64) == OTHER_VALUE_AS(x, uint64);
|
||||||
case FV_DOUBLE: return VALUE_AS(double) == OTHER_VALUE_AS(x, double);
|
case FV_DOUBLE: return VALUE_AS(double) == OTHER_VALUE_AS(x, double);
|
||||||
|
@ -458,14 +415,14 @@ bool FlagValue::Equal(const FlagValue& x) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
FlagValue* FlagValue::New() const {
|
FlagValue* FlagValue::New() const {
|
||||||
|
const char *type = TypeName();
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case FV_BOOL: return new FlagValue(new bool(false), true);
|
case FV_BOOL: return new FlagValue(new bool(false), type, true);
|
||||||
case FV_INT32: return new FlagValue(new int32(0), true);
|
case FV_INT32: return new FlagValue(new int32(0), type, true);
|
||||||
case FV_UINT32: return new FlagValue(new uint32(0), true);
|
case FV_INT64: return new FlagValue(new int64(0), type, true);
|
||||||
case FV_INT64: return new FlagValue(new int64(0), true);
|
case FV_UINT64: return new FlagValue(new uint64(0), type, true);
|
||||||
case FV_UINT64: return new FlagValue(new uint64(0), true);
|
case FV_DOUBLE: return new FlagValue(new double(0.0), type, true);
|
||||||
case FV_DOUBLE: return new FlagValue(new double(0.0), true);
|
case FV_STRING: return new FlagValue(new string, type, true);
|
||||||
case FV_STRING: return new FlagValue(new string, true);
|
|
||||||
default: assert(false); return NULL; // unknown type
|
default: assert(false); return NULL; // unknown type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -475,7 +432,6 @@ void FlagValue::CopyFrom(const FlagValue& x) {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case FV_BOOL: SET_VALUE_AS(bool, OTHER_VALUE_AS(x, bool)); break;
|
case FV_BOOL: SET_VALUE_AS(bool, OTHER_VALUE_AS(x, bool)); break;
|
||||||
case FV_INT32: SET_VALUE_AS(int32, OTHER_VALUE_AS(x, int32)); break;
|
case FV_INT32: SET_VALUE_AS(int32, OTHER_VALUE_AS(x, int32)); break;
|
||||||
case FV_UINT32: SET_VALUE_AS(uint32, OTHER_VALUE_AS(x, uint32)); break;
|
|
||||||
case FV_INT64: SET_VALUE_AS(int64, OTHER_VALUE_AS(x, int64)); break;
|
case FV_INT64: SET_VALUE_AS(int64, OTHER_VALUE_AS(x, int64)); break;
|
||||||
case FV_UINT64: SET_VALUE_AS(uint64, OTHER_VALUE_AS(x, uint64)); break;
|
case FV_UINT64: SET_VALUE_AS(uint64, OTHER_VALUE_AS(x, uint64)); break;
|
||||||
case FV_DOUBLE: SET_VALUE_AS(double, OTHER_VALUE_AS(x, double)); break;
|
case FV_DOUBLE: SET_VALUE_AS(double, OTHER_VALUE_AS(x, double)); break;
|
||||||
|
@ -484,6 +440,22 @@ void FlagValue::CopyFrom(const FlagValue& x) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FlagValue::ValueSize() const {
|
||||||
|
if (type_ > FV_MAX_INDEX) {
|
||||||
|
assert(false); // unknown type
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static const uint8 valuesize[] = {
|
||||||
|
sizeof(bool),
|
||||||
|
sizeof(int32),
|
||||||
|
sizeof(int64),
|
||||||
|
sizeof(uint64),
|
||||||
|
sizeof(double),
|
||||||
|
sizeof(string),
|
||||||
|
};
|
||||||
|
return valuesize[type_];
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// CommandLineFlag
|
// CommandLineFlag
|
||||||
// This represents a single flag, including its name, description,
|
// This represents a single flag, including its name, description,
|
||||||
|
@ -512,14 +484,11 @@ class CommandLineFlag {
|
||||||
ValidateFnProto validate_function() const { return validate_fn_proto_; }
|
ValidateFnProto validate_function() const { return validate_fn_proto_; }
|
||||||
const void* flag_ptr() const { return current_->value_buffer_; }
|
const void* flag_ptr() const { return current_->value_buffer_; }
|
||||||
|
|
||||||
FlagValue::ValueType Type() const { return defvalue_->Type(); }
|
|
||||||
|
|
||||||
void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result);
|
void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result);
|
||||||
|
|
||||||
// If validate_fn_proto_ is non-NULL, calls it on value, returns result.
|
// If validate_fn_proto_ is non-NULL, calls it on value, returns result.
|
||||||
bool Validate(const FlagValue& value) const;
|
bool Validate(const FlagValue& value) const;
|
||||||
bool ValidateCurrent() const { return Validate(*current_); }
|
bool ValidateCurrent() const { return Validate(*current_); }
|
||||||
bool Modified() const { return modified_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// for SetFlagLocked() and setting flags_by_ptr_
|
// for SetFlagLocked() and setting flags_by_ptr_
|
||||||
|
@ -562,14 +531,26 @@ CommandLineFlag::~CommandLineFlag() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CommandLineFlag::CleanFileName() const {
|
const char* CommandLineFlag::CleanFileName() const {
|
||||||
// This function has been used to strip off a common prefix from
|
// Compute top-level directory & file that this appears in
|
||||||
// flag source file names. Because flags can be defined in different
|
// search full path backwards.
|
||||||
// shared libraries, there may not be a single common prefix.
|
// Stop going backwards at kRootDir; and skip by the first slash.
|
||||||
// Further, this functionality hasn't been active for many years.
|
static const char kRootDir[] = ""; // can set this to root directory,
|
||||||
// Need a better way to produce more user friendly help output or
|
|
||||||
// "anonymize" file paths in help output, respectively.
|
if (sizeof(kRootDir)-1 == 0) // no prefix to strip
|
||||||
// Follow issue at: https://github.com/gflags/gflags/issues/86
|
return filename();
|
||||||
return filename();
|
|
||||||
|
const char* clean_name = filename() + strlen(filename()) - 1;
|
||||||
|
while ( clean_name > filename() ) {
|
||||||
|
if (*clean_name == PATH_SEPARATOR) {
|
||||||
|
if (strncmp(clean_name, kRootDir, sizeof(kRootDir)-1) == 0) {
|
||||||
|
clean_name += sizeof(kRootDir)-1; // past root-dir
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
--clean_name;
|
||||||
|
}
|
||||||
|
while ( *clean_name == PATH_SEPARATOR ) ++clean_name; // Skip any slashes
|
||||||
|
return clean_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandLineFlag::FillCommandLineFlagInfo(
|
void CommandLineFlag::FillCommandLineFlagInfo(
|
||||||
|
@ -680,7 +661,7 @@ class FlagRegistry {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class GFLAGS_NAMESPACE::FlagSaverImpl; // reads all the flags in order to copy them
|
friend class GFLAGS_NAMESPACE::FlagSaverImpl; // reads all the flags in order to copy them
|
||||||
friend class CommandLineFlagParser; // for ValidateUnmodifiedFlags
|
friend class CommandLineFlagParser; // for ValidateAllFlags
|
||||||
friend void GFLAGS_NAMESPACE::GetAllFlags(vector<CommandLineFlagInfo>*);
|
friend void GFLAGS_NAMESPACE::GetAllFlags(vector<CommandLineFlagInfo>*);
|
||||||
|
|
||||||
// The map from name to flag, for FindFlagLocked().
|
// The map from name to flag, for FindFlagLocked().
|
||||||
|
@ -696,6 +677,7 @@ class FlagRegistry {
|
||||||
static FlagRegistry* global_registry_; // a singleton registry
|
static FlagRegistry* global_registry_; // a singleton registry
|
||||||
|
|
||||||
Mutex lock_;
|
Mutex lock_;
|
||||||
|
static Mutex global_registry_lock_;
|
||||||
|
|
||||||
static void InitGlobalRegistry();
|
static void InitGlobalRegistry();
|
||||||
|
|
||||||
|
@ -740,12 +722,7 @@ void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
|
||||||
CommandLineFlag* FlagRegistry::FindFlagLocked(const char* name) {
|
CommandLineFlag* FlagRegistry::FindFlagLocked(const char* name) {
|
||||||
FlagConstIterator i = flags_.find(name);
|
FlagConstIterator i = flags_.find(name);
|
||||||
if (i == flags_.end()) {
|
if (i == flags_.end()) {
|
||||||
// If the name has dashes in it, try again after replacing with
|
return NULL;
|
||||||
// underscores.
|
|
||||||
if (strchr(name, '-') == NULL) return NULL;
|
|
||||||
string name_rep = name;
|
|
||||||
std::replace(name_rep.begin(), name_rep.end(), '-', '_');
|
|
||||||
return FindFlagLocked(name_rep.c_str());
|
|
||||||
} else {
|
} else {
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
|
@ -797,7 +774,7 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg,
|
||||||
kError, key->c_str());
|
kError, key->c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (flag->Type() != FlagValue::FV_BOOL) {
|
if (strcmp(flag->type_name(), "bool") != 0) {
|
||||||
// 'x' exists but is not boolean, so we're not in the exception case.
|
// 'x' exists but is not boolean, so we're not in the exception case.
|
||||||
*error_message = StringPrintf(
|
*error_message = StringPrintf(
|
||||||
"%sboolean value (%s) specified for %s command line flag\n",
|
"%sboolean value (%s) specified for %s command line flag\n",
|
||||||
|
@ -811,7 +788,7 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign a value if this is a boolean flag
|
// Assign a value if this is a boolean flag
|
||||||
if (*v == NULL && flag->Type() == FlagValue::FV_BOOL) {
|
if (*v == NULL && strcmp(flag->type_name(), "bool") == 0) {
|
||||||
*v = "1"; // the --nox case was already handled, so this is the --x case
|
*v = "1"; // the --nox case was already handled, so this is the --x case
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,10 +875,10 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag,
|
||||||
|
|
||||||
// Get the singleton FlagRegistry object
|
// Get the singleton FlagRegistry object
|
||||||
FlagRegistry* FlagRegistry::global_registry_ = NULL;
|
FlagRegistry* FlagRegistry::global_registry_ = NULL;
|
||||||
|
Mutex FlagRegistry::global_registry_lock_(Mutex::LINKER_INITIALIZED);
|
||||||
|
|
||||||
FlagRegistry* FlagRegistry::GlobalRegistry() {
|
FlagRegistry* FlagRegistry::GlobalRegistry() {
|
||||||
static Mutex lock(Mutex::LINKER_INITIALIZED);
|
MutexLock acquire_lock(&global_registry_lock_);
|
||||||
MutexLock acquire_lock(&lock);
|
|
||||||
if (!global_registry_) {
|
if (!global_registry_) {
|
||||||
global_registry_ = new FlagRegistry;
|
global_registry_ = new FlagRegistry;
|
||||||
}
|
}
|
||||||
|
@ -940,9 +917,8 @@ class CommandLineFlagParser {
|
||||||
// In gflags_reporting.cc:HandleCommandLineHelpFlags().
|
// In gflags_reporting.cc:HandleCommandLineHelpFlags().
|
||||||
|
|
||||||
// Stage 3: validate all the commandline flags that have validators
|
// Stage 3: validate all the commandline flags that have validators
|
||||||
// registered and were not set/modified by ParseNewCommandLineFlags.
|
// registered.
|
||||||
void ValidateFlags(bool all);
|
void ValidateAllFlags();
|
||||||
void ValidateUnmodifiedFlags();
|
|
||||||
|
|
||||||
// Stage 4: report any errors and return true if any were found.
|
// Stage 4: report any errors and return true if any were found.
|
||||||
bool ReportErrors();
|
bool ReportErrors();
|
||||||
|
@ -1029,6 +1005,9 @@ static string ReadFileIntoString(const char* filename) {
|
||||||
|
|
||||||
uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
|
uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
|
||||||
bool remove_flags) {
|
bool remove_flags) {
|
||||||
|
const char *program_name = strrchr((*argv)[0], PATH_SEPARATOR); // nix path
|
||||||
|
program_name = (program_name == NULL ? (*argv)[0] : program_name+1);
|
||||||
|
|
||||||
int first_nonopt = *argc; // for non-options moved to the end
|
int first_nonopt = *argc; // for non-options moved to the end
|
||||||
|
|
||||||
registry_->Lock();
|
registry_->Lock();
|
||||||
|
@ -1036,15 +1015,17 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
|
||||||
char* arg = (*argv)[i];
|
char* arg = (*argv)[i];
|
||||||
|
|
||||||
// Like getopt(), we permute non-option flags to be at the end.
|
// Like getopt(), we permute non-option flags to be at the end.
|
||||||
if (arg[0] != '-' || arg[1] == '\0') { // must be a program argument: "-" is an argument, not a flag
|
if (arg[0] != '-' || // must be a program argument
|
||||||
|
(arg[0] == '-' && arg[1] == '\0')) { // "-" is an argument, not a flag
|
||||||
memmove((*argv) + i, (*argv) + i+1, (*argc - (i+1)) * sizeof((*argv)[i]));
|
memmove((*argv) + i, (*argv) + i+1, (*argc - (i+1)) * sizeof((*argv)[i]));
|
||||||
(*argv)[*argc-1] = arg; // we go last
|
(*argv)[*argc-1] = arg; // we go last
|
||||||
first_nonopt--; // we've been pushed onto the stack
|
first_nonopt--; // we've been pushed onto the stack
|
||||||
i--; // to undo the i++ in the loop
|
i--; // to undo the i++ in the loop
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
arg++; // skip leading '-'
|
|
||||||
if (arg[0] == '-') arg++; // or leading '--'
|
if (arg[0] == '-') arg++; // allow leading '-'
|
||||||
|
if (arg[0] == '-') arg++; // or leading '--'
|
||||||
|
|
||||||
// -- alone means what it does for GNU: stop options parsing
|
// -- alone means what it does for GNU: stop options parsing
|
||||||
if (*arg == '\0') {
|
if (*arg == '\0') {
|
||||||
|
@ -1066,7 +1047,7 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
|
||||||
|
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
// Boolean options are always assigned a value by SplitArgumentLocked()
|
// Boolean options are always assigned a value by SplitArgumentLocked()
|
||||||
assert(flag->Type() != FlagValue::FV_BOOL);
|
assert(strcmp(flag->type_name(), "bool") != 0);
|
||||||
if (i+1 >= first_nonopt) {
|
if (i+1 >= first_nonopt) {
|
||||||
// This flag needs a value, but there is nothing available
|
// This flag needs a value, but there is nothing available
|
||||||
error_flags_[key] = (string(kError) + "flag '" + (*argv)[i] + "'"
|
error_flags_[key] = (string(kError) + "flag '" + (*argv)[i] + "'"
|
||||||
|
@ -1091,7 +1072,7 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
|
||||||
// "-lat -30.5" would trigger the warning. The common cases we
|
// "-lat -30.5" would trigger the warning. The common cases we
|
||||||
// want to solve talk about true and false as values.
|
// want to solve talk about true and false as values.
|
||||||
if (value[0] == '-'
|
if (value[0] == '-'
|
||||||
&& flag->Type() == FlagValue::FV_STRING
|
&& strcmp(flag->type_name(), "string") == 0
|
||||||
&& (strstr(flag->help(), "true")
|
&& (strstr(flag->help(), "true")
|
||||||
|| strstr(flag->help(), "false"))) {
|
|| strstr(flag->help(), "false"))) {
|
||||||
LOG(WARNING) << "Did you really mean to set flag '"
|
LOG(WARNING) << "Did you really mean to set flag '"
|
||||||
|
@ -1156,8 +1137,8 @@ string CommandLineFlagParser::ProcessFromenvLocked(const string& flagval,
|
||||||
}
|
}
|
||||||
|
|
||||||
const string envname = string("FLAGS_") + string(flagname);
|
const string envname = string("FLAGS_") + string(flagname);
|
||||||
string envval;
|
string envval;
|
||||||
if (!SafeGetEnv(envname.c_str(), envval)) {
|
if (!SafeGetEnv(envname.c_str(), envval)) {
|
||||||
if (errors_are_fatal) {
|
if (errors_are_fatal) {
|
||||||
error_flags_[flagname] = (string(kError) + envname +
|
error_flags_[flagname] = (string(kError) + envname +
|
||||||
" not found in environment\n");
|
" not found in environment\n");
|
||||||
|
@ -1203,31 +1184,23 @@ string CommandLineFlagParser::ProcessSingleOptionLocked(
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandLineFlagParser::ValidateFlags(bool all) {
|
void CommandLineFlagParser::ValidateAllFlags() {
|
||||||
FlagRegistryLock frl(registry_);
|
FlagRegistryLock frl(registry_);
|
||||||
for (FlagRegistry::FlagConstIterator i = registry_->flags_.begin();
|
for (FlagRegistry::FlagConstIterator i = registry_->flags_.begin();
|
||||||
i != registry_->flags_.end(); ++i) {
|
i != registry_->flags_.end(); ++i) {
|
||||||
if ((all || !i->second->Modified()) && !i->second->ValidateCurrent()) {
|
if (!i->second->ValidateCurrent()) {
|
||||||
// only set a message if one isn't already there. (If there's
|
// only set a message if one isn't already there. (If there's
|
||||||
// an error message, our job is done, even if it's not exactly
|
// an error message, our job is done, even if it's not exactly
|
||||||
// the same error.)
|
// the same error.)
|
||||||
if (error_flags_[i->second->name()].empty()) {
|
if (error_flags_[i->second->name()].empty())
|
||||||
error_flags_[i->second->name()] =
|
error_flags_[i->second->name()] =
|
||||||
string(kError) + "--" + i->second->name() +
|
string(kError) + "--" + i->second->name() +
|
||||||
" must be set on the commandline";
|
" must be set on the commandline"
|
||||||
if (!i->second->Modified()) {
|
" (default value fails validation)\n";
|
||||||
error_flags_[i->second->name()] += " (default value fails validation)";
|
|
||||||
}
|
|
||||||
error_flags_[i->second->name()] += "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandLineFlagParser::ValidateUnmodifiedFlags() {
|
|
||||||
ValidateFlags(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CommandLineFlagParser::ReportErrors() {
|
bool CommandLineFlagParser::ReportErrors() {
|
||||||
// error_flags_ indicates errors we saw while parsing.
|
// error_flags_ indicates errors we saw while parsing.
|
||||||
// But we ignore undefined-names if ok'ed by --undef_ok
|
// But we ignore undefined-names if ok'ed by --undef_ok
|
||||||
|
@ -1279,11 +1252,7 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked(
|
||||||
for (; line_end; flagfile_contents = line_end + 1) {
|
for (; line_end; flagfile_contents = line_end + 1) {
|
||||||
while (*flagfile_contents && isspace(*flagfile_contents))
|
while (*flagfile_contents && isspace(*flagfile_contents))
|
||||||
++flagfile_contents;
|
++flagfile_contents;
|
||||||
// Windows uses "\r\n"
|
line_end = strchr(flagfile_contents, '\n');
|
||||||
line_end = strchr(flagfile_contents, '\r');
|
|
||||||
if (line_end == NULL)
|
|
||||||
line_end = strchr(flagfile_contents, '\n');
|
|
||||||
|
|
||||||
size_t len = line_end ? line_end - flagfile_contents
|
size_t len = line_end ? line_end - flagfile_contents
|
||||||
: strlen(flagfile_contents);
|
: strlen(flagfile_contents);
|
||||||
string line(flagfile_contents, len);
|
string line(flagfile_contents, len);
|
||||||
|
@ -1341,8 +1310,8 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked(
|
||||||
|| fnmatch(glob.c_str(), ProgramInvocationName(), FNM_PATHNAME) == 0
|
|| fnmatch(glob.c_str(), ProgramInvocationName(), FNM_PATHNAME) == 0
|
||||||
|| fnmatch(glob.c_str(), ProgramInvocationShortName(), FNM_PATHNAME) == 0
|
|| fnmatch(glob.c_str(), ProgramInvocationShortName(), FNM_PATHNAME) == 0
|
||||||
#elif defined(HAVE_SHLWAPI_H)
|
#elif defined(HAVE_SHLWAPI_H)
|
||||||
|| PathMatchSpecA(glob.c_str(), ProgramInvocationName())
|
|| PathMatchSpec(glob.c_str(), ProgramInvocationName())
|
||||||
|| PathMatchSpecA(glob.c_str(), ProgramInvocationShortName())
|
|| PathMatchSpec(glob.c_str(), ProgramInvocationShortName())
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
flags_are_relevant = true;
|
flags_are_relevant = true;
|
||||||
|
@ -1363,14 +1332,14 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked(
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T GetFromEnv(const char *varname, T dflt) {
|
T GetFromEnv(const char *varname, const char* type, T dflt) {
|
||||||
std::string valstr;
|
std::string valstr;
|
||||||
if (SafeGetEnv(varname, valstr)) {
|
if (SafeGetEnv(varname, valstr)) {
|
||||||
FlagValue ifv(new T, true);
|
FlagValue ifv(new T, type, true);
|
||||||
if (!ifv.ParseFrom(valstr.c_str())) {
|
if (!ifv.ParseFrom(valstr.c_str())) {
|
||||||
ReportError(DIE, "ERROR: error parsing env variable '%s' with value '%s'\n",
|
ReportError(DIE, "ERROR: error parsing env variable '%s' with value '%s'\n",
|
||||||
varname, valstr.c_str());
|
varname, valstr.c_str());
|
||||||
}
|
}
|
||||||
return OTHER_VALUE_AS(ifv, T);
|
return OTHER_VALUE_AS(ifv, T);
|
||||||
} else return dflt;
|
} else return dflt;
|
||||||
}
|
}
|
||||||
|
@ -1417,48 +1386,22 @@ bool AddFlagValidator(const void* flag_ptr, ValidateFnProto validate_fn_proto) {
|
||||||
// values in a global destructor.
|
// values in a global destructor.
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
namespace {
|
FlagRegisterer::FlagRegisterer(const char* name, const char* type,
|
||||||
void RegisterCommandLineFlag(const char* name,
|
const char* help, const char* filename,
|
||||||
const char* help,
|
void* current_storage, void* defvalue_storage) {
|
||||||
const char* filename,
|
|
||||||
FlagValue* current,
|
|
||||||
FlagValue* defvalue) {
|
|
||||||
if (help == NULL)
|
if (help == NULL)
|
||||||
help = "";
|
help = "";
|
||||||
|
// FlagValue expects the type-name to not include any namespace
|
||||||
|
// components, so we get rid of those, if any.
|
||||||
|
if (strchr(type, ':'))
|
||||||
|
type = strrchr(type, ':') + 1;
|
||||||
|
FlagValue* current = new FlagValue(current_storage, type, false);
|
||||||
|
FlagValue* defvalue = new FlagValue(defvalue_storage, type, false);
|
||||||
// Importantly, flag_ will never be deleted, so storage is always good.
|
// Importantly, flag_ will never be deleted, so storage is always good.
|
||||||
CommandLineFlag* flag =
|
CommandLineFlag* flag = new CommandLineFlag(name, help, filename,
|
||||||
new CommandLineFlag(name, help, filename, current, defvalue);
|
current, defvalue);
|
||||||
FlagRegistry::GlobalRegistry()->RegisterFlag(flag); // default registry
|
FlagRegistry::GlobalRegistry()->RegisterFlag(flag); // default registry
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FlagType>
|
|
||||||
FlagRegisterer::FlagRegisterer(const char* name,
|
|
||||||
const char* help,
|
|
||||||
const char* filename,
|
|
||||||
FlagType* current_storage,
|
|
||||||
FlagType* defvalue_storage) {
|
|
||||||
FlagValue* const current = new FlagValue(current_storage, false);
|
|
||||||
FlagValue* const defvalue = new FlagValue(defvalue_storage, false);
|
|
||||||
RegisterCommandLineFlag(name, help, filename, current, defvalue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force compiler to generate code for the given template specialization.
|
|
||||||
#define INSTANTIATE_FLAG_REGISTERER_CTOR(type) \
|
|
||||||
template GFLAGS_DLL_DECL FlagRegisterer::FlagRegisterer( \
|
|
||||||
const char* name, const char* help, const char* filename, \
|
|
||||||
type* current_storage, type* defvalue_storage)
|
|
||||||
|
|
||||||
// Do this for all supported flag types.
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(bool);
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(int32);
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(uint32);
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(int64);
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(uint64);
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(double);
|
|
||||||
INSTANTIATE_FLAG_REGISTERER_CTOR(std::string);
|
|
||||||
|
|
||||||
#undef INSTANTIATE_FLAG_REGISTERER_CTOR
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// GetAllFlags()
|
// GetAllFlags()
|
||||||
|
@ -1508,58 +1451,65 @@ void GetAllFlags(vector<CommandLineFlagInfo>* OUTPUT) {
|
||||||
|
|
||||||
// These values are not protected by a Mutex because they are normally
|
// These values are not protected by a Mutex because they are normally
|
||||||
// set only once during program startup.
|
// set only once during program startup.
|
||||||
static string argv0("UNKNOWN"); // just the program name
|
static const char* argv0 = "UNKNOWN"; // just the program name
|
||||||
static string cmdline; // the entire command-line
|
static const char* cmdline = ""; // the entire command-line
|
||||||
static string program_usage;
|
|
||||||
static vector<string> argvs;
|
static vector<string> argvs;
|
||||||
static uint32 argv_sum = 0;
|
static uint32 argv_sum = 0;
|
||||||
|
static const char* program_usage = NULL;
|
||||||
|
|
||||||
void SetArgv(int argc, const char** argv) {
|
void SetArgv(int argc, const char** argv) {
|
||||||
static bool called_set_argv = false;
|
static bool called_set_argv = false;
|
||||||
if (called_set_argv) return;
|
if (called_set_argv) // we already have an argv for you
|
||||||
|
return;
|
||||||
|
|
||||||
called_set_argv = true;
|
called_set_argv = true;
|
||||||
|
|
||||||
assert(argc > 0); // every program has at least a name
|
assert(argc > 0); // every program has at least a progname
|
||||||
argv0 = argv[0];
|
argv0 = strdup(argv[0]); // small memory leak, but fn only called once
|
||||||
|
assert(argv0);
|
||||||
|
|
||||||
cmdline.clear();
|
string cmdline_string; // easier than doing strcats
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
if (i != 0) cmdline += " ";
|
if (i != 0) {
|
||||||
cmdline += argv[i];
|
cmdline_string += " ";
|
||||||
|
}
|
||||||
|
cmdline_string += argv[i];
|
||||||
argvs.push_back(argv[i]);
|
argvs.push_back(argv[i]);
|
||||||
}
|
}
|
||||||
|
cmdline = strdup(cmdline_string.c_str()); // another small memory leak
|
||||||
|
assert(cmdline);
|
||||||
|
|
||||||
// Compute a simple sum of all the chars in argv
|
// Compute a simple sum of all the chars in argv
|
||||||
argv_sum = 0;
|
for (const char* c = cmdline; *c; c++)
|
||||||
for (string::const_iterator c = cmdline.begin(); c != cmdline.end(); ++c) {
|
|
||||||
argv_sum += *c;
|
argv_sum += *c;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector<string>& GetArgvs() { return argvs; }
|
const vector<string>& GetArgvs() { return argvs; }
|
||||||
const char* GetArgv() { return cmdline.c_str(); }
|
const char* GetArgv() { return cmdline; }
|
||||||
const char* GetArgv0() { return argv0.c_str(); }
|
const char* GetArgv0() { return argv0; }
|
||||||
uint32 GetArgvSum() { return argv_sum; }
|
uint32 GetArgvSum() { return argv_sum; }
|
||||||
const char* ProgramInvocationName() { // like the GNU libc fn
|
const char* ProgramInvocationName() { // like the GNU libc fn
|
||||||
return GetArgv0();
|
return GetArgv0();
|
||||||
}
|
}
|
||||||
const char* ProgramInvocationShortName() { // like the GNU libc fn
|
const char* ProgramInvocationShortName() { // like the GNU libc fn
|
||||||
size_t pos = argv0.rfind('/');
|
const char* slash = strrchr(argv0, '/');
|
||||||
#ifdef OS_WINDOWS
|
#ifdef OS_WINDOWS
|
||||||
if (pos == string::npos) pos = argv0.rfind('\\');
|
if (!slash) slash = strrchr(argv0, '\\');
|
||||||
#endif
|
#endif
|
||||||
return (pos == string::npos ? argv0.c_str() : (argv0.c_str() + pos + 1));
|
return slash ? slash + 1 : argv0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetUsageMessage(const string& usage) {
|
void SetUsageMessage(const string& usage) {
|
||||||
program_usage = usage;
|
if (program_usage != NULL)
|
||||||
|
ReportError(DIE, "ERROR: SetUsageMessage() called twice\n");
|
||||||
|
program_usage = strdup(usage.c_str()); // small memory leak
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ProgramUsage() {
|
const char* ProgramUsage() {
|
||||||
if (program_usage.empty()) {
|
if (program_usage) {
|
||||||
return "Warning: SetUsageMessage() never called";
|
return program_usage;
|
||||||
}
|
}
|
||||||
return program_usage.c_str();
|
return "Warning: SetUsageMessage() never called";
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
@ -1567,14 +1517,16 @@ const char* ProgramUsage() {
|
||||||
// VersionString()
|
// VersionString()
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
static string version_string;
|
static const char* version_string = NULL;
|
||||||
|
|
||||||
void SetVersionString(const string& version) {
|
void SetVersionString(const string& version) {
|
||||||
version_string = version;
|
if (version_string != NULL)
|
||||||
|
ReportError(DIE, "ERROR: SetVersionString() called twice\n");
|
||||||
|
version_string = strdup(version.c_str()); // small memory leak
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* VersionString() {
|
const char* VersionString() {
|
||||||
return version_string.c_str();
|
return version_string ? version_string : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1835,7 +1787,6 @@ bool ReadFromFlagsFile(const string& filename, const char* prog_name,
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// BoolFromEnv()
|
// BoolFromEnv()
|
||||||
// Int32FromEnv()
|
// Int32FromEnv()
|
||||||
// Uint32FromEnv()
|
|
||||||
// Int64FromEnv()
|
// Int64FromEnv()
|
||||||
// Uint64FromEnv()
|
// Uint64FromEnv()
|
||||||
// DoubleFromEnv()
|
// DoubleFromEnv()
|
||||||
|
@ -1847,22 +1798,19 @@ bool ReadFromFlagsFile(const string& filename, const char* prog_name,
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
bool BoolFromEnv(const char *v, bool dflt) {
|
bool BoolFromEnv(const char *v, bool dflt) {
|
||||||
return GetFromEnv(v, dflt);
|
return GetFromEnv(v, "bool", dflt);
|
||||||
}
|
}
|
||||||
int32 Int32FromEnv(const char *v, int32 dflt) {
|
int32 Int32FromEnv(const char *v, int32 dflt) {
|
||||||
return GetFromEnv(v, dflt);
|
return GetFromEnv(v, "int32", dflt);
|
||||||
}
|
|
||||||
uint32 Uint32FromEnv(const char *v, uint32 dflt) {
|
|
||||||
return GetFromEnv(v, dflt);
|
|
||||||
}
|
}
|
||||||
int64 Int64FromEnv(const char *v, int64 dflt) {
|
int64 Int64FromEnv(const char *v, int64 dflt) {
|
||||||
return GetFromEnv(v, dflt);
|
return GetFromEnv(v, "int64", dflt);
|
||||||
}
|
}
|
||||||
uint64 Uint64FromEnv(const char *v, uint64 dflt) {
|
uint64 Uint64FromEnv(const char *v, uint64 dflt) {
|
||||||
return GetFromEnv(v, dflt);
|
return GetFromEnv(v, "uint64", dflt);
|
||||||
}
|
}
|
||||||
double DoubleFromEnv(const char *v, double dflt) {
|
double DoubleFromEnv(const char *v, double dflt) {
|
||||||
return GetFromEnv(v, dflt);
|
return GetFromEnv(v, "double", dflt);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -1898,10 +1846,6 @@ bool RegisterFlagValidator(const int32* flag,
|
||||||
bool (*validate_fn)(const char*, int32)) {
|
bool (*validate_fn)(const char*, int32)) {
|
||||||
return AddFlagValidator(flag, reinterpret_cast<ValidateFnProto>(validate_fn));
|
return AddFlagValidator(flag, reinterpret_cast<ValidateFnProto>(validate_fn));
|
||||||
}
|
}
|
||||||
bool RegisterFlagValidator(const uint32* flag,
|
|
||||||
bool (*validate_fn)(const char*, uint32)) {
|
|
||||||
return AddFlagValidator(flag, reinterpret_cast<ValidateFnProto>(validate_fn));
|
|
||||||
}
|
|
||||||
bool RegisterFlagValidator(const int64* flag,
|
bool RegisterFlagValidator(const int64* flag,
|
||||||
bool (*validate_fn)(const char*, int64)) {
|
bool (*validate_fn)(const char*, int64)) {
|
||||||
return AddFlagValidator(flag, reinterpret_cast<ValidateFnProto>(validate_fn));
|
return AddFlagValidator(flag, reinterpret_cast<ValidateFnProto>(validate_fn));
|
||||||
|
@ -1957,7 +1901,7 @@ static uint32 ParseCommandLineFlagsInternal(int* argc, char*** argv,
|
||||||
HandleCommandLineHelpFlags(); // may cause us to exit on --help, etc.
|
HandleCommandLineHelpFlags(); // may cause us to exit on --help, etc.
|
||||||
|
|
||||||
// See if any of the unset flags fail their validation checks
|
// See if any of the unset flags fail their validation checks
|
||||||
parser.ValidateUnmodifiedFlags();
|
parser.ValidateAllFlags();
|
||||||
|
|
||||||
if (parser.ReportErrors()) // may cause us to exit on illegal flags
|
if (parser.ReportErrors()) // may cause us to exit on illegal flags
|
||||||
gflags_exitfunc(1);
|
gflags_exitfunc(1);
|
||||||
|
|
|
@ -81,12 +81,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gflags/gflags_declare.h" // IWYU pragma: export
|
#include "gflags_declare.h" // IWYU pragma: export
|
||||||
|
|
||||||
|
|
||||||
// We always want to export variables defined in user code
|
// We always want to export variables defined in user code
|
||||||
#ifndef GFLAGS_DLL_DEFINE_FLAG
|
#ifndef GFLAGS_DLL_DEFINE_FLAG
|
||||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
# ifdef _MSC_VER
|
||||||
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
|
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
|
||||||
# else
|
# else
|
||||||
# define GFLAGS_DLL_DEFINE_FLAG
|
# define GFLAGS_DLL_DEFINE_FLAG
|
||||||
|
@ -94,7 +94,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace GFLAGS_NAMESPACE {
|
namespace @GFLAGS_NAMESPACE@ {
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
@ -128,7 +128,6 @@ namespace GFLAGS_NAMESPACE {
|
||||||
// validator is already registered for this flag).
|
// validator is already registered for this flag).
|
||||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const bool* flag, bool (*validate_fn)(const char*, bool));
|
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const bool* flag, bool (*validate_fn)(const char*, bool));
|
||||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int32* flag, bool (*validate_fn)(const char*, int32));
|
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int32* flag, bool (*validate_fn)(const char*, int32));
|
||||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint32* flag, bool (*validate_fn)(const char*, uint32));
|
|
||||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int64* flag, bool (*validate_fn)(const char*, int64));
|
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int64* flag, bool (*validate_fn)(const char*, int64));
|
||||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint64* flag, bool (*validate_fn)(const char*, uint64));
|
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint64* flag, bool (*validate_fn)(const char*, uint64));
|
||||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const double* flag, bool (*validate_fn)(const char*, double));
|
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const double* flag, bool (*validate_fn)(const char*, double));
|
||||||
|
@ -137,7 +136,7 @@ extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const std::string* flag, bool
|
||||||
// Convenience macro for the registration of a flag validator
|
// Convenience macro for the registration of a flag validator
|
||||||
#define DEFINE_validator(name, validator) \
|
#define DEFINE_validator(name, validator) \
|
||||||
static const bool name##_validator_registered = \
|
static const bool name##_validator_registered = \
|
||||||
GFLAGS_NAMESPACE::RegisterFlagValidator(&FLAGS_##name, validator)
|
@GFLAGS_NAMESPACE@::RegisterFlagValidator(&FLAGS_##name, validator)
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
@ -223,7 +222,7 @@ extern GFLAGS_DLL_DECL bool GetCommandLineFlagInfo(const char* name, CommandLine
|
||||||
// if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
|
// if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
|
||||||
extern GFLAGS_DLL_DECL CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
|
extern GFLAGS_DLL_DECL CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
|
||||||
|
|
||||||
enum FlagSettingMode {
|
enum GFLAGS_DLL_DECL FlagSettingMode {
|
||||||
// update the flag's value (can call this multiple times).
|
// update the flag's value (can call this multiple times).
|
||||||
SET_FLAGS_VALUE,
|
SET_FLAGS_VALUE,
|
||||||
// update the flag's value, but *only if* it has not yet been updated
|
// update the flag's value, but *only if* it has not yet been updated
|
||||||
|
@ -314,7 +313,6 @@ extern GFLAGS_DLL_DECL bool ReadFromFlagsFile(const std::string& filename, const
|
||||||
|
|
||||||
extern GFLAGS_DLL_DECL bool BoolFromEnv(const char *varname, bool defval);
|
extern GFLAGS_DLL_DECL bool BoolFromEnv(const char *varname, bool defval);
|
||||||
extern GFLAGS_DLL_DECL int32 Int32FromEnv(const char *varname, int32 defval);
|
extern GFLAGS_DLL_DECL int32 Int32FromEnv(const char *varname, int32 defval);
|
||||||
extern GFLAGS_DLL_DECL uint32 Uint32FromEnv(const char *varname, uint32 defval);
|
|
||||||
extern GFLAGS_DLL_DECL int64 Int64FromEnv(const char *varname, int64 defval);
|
extern GFLAGS_DLL_DECL int64 Int64FromEnv(const char *varname, int64 defval);
|
||||||
extern GFLAGS_DLL_DECL uint64 Uint64FromEnv(const char *varname, uint64 defval);
|
extern GFLAGS_DLL_DECL uint64 Uint64FromEnv(const char *varname, uint64 defval);
|
||||||
extern GFLAGS_DLL_DECL double DoubleFromEnv(const char *varname, double defval);
|
extern GFLAGS_DLL_DECL double DoubleFromEnv(const char *varname, double defval);
|
||||||
|
@ -431,37 +429,11 @@ extern GFLAGS_DLL_DECL void ShutDownCommandLineFlags();
|
||||||
|
|
||||||
class GFLAGS_DLL_DECL FlagRegisterer {
|
class GFLAGS_DLL_DECL FlagRegisterer {
|
||||||
public:
|
public:
|
||||||
// We instantiate this template ctor for all supported types,
|
FlagRegisterer(const char* name, const char* type,
|
||||||
// so it is possible to place implementation of the FlagRegisterer ctor in
|
|
||||||
// .cc file.
|
|
||||||
// Calling this constructor with unsupported type will produce linker error.
|
|
||||||
template <typename FlagType>
|
|
||||||
FlagRegisterer(const char* name,
|
|
||||||
const char* help, const char* filename,
|
const char* help, const char* filename,
|
||||||
FlagType* current_storage, FlagType* defvalue_storage);
|
void* current_storage, void* defvalue_storage);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Force compiler to not generate code for the given template specialization.
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1800 // Visual Studio 2013 version 12.0
|
|
||||||
#define GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(type)
|
|
||||||
#else
|
|
||||||
#define GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(type) \
|
|
||||||
extern template GFLAGS_DLL_DECL FlagRegisterer::FlagRegisterer( \
|
|
||||||
const char* name, const char* help, const char* filename, \
|
|
||||||
type* current_storage, type* defvalue_storage)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Do this for all supported flag types.
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(bool);
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(int32);
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(uint32);
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(int64);
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(uint64);
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(double);
|
|
||||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(std::string);
|
|
||||||
|
|
||||||
#undef GFLAGS_DECLARE_FLAG_REGISTERER_CTOR
|
|
||||||
|
|
||||||
// If your application #defines STRIP_FLAG_HELP to a non-zero value
|
// If your application #defines STRIP_FLAG_HELP to a non-zero value
|
||||||
// before #including this file, we remove the help message from the
|
// before #including this file, we remove the help message from the
|
||||||
// binary file. This can reduce the size of the resulting binary
|
// binary file. This can reduce the size of the resulting binary
|
||||||
|
@ -470,7 +442,7 @@ GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(std::string);
|
||||||
extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
|
extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
|
||||||
|
|
||||||
|
|
||||||
} // namespace GFLAGS_NAMESPACE
|
} // namespace @GFLAGS_NAMESPACE@
|
||||||
|
|
||||||
|
|
||||||
#ifndef SWIG // In swig, ignore the main flag declarations
|
#ifndef SWIG // In swig, ignore the main flag declarations
|
||||||
|
@ -478,7 +450,7 @@ extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
|
||||||
#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0
|
#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0
|
||||||
// Need this construct to avoid the 'defined but not used' warning.
|
// Need this construct to avoid the 'defined but not used' warning.
|
||||||
#define MAYBE_STRIPPED_HELP(txt) \
|
#define MAYBE_STRIPPED_HELP(txt) \
|
||||||
(false ? (txt) : GFLAGS_NAMESPACE::kStrippedFlagHelp)
|
(false ? (txt) : @GFLAGS_NAMESPACE@::kStrippedFlagHelp)
|
||||||
#else
|
#else
|
||||||
#define MAYBE_STRIPPED_HELP(txt) txt
|
#define MAYBE_STRIPPED_HELP(txt) txt
|
||||||
#endif
|
#endif
|
||||||
|
@ -499,9 +471,9 @@ extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
|
||||||
static const type FLAGS_nono##name = value; \
|
static const type FLAGS_nono##name = value; \
|
||||||
/* We always want to export defined variables, dll or no */ \
|
/* We always want to export defined variables, dll or no */ \
|
||||||
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
|
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
|
||||||
static type FLAGS_no##name = FLAGS_nono##name; \
|
type FLAGS_no##name = FLAGS_nono##name; \
|
||||||
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
|
static @GFLAGS_NAMESPACE@::FlagRegisterer o_##name( \
|
||||||
#name, MAYBE_STRIPPED_HELP(help), __FILE__, \
|
#name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \
|
||||||
&FLAGS_##name, &FLAGS_no##name); \
|
&FLAGS_##name, &FLAGS_no##name); \
|
||||||
} \
|
} \
|
||||||
using fL##shorttype::FLAGS_##name
|
using fL##shorttype::FLAGS_##name
|
||||||
|
@ -528,24 +500,20 @@ GFLAGS_DLL_DECL bool IsBoolFlag(bool from);
|
||||||
#define DEFINE_bool(name, val, txt) \
|
#define DEFINE_bool(name, val, txt) \
|
||||||
namespace fLB { \
|
namespace fLB { \
|
||||||
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \
|
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \
|
||||||
(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double))? 1: -1]; \
|
(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \
|
||||||
} \
|
} \
|
||||||
DEFINE_VARIABLE(bool, B, name, val, txt)
|
DEFINE_VARIABLE(bool, B, name, val, txt)
|
||||||
|
|
||||||
#define DEFINE_int32(name, val, txt) \
|
#define DEFINE_int32(name, val, txt) \
|
||||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::int32, I, \
|
DEFINE_VARIABLE(@GFLAGS_NAMESPACE@::int32, I, \
|
||||||
name, val, txt)
|
|
||||||
|
|
||||||
#define DEFINE_uint32(name,val, txt) \
|
|
||||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint32, U, \
|
|
||||||
name, val, txt)
|
name, val, txt)
|
||||||
|
|
||||||
#define DEFINE_int64(name, val, txt) \
|
#define DEFINE_int64(name, val, txt) \
|
||||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, \
|
DEFINE_VARIABLE(@GFLAGS_NAMESPACE@::int64, I64, \
|
||||||
name, val, txt)
|
name, val, txt)
|
||||||
|
|
||||||
#define DEFINE_uint64(name,val, txt) \
|
#define DEFINE_uint64(name,val, txt) \
|
||||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, \
|
DEFINE_VARIABLE(@GFLAGS_NAMESPACE@::uint64, U64, \
|
||||||
name, val, txt)
|
name, val, txt)
|
||||||
|
|
||||||
#define DEFINE_double(name, val, txt) \
|
#define DEFINE_double(name, val, txt) \
|
||||||
|
@ -570,26 +538,6 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot,
|
||||||
}
|
}
|
||||||
inline clstring* dont_pass0toDEFINE_string(char *stringspot,
|
inline clstring* dont_pass0toDEFINE_string(char *stringspot,
|
||||||
int value);
|
int value);
|
||||||
|
|
||||||
// Auxiliary class used to explicitly call destructor of string objects
|
|
||||||
// allocated using placement new during static program deinitialization.
|
|
||||||
// The destructor MUST be an inline function such that the explicit
|
|
||||||
// destruction occurs in the same compilation unit as the placement new.
|
|
||||||
class StringFlagDestructor {
|
|
||||||
void *current_storage_;
|
|
||||||
void *defvalue_storage_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
StringFlagDestructor(void *current, void *defvalue)
|
|
||||||
: current_storage_(current), defvalue_storage_(defvalue) {}
|
|
||||||
|
|
||||||
~StringFlagDestructor() {
|
|
||||||
reinterpret_cast<clstring*>(current_storage_ )->~clstring();
|
|
||||||
reinterpret_cast<clstring*>(defvalue_storage_)->~clstring();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace fLS
|
} // namespace fLS
|
||||||
|
|
||||||
// We need to define a var named FLAGS_no##name so people don't define
|
// We need to define a var named FLAGS_no##name so people don't define
|
||||||
|
@ -602,15 +550,13 @@ public:
|
||||||
#define DEFINE_string(name, val, txt) \
|
#define DEFINE_string(name, val, txt) \
|
||||||
namespace fLS { \
|
namespace fLS { \
|
||||||
using ::fLS::clstring; \
|
using ::fLS::clstring; \
|
||||||
using ::fLS::StringFlagDestructor; \
|
|
||||||
static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \
|
static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \
|
||||||
clstring* const FLAGS_no##name = ::fLS:: \
|
clstring* const FLAGS_no##name = ::fLS:: \
|
||||||
dont_pass0toDEFINE_string(s_##name[0].s, \
|
dont_pass0toDEFINE_string(s_##name[0].s, \
|
||||||
val); \
|
val); \
|
||||||
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
|
static @GFLAGS_NAMESPACE@::FlagRegisterer o_##name( \
|
||||||
#name, MAYBE_STRIPPED_HELP(txt), __FILE__, \
|
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
|
||||||
FLAGS_no##name, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
|
s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
|
||||||
static StringFlagDestructor d_##name(s_##name[0].s, s_##name[1].s); \
|
|
||||||
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
|
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
|
||||||
using fLS::FLAGS_##name; \
|
using fLS::FLAGS_##name; \
|
||||||
clstring& FLAGS_##name = *FLAGS_no##name; \
|
clstring& FLAGS_##name = *FLAGS_no##name; \
|
||||||
|
@ -619,8 +565,4 @@ public:
|
||||||
|
|
||||||
#endif // SWIG
|
#endif // SWIG
|
||||||
|
|
||||||
|
|
||||||
@INCLUDE_GFLAGS_NS_H@
|
|
||||||
|
|
||||||
|
|
||||||
#endif // GFLAGS_GFLAGS_H_
|
#endif // GFLAGS_GFLAGS_H_
|
||||||
|
|
|
@ -39,25 +39,26 @@
|
||||||
// 2a) If there are no matching flags, do nothing.
|
// 2a) If there are no matching flags, do nothing.
|
||||||
// 2b) If all matching flags share a common prefix longer than the
|
// 2b) If all matching flags share a common prefix longer than the
|
||||||
// completion word, output just that matching prefix
|
// completion word, output just that matching prefix
|
||||||
// 3) Categorize those flags to produce a rough ordering of relevance.
|
// 3) Categorize those flags to produce a rough ordering of relevence.
|
||||||
// 4) Potentially trim the set of flags returned to a smaller number
|
// 4) Potentially trim the set of flags returned to a smaller number
|
||||||
// that bash is happier with
|
// that bash is happier with
|
||||||
// 5) Output the matching flags in groups ordered by relevance.
|
// 5) Output the matching flags in groups ordered by relevence.
|
||||||
// 5a) Force bash to place most-relevent groups at the top of the list
|
// 5a) Force bash to place most-relevent groups at the top of the list
|
||||||
// 5b) Trim most flag's descriptions to fit on a single terminal line
|
// 5b) Trim most flag's descriptions to fit on a single terminal line
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
#include "config.h"
|
||||||
#include <cstring> // for strlen
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h> // for strlen
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "config.h"
|
#include "gflags.h"
|
||||||
#include "gflags/gflags.h"
|
|
||||||
#include "gflags/gflags_completions.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using std::set;
|
using std::set;
|
||||||
|
@ -119,7 +120,7 @@ static void CategorizeAllMatchingFlags(
|
||||||
NotableFlags *notable_flags);
|
NotableFlags *notable_flags);
|
||||||
|
|
||||||
static void TryFindModuleAndPackageDir(
|
static void TryFindModuleAndPackageDir(
|
||||||
const vector<CommandLineFlagInfo> &all_flags,
|
const vector<CommandLineFlagInfo> all_flags,
|
||||||
string *module,
|
string *module,
|
||||||
string *package_dir);
|
string *package_dir);
|
||||||
|
|
||||||
|
@ -170,7 +171,7 @@ static string GetLongFlagLine(
|
||||||
// most likely to be useful first. If this is set, however, the user
|
// most likely to be useful first. If this is set, however, the user
|
||||||
// really does want us to return every single flag as an option.
|
// really does want us to return every single flag as an option.
|
||||||
// - force_no_update: Any time we output lines, all of which share a
|
// - force_no_update: Any time we output lines, all of which share a
|
||||||
// common prefix, bash will 'helpfuly' not even bother to show the
|
// common prefix, bash will 'helpfully' not even bother to show the
|
||||||
// output, instead changing the current word to be that common prefix.
|
// output, instead changing the current word to be that common prefix.
|
||||||
// If it's clear this shouldn't happen, we'll set this boolean
|
// If it's clear this shouldn't happen, we'll set this boolean
|
||||||
struct CompletionOptions {
|
struct CompletionOptions {
|
||||||
|
@ -179,16 +180,11 @@ struct CompletionOptions {
|
||||||
bool flag_description_substring_search;
|
bool flag_description_substring_search;
|
||||||
bool return_all_matching_flags;
|
bool return_all_matching_flags;
|
||||||
bool force_no_update;
|
bool force_no_update;
|
||||||
CompletionOptions(): flag_name_substring_search(false),
|
|
||||||
flag_location_substring_search(false),
|
|
||||||
flag_description_substring_search(false),
|
|
||||||
return_all_matching_flags(false),
|
|
||||||
force_no_update(false) { }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Notable flags are flags that are special or preferred for some
|
// Notable flags are flags that are special or preferred for some
|
||||||
// reason. For example, flags that are defined in the binary's module
|
// reason. For example, flags that are defined in the binary's module
|
||||||
// are expected to be much more relevant than flags defined in some
|
// are expected to be much more relevent than flags defined in some
|
||||||
// other random location. These sets are specified roughly in precedence
|
// other random location. These sets are specified roughly in precedence
|
||||||
// order. Once a flag is placed in one of these 'higher' sets, it won't
|
// order. Once a flag is placed in one of these 'higher' sets, it won't
|
||||||
// be placed in any of the 'lower' sets.
|
// be placed in any of the 'lower' sets.
|
||||||
|
@ -207,7 +203,7 @@ struct NotableFlags {
|
||||||
static void PrintFlagCompletionInfo(void) {
|
static void PrintFlagCompletionInfo(void) {
|
||||||
string cursor_word = FLAGS_tab_completion_word;
|
string cursor_word = FLAGS_tab_completion_word;
|
||||||
string canonical_token;
|
string canonical_token;
|
||||||
CompletionOptions options = CompletionOptions();
|
CompletionOptions options = { };
|
||||||
CanonicalizeCursorWordAndSearchOptions(
|
CanonicalizeCursorWordAndSearchOptions(
|
||||||
cursor_word,
|
cursor_word,
|
||||||
&canonical_token,
|
&canonical_token,
|
||||||
|
@ -325,10 +321,12 @@ static void CanonicalizeCursorWordAndSearchOptions(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_question_marks > 2) options->flag_description_substring_search = true;
|
switch (found_question_marks) { // all fallthroughs
|
||||||
if (found_question_marks > 1) options->flag_location_substring_search = true;
|
case 3: options->flag_description_substring_search = true;
|
||||||
if (found_question_marks > 0) options->flag_name_substring_search = true;
|
case 2: options->flag_location_substring_search = true;
|
||||||
|
case 1: options->flag_name_substring_search = true;
|
||||||
|
};
|
||||||
|
|
||||||
options->return_all_matching_flags = (found_plusses > 0);
|
options->return_all_matching_flags = (found_plusses > 0);
|
||||||
}
|
}
|
||||||
|
@ -410,7 +408,7 @@ static bool DoesSingleFlagMatch(
|
||||||
// 3) Categorize matches (and helper method)
|
// 3) Categorize matches (and helper method)
|
||||||
|
|
||||||
// Given a set of matching flags, categorize them by
|
// Given a set of matching flags, categorize them by
|
||||||
// likely relevance to this specific binary
|
// likely relevence to this specific binary
|
||||||
static void CategorizeAllMatchingFlags(
|
static void CategorizeAllMatchingFlags(
|
||||||
const set<const CommandLineFlagInfo *> &all_matches,
|
const set<const CommandLineFlagInfo *> &all_matches,
|
||||||
const string &search_token,
|
const string &search_token,
|
||||||
|
@ -451,6 +449,10 @@ static void CategorizeAllMatchingFlags(
|
||||||
// In the package, since there was no slash after the package portion
|
// In the package, since there was no slash after the package portion
|
||||||
notable_flags->package_flags.insert(*it);
|
notable_flags->package_flags.insert(*it);
|
||||||
DVLOG(3) << "Result: package match";
|
DVLOG(3) << "Result: package match";
|
||||||
|
} else if (false) {
|
||||||
|
// In the list of the XXX most commonly supplied flags overall
|
||||||
|
// TODO(user): Compile this list.
|
||||||
|
DVLOG(3) << "Result: most-common match";
|
||||||
} else if (!package_dir.empty() &&
|
} else if (!package_dir.empty() &&
|
||||||
pos != string::npos && slash != string::npos) {
|
pos != string::npos && slash != string::npos) {
|
||||||
// In a subdirectory of the package
|
// In a subdirectory of the package
|
||||||
|
@ -468,7 +470,7 @@ static void PushNameWithSuffix(vector<string>* suffixes, const char* suffix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TryFindModuleAndPackageDir(
|
static void TryFindModuleAndPackageDir(
|
||||||
const vector<CommandLineFlagInfo> &all_flags,
|
const vector<CommandLineFlagInfo> all_flags,
|
||||||
string *module,
|
string *module,
|
||||||
string *package_dir) {
|
string *package_dir) {
|
||||||
module->clear();
|
module->clear();
|
||||||
|
@ -544,7 +546,8 @@ static void FinalizeCompletionOutput(
|
||||||
|
|
||||||
vector<DisplayInfoGroup> output_groups;
|
vector<DisplayInfoGroup> output_groups;
|
||||||
bool perfect_match_found = false;
|
bool perfect_match_found = false;
|
||||||
if (!notable_flags->perfect_match_flag.empty()) {
|
if (lines_so_far < max_desired_lines &&
|
||||||
|
!notable_flags->perfect_match_flag.empty()) {
|
||||||
perfect_match_found = true;
|
perfect_match_found = true;
|
||||||
DisplayInfoGroup group =
|
DisplayInfoGroup group =
|
||||||
{ "",
|
{ "",
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
// handling.
|
// handling.
|
||||||
//
|
//
|
||||||
// ** Overview of Bash completions:
|
// ** Overview of Bash completions:
|
||||||
// Bash can be told to programmatically determine completions for the
|
// Bash can be told to programatically determine completions for the
|
||||||
// current 'cursor word'. It does this by (in this case) invoking a
|
// current 'cursor word'. It does this by (in this case) invoking a
|
||||||
// command with some additional arguments identifying the command
|
// command with some additional arguments identifying the command
|
||||||
// being executed, the word being completed, and the previous word
|
// being executed, the word being completed, and the previous word
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
// we'll include the default flag value and as much of the flag's
|
// we'll include the default flag value and as much of the flag's
|
||||||
// description as can fit on a single terminal line width, as specified
|
// description as can fit on a single terminal line width, as specified
|
||||||
// by the flag --tab_completion_columns). Furthermore, we'll try to
|
// by the flag --tab_completion_columns). Furthermore, we'll try to
|
||||||
// make bash order the output such that the most useful or relevant
|
// make bash order the output such that the most useful or relevent
|
||||||
// flags are the most likely to be shown at the top.
|
// flags are the most likely to be shown at the top.
|
||||||
//
|
//
|
||||||
// ** Additional features:
|
// ** Additional features:
|
||||||
|
|
|
@ -37,40 +37,22 @@
|
||||||
#ifndef GFLAGS_DECLARE_H_
|
#ifndef GFLAGS_DECLARE_H_
|
||||||
#define GFLAGS_DECLARE_H_
|
#define GFLAGS_DECLARE_H_
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Namespace of gflags library symbols.
|
|
||||||
#define GFLAGS_NAMESPACE @GFLAGS_NAMESPACE@
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Windows DLL import/export.
|
// Windows DLL import/export.
|
||||||
|
|
||||||
// Whether gflags library is a DLL.
|
// We always want to import the symbols of the gflags library
|
||||||
//
|
|
||||||
// Set to 1 by default when the shared gflags library was built on Windows.
|
|
||||||
// Must be overwritten when this header file is used with the optionally also
|
|
||||||
// built static library instead; set by CMake's INTERFACE_COMPILE_DEFINITIONS.
|
|
||||||
#ifndef GFLAGS_IS_A_DLL
|
|
||||||
# define GFLAGS_IS_A_DLL @GFLAGS_IS_A_DLL@
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// We always want to import the symbols of the gflags library.
|
|
||||||
#ifndef GFLAGS_DLL_DECL
|
#ifndef GFLAGS_DLL_DECL
|
||||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
# if @GFLAGS_IS_A_DLL@ && defined(_MSC_VER)
|
||||||
# define GFLAGS_DLL_DECL __declspec(dllimport)
|
# define GFLAGS_DLL_DECL __declspec(dllimport)
|
||||||
# elif defined(__GNUC__) && __GNUC__ >= 4
|
|
||||||
# define GFLAGS_DLL_DECL __attribute__((visibility("default")))
|
|
||||||
# else
|
# else
|
||||||
# define GFLAGS_DLL_DECL
|
# define GFLAGS_DLL_DECL
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We always want to import variables declared in user code.
|
// We always want to import variables declared in user code
|
||||||
#ifndef GFLAGS_DLL_DECLARE_FLAG
|
#ifndef GFLAGS_DLL_DECLARE_FLAG
|
||||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
# ifdef _MSC_VER
|
||||||
# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
|
# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
|
||||||
# elif defined(__GNUC__) && __GNUC__ >= 4
|
|
||||||
# define GFLAGS_DLL_DECLARE_FLAG __attribute__((visibility("default")))
|
|
||||||
# else
|
# else
|
||||||
# define GFLAGS_DLL_DECLARE_FLAG
|
# define GFLAGS_DLL_DECLARE_FLAG
|
||||||
# endif
|
# endif
|
||||||
|
@ -87,7 +69,7 @@
|
||||||
# include <inttypes.h> // a third place for uint32_t or u_int32_t
|
# include <inttypes.h> // a third place for uint32_t or u_int32_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace GFLAGS_NAMESPACE {
|
namespace @GFLAGS_NAMESPACE@ {
|
||||||
|
|
||||||
#if @GFLAGS_INTTYPES_FORMAT_C99@ // C99
|
#if @GFLAGS_INTTYPES_FORMAT_C99@ // C99
|
||||||
typedef int32_t int32;
|
typedef int32_t int32;
|
||||||
|
@ -108,7 +90,7 @@ typedef unsigned __int64 uint64;
|
||||||
# error Do not know how to define a 32-bit integer quantity on your system
|
# error Do not know how to define a 32-bit integer quantity on your system
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace GFLAGS_NAMESPACE
|
} // namespace @GFLAGS_NAMESPACE@
|
||||||
|
|
||||||
|
|
||||||
namespace fLS {
|
namespace fLS {
|
||||||
|
@ -131,16 +113,13 @@ typedef std::string clstring;
|
||||||
DECLARE_VARIABLE(bool, B, name)
|
DECLARE_VARIABLE(bool, B, name)
|
||||||
|
|
||||||
#define DECLARE_int32(name) \
|
#define DECLARE_int32(name) \
|
||||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int32, I, name)
|
DECLARE_VARIABLE(GFLAGS_NAMESPACE::int32, I, name)
|
||||||
|
|
||||||
#define DECLARE_uint32(name) \
|
|
||||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint32, U, name)
|
|
||||||
|
|
||||||
#define DECLARE_int64(name) \
|
#define DECLARE_int64(name) \
|
||||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int64, I64, name)
|
DECLARE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, name)
|
||||||
|
|
||||||
#define DECLARE_uint64(name) \
|
#define DECLARE_uint64(name) \
|
||||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint64, U64, name)
|
DECLARE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, name)
|
||||||
|
|
||||||
#define DECLARE_double(name) \
|
#define DECLARE_double(name) \
|
||||||
DECLARE_VARIABLE(double, D, name)
|
DECLARE_VARIABLE(double, D, name)
|
||||||
|
@ -148,6 +127,7 @@ typedef std::string clstring;
|
||||||
#define DECLARE_string(name) \
|
#define DECLARE_string(name) \
|
||||||
/* We always want to import declared variables, dll or no */ \
|
/* We always want to import declared variables, dll or no */ \
|
||||||
namespace fLS { \
|
namespace fLS { \
|
||||||
|
using ::fLS::clstring; \
|
||||||
extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \
|
extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \
|
||||||
} \
|
} \
|
||||||
using fLS::FLAGS_##name
|
using fLS::FLAGS_##name
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
// Copyright (c) 2014, Andreas Schuh
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are
|
|
||||||
// met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright
|
|
||||||
// notice, this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above
|
|
||||||
// copyright notice, this list of conditions and the following disclaimer
|
|
||||||
// in the documentation and/or other materials provided with the
|
|
||||||
// distribution.
|
|
||||||
// * Neither the name of Google Inc. nor the names of its
|
|
||||||
// contributors may be used to endorse or promote products derived from
|
|
||||||
// this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Imports the gflags library symbols into an alternative/deprecated namespace.
|
|
||||||
|
|
||||||
#ifndef GFLAGS_GFLAGS_H_
|
|
||||||
# error The internal header gflags_@ns@.h may only be included by gflags.h
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef GFLAGS_NS_@NS@_H_
|
|
||||||
#define GFLAGS_NS_@NS@_H_
|
|
||||||
|
|
||||||
|
|
||||||
namespace @ns@ {
|
|
||||||
|
|
||||||
|
|
||||||
using GFLAGS_NAMESPACE::int32;
|
|
||||||
using GFLAGS_NAMESPACE::uint32;
|
|
||||||
using GFLAGS_NAMESPACE::int64;
|
|
||||||
using GFLAGS_NAMESPACE::uint64;
|
|
||||||
|
|
||||||
using GFLAGS_NAMESPACE::RegisterFlagValidator;
|
|
||||||
using GFLAGS_NAMESPACE::CommandLineFlagInfo;
|
|
||||||
using GFLAGS_NAMESPACE::GetAllFlags;
|
|
||||||
using GFLAGS_NAMESPACE::ShowUsageWithFlags;
|
|
||||||
using GFLAGS_NAMESPACE::ShowUsageWithFlagsRestrict;
|
|
||||||
using GFLAGS_NAMESPACE::DescribeOneFlag;
|
|
||||||
using GFLAGS_NAMESPACE::SetArgv;
|
|
||||||
using GFLAGS_NAMESPACE::GetArgvs;
|
|
||||||
using GFLAGS_NAMESPACE::GetArgv;
|
|
||||||
using GFLAGS_NAMESPACE::GetArgv0;
|
|
||||||
using GFLAGS_NAMESPACE::GetArgvSum;
|
|
||||||
using GFLAGS_NAMESPACE::ProgramInvocationName;
|
|
||||||
using GFLAGS_NAMESPACE::ProgramInvocationShortName;
|
|
||||||
using GFLAGS_NAMESPACE::ProgramUsage;
|
|
||||||
using GFLAGS_NAMESPACE::VersionString;
|
|
||||||
using GFLAGS_NAMESPACE::GetCommandLineOption;
|
|
||||||
using GFLAGS_NAMESPACE::GetCommandLineFlagInfo;
|
|
||||||
using GFLAGS_NAMESPACE::GetCommandLineFlagInfoOrDie;
|
|
||||||
using GFLAGS_NAMESPACE::FlagSettingMode;
|
|
||||||
using GFLAGS_NAMESPACE::SET_FLAGS_VALUE;
|
|
||||||
using GFLAGS_NAMESPACE::SET_FLAG_IF_DEFAULT;
|
|
||||||
using GFLAGS_NAMESPACE::SET_FLAGS_DEFAULT;
|
|
||||||
using GFLAGS_NAMESPACE::SetCommandLineOption;
|
|
||||||
using GFLAGS_NAMESPACE::SetCommandLineOptionWithMode;
|
|
||||||
using GFLAGS_NAMESPACE::FlagSaver;
|
|
||||||
using GFLAGS_NAMESPACE::CommandlineFlagsIntoString;
|
|
||||||
using GFLAGS_NAMESPACE::ReadFlagsFromString;
|
|
||||||
using GFLAGS_NAMESPACE::AppendFlagsIntoFile;
|
|
||||||
using GFLAGS_NAMESPACE::ReadFromFlagsFile;
|
|
||||||
using GFLAGS_NAMESPACE::BoolFromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::Int32FromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::Uint32FromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::Int64FromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::Uint64FromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::DoubleFromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::StringFromEnv;
|
|
||||||
using GFLAGS_NAMESPACE::SetUsageMessage;
|
|
||||||
using GFLAGS_NAMESPACE::SetVersionString;
|
|
||||||
using GFLAGS_NAMESPACE::ParseCommandLineNonHelpFlags;
|
|
||||||
using GFLAGS_NAMESPACE::HandleCommandLineHelpFlags;
|
|
||||||
using GFLAGS_NAMESPACE::AllowCommandLineReparsing;
|
|
||||||
using GFLAGS_NAMESPACE::ReparseCommandLineNonHelpFlags;
|
|
||||||
using GFLAGS_NAMESPACE::ShutDownCommandLineFlags;
|
|
||||||
using GFLAGS_NAMESPACE::FlagRegisterer;
|
|
||||||
|
|
||||||
#ifndef SWIG
|
|
||||||
using GFLAGS_NAMESPACE::ParseCommandLineFlags;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace @ns@
|
|
||||||
|
|
||||||
|
|
||||||
#endif // GFLAGS_NS_@NS@_H_
|
|
|
@ -48,22 +48,22 @@
|
||||||
// called after all flag-values have been assigned, that is, after
|
// called after all flag-values have been assigned, that is, after
|
||||||
// parsing the command-line.
|
// parsing the command-line.
|
||||||
|
|
||||||
#include <cstdio>
|
#include <stdio.h>
|
||||||
#include <cstring>
|
#include <string.h>
|
||||||
#include <cctype>
|
#include <ctype.h>
|
||||||
#include <cassert>
|
#include <assert.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gflags/gflags.h"
|
#include "gflags.h"
|
||||||
#include "gflags/gflags_completions.h"
|
#include "gflags_completions.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
// The 'reporting' flags. They all call gflags_exitfunc().
|
// The 'reporting' flags. They all call gflags_exitfunc().
|
||||||
DEFINE_bool (help, false, "show help on all flags [tip: all flags can have two dashes]");
|
DEFINE_bool (help, false, "show help on all flags [tip: all flags can have two dashes]");
|
||||||
DEFINE_bool (helpful, false, "show help on all flags -- same as -help");
|
DEFINE_bool (helpfull, false, "show help on all flags -- same as -help");
|
||||||
DEFINE_bool (helpshort, false, "show help on only the main module for this program");
|
DEFINE_bool (helpshort, false, "show help on only the main module for this program");
|
||||||
DEFINE_string(helpon, "", "show help on the modules named by this flag value");
|
DEFINE_string(helpon, "", "show help on the modules named by this flag value");
|
||||||
DEFINE_string(helpmatch, "", "show help on modules whose name contains the specified substr");
|
DEFINE_string(helpmatch, "", "show help on modules whose name contains the specified substr");
|
||||||
|
@ -123,11 +123,10 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) {
|
||||||
flag.description.c_str());
|
flag.description.c_str());
|
||||||
const char* c_string = main_part.c_str();
|
const char* c_string = main_part.c_str();
|
||||||
int chars_left = static_cast<int>(main_part.length());
|
int chars_left = static_cast<int>(main_part.length());
|
||||||
string final_string;
|
string final_string = "";
|
||||||
int chars_in_line = 0; // how many chars in current line so far?
|
int chars_in_line = 0; // how many chars in current line so far?
|
||||||
while (1) {
|
while (1) {
|
||||||
assert(static_cast<size_t>(chars_left)
|
assert(chars_left == strlen(c_string)); // Unless there's a \0 in there?
|
||||||
== strlen(c_string)); // Unless there's a \0 in there?
|
|
||||||
const char* newline = strchr(c_string, '\n');
|
const char* newline = strchr(c_string, '\n');
|
||||||
if (newline == NULL && chars_in_line+chars_left < kLineLength) {
|
if (newline == NULL && chars_in_line+chars_left < kLineLength) {
|
||||||
// The whole remainder of the string fits on this line
|
// The whole remainder of the string fits on this line
|
||||||
|
@ -275,9 +274,9 @@ static void ShowUsageWithFlagsMatching(const char *argv0,
|
||||||
++flag) {
|
++flag) {
|
||||||
if (substrings.empty() ||
|
if (substrings.empty() ||
|
||||||
FileMatchesSubstring(flag->filename, substrings)) {
|
FileMatchesSubstring(flag->filename, substrings)) {
|
||||||
found_match = true; // this flag passed the match!
|
|
||||||
// If the flag has been stripped, pretend that it doesn't exist.
|
// If the flag has been stripped, pretend that it doesn't exist.
|
||||||
if (flag->description == kStrippedFlagHelp) continue;
|
if (flag->description == kStrippedFlagHelp) continue;
|
||||||
|
found_match = true; // this flag passed the match!
|
||||||
if (flag->filename != last_filename) { // new file
|
if (flag->filename != last_filename) { // new file
|
||||||
if (Dirname(flag->filename) != Dirname(last_filename)) { // new dir!
|
if (Dirname(flag->filename) != Dirname(last_filename)) { // new dir!
|
||||||
if (!first_directory)
|
if (!first_directory)
|
||||||
|
@ -296,10 +295,10 @@ static void ShowUsageWithFlagsMatching(const char *argv0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict_) {
|
void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict) {
|
||||||
vector<string> substrings;
|
vector<string> substrings;
|
||||||
if (restrict_ != NULL && *restrict_ != '\0') {
|
if (restrict != NULL && *restrict != '\0') {
|
||||||
substrings.push_back(restrict_);
|
substrings.push_back(restrict);
|
||||||
}
|
}
|
||||||
ShowUsageWithFlagsMatching(argv0, substrings);
|
ShowUsageWithFlagsMatching(argv0, substrings);
|
||||||
}
|
}
|
||||||
|
@ -353,7 +352,7 @@ static void ShowVersion() {
|
||||||
|
|
||||||
static void AppendPrognameStrings(vector<string>* substrings,
|
static void AppendPrognameStrings(vector<string>* substrings,
|
||||||
const char* progname) {
|
const char* progname) {
|
||||||
string r;
|
string r("");
|
||||||
r += PATH_SEPARATOR;
|
r += PATH_SEPARATOR;
|
||||||
r += progname;
|
r += progname;
|
||||||
substrings->push_back(r + ".");
|
substrings->push_back(r + ".");
|
||||||
|
@ -383,14 +382,14 @@ void HandleCommandLineHelpFlags() {
|
||||||
ShowUsageWithFlagsMatching(progname, substrings);
|
ShowUsageWithFlagsMatching(progname, substrings);
|
||||||
gflags_exitfunc(1);
|
gflags_exitfunc(1);
|
||||||
|
|
||||||
} else if (FLAGS_help || FLAGS_helpful) {
|
} else if (FLAGS_help || FLAGS_helpfull) {
|
||||||
// show all options
|
// show all options
|
||||||
ShowUsageWithFlagsRestrict(progname, ""); // empty restrict
|
ShowUsageWithFlagsRestrict(progname, ""); // empty restrict
|
||||||
gflags_exitfunc(1);
|
gflags_exitfunc(1);
|
||||||
|
|
||||||
} else if (!FLAGS_helpon.empty()) {
|
} else if (!FLAGS_helpon.empty()) {
|
||||||
string restrict_ = PATH_SEPARATOR + FLAGS_helpon + ".";
|
string restrict = PATH_SEPARATOR + FLAGS_helpon + ".";
|
||||||
ShowUsageWithFlagsRestrict(progname, restrict_.c_str());
|
ShowUsageWithFlagsRestrict(progname, restrict.c_str());
|
||||||
gflags_exitfunc(1);
|
gflags_exitfunc(1);
|
||||||
|
|
||||||
} else if (!FLAGS_helpmatch.empty()) {
|
} else if (!FLAGS_helpmatch.empty()) {
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
#ifndef GFLAGS_MUTEX_H_
|
#ifndef GFLAGS_MUTEX_H_
|
||||||
#define GFLAGS_MUTEX_H_
|
#define GFLAGS_MUTEX_H_
|
||||||
|
|
||||||
#include "gflags/gflags_declare.h" // to figure out pthreads support
|
#include "gflags_declare.h" // to figure out pthreads support
|
||||||
|
|
||||||
#if defined(NO_THREADS)
|
#if defined(NO_THREADS)
|
||||||
typedef int MutexType; // to keep a lock-count
|
typedef int MutexType; // to keep a lock-count
|
||||||
|
@ -166,7 +166,7 @@ class Mutex {
|
||||||
// It inhibits work being done by the destructor, which makes it
|
// It inhibits work being done by the destructor, which makes it
|
||||||
// safer for code that tries to acqiure this mutex in their global
|
// safer for code that tries to acqiure this mutex in their global
|
||||||
// destructor.
|
// destructor.
|
||||||
explicit inline Mutex(LinkerInitialized);
|
inline Mutex(LinkerInitialized);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
inline ~Mutex();
|
inline ~Mutex();
|
||||||
|
@ -197,7 +197,7 @@ class Mutex {
|
||||||
inline void SetIsSafe() { is_safe_ = true; }
|
inline void SetIsSafe() { is_safe_ = true; }
|
||||||
|
|
||||||
// Catch the error of writing Mutex when intending MutexLock.
|
// Catch the error of writing Mutex when intending MutexLock.
|
||||||
explicit Mutex(Mutex* /*ignored*/) {}
|
Mutex(Mutex* /*ignored*/) {}
|
||||||
// Disallow "evil" constructors
|
// Disallow "evil" constructors
|
||||||
Mutex(const Mutex&);
|
Mutex(const Mutex&);
|
||||||
void operator=(const Mutex&);
|
void operator=(const Mutex&);
|
||||||
|
@ -344,5 +344,8 @@ class WriterMutexLock {
|
||||||
|
|
||||||
} // namespace MUTEX_NAMESPACE
|
} // namespace MUTEX_NAMESPACE
|
||||||
|
|
||||||
|
using namespace MUTEX_NAMESPACE;
|
||||||
|
|
||||||
|
#undef MUTEX_NAMESPACE
|
||||||
|
|
||||||
#endif /* #define GFLAGS_MUTEX_H__ */
|
#endif /* #define GFLAGS_MUTEX_H__ */
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <config.h>
|
||||||
#ifdef HAVE_INTTYPES_H
|
#ifdef HAVE_INTTYPES_H
|
||||||
# include <inttypes.h>
|
# include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -87,10 +88,9 @@ typedef unsigned char uint8;
|
||||||
|
|
||||||
// -- utility macros ---------------------------------------------------------
|
// -- utility macros ---------------------------------------------------------
|
||||||
|
|
||||||
template <bool b> struct CompileAssert;
|
template <bool> struct CompileAssert {};
|
||||||
template <> struct CompileAssert<true> {};
|
|
||||||
#define COMPILE_ASSERT(expr, msg) \
|
#define COMPILE_ASSERT(expr, msg) \
|
||||||
enum { assert_##msg = sizeof(CompileAssert<bool(expr)>) }
|
typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
|
||||||
|
|
||||||
// Returns the number of elements in an array.
|
// Returns the number of elements in an array.
|
||||||
#define arraysize(arr) (sizeof(arr)/sizeof(*(arr)))
|
#define arraysize(arr) (sizeof(arr)/sizeof(*(arr)))
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
|
|
||||||
// These call the windows _vsnprintf, but always NUL-terminate.
|
// These call the windows _vsnprintf, but always NUL-terminate.
|
||||||
#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */
|
#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */
|
||||||
#if !(defined(_MSC_VER) && _MSC_VER >= 1900) /* msvc 2015 already defines */
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning(push)
|
# pragma warning(push)
|
||||||
|
@ -69,5 +68,4 @@ int snprintf(char *str, size_t size, const char *format, ...) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* if !(defined(_MSC_VER) && _MSC_VER >= 1900) */
|
|
||||||
#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */
|
#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */
|
||||||
|
|
|
@ -63,21 +63,18 @@
|
||||||
* name vsnprintf, since windows defines that (but not snprintf (!)).
|
* name vsnprintf, since windows defines that (but not snprintf (!)).
|
||||||
*/
|
*/
|
||||||
#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */
|
#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */
|
||||||
#if !(defined(_MSC_VER) && _MSC_VER >= 1900) /* msvc 2015 already defines */
|
|
||||||
extern GFLAGS_DLL_DECL int snprintf(char *str, size_t size,
|
extern GFLAGS_DLL_DECL int snprintf(char *str, size_t size,
|
||||||
const char *format, ...);
|
const char *format, ...);
|
||||||
extern int GFLAGS_DLL_DECL safe_vsnprintf(char *str, size_t size,
|
extern int GFLAGS_DLL_DECL safe_vsnprintf(char *str, size_t size,
|
||||||
const char *format, va_list ap);
|
const char *format, va_list ap);
|
||||||
#define vsnprintf(str, size, format, ap) safe_vsnprintf(str, size, format, ap)
|
#define vsnprintf(str, size, format, ap) safe_vsnprintf(str, size, format, ap)
|
||||||
#define va_copy(dst, src) (dst) = (src)
|
#define va_copy(dst, src) (dst) = (src)
|
||||||
#endif
|
|
||||||
#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */
|
#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning(push)
|
# pragma warning(push)
|
||||||
# pragma warning(disable: 4996) // ignore getenv security warning
|
# pragma warning(disable: 4996) // ignore getenv security warning
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
|
|
||||||
inline void setenv(const char* name, const char* value, int) {
|
inline void setenv(const char* name, const char* value, int) {
|
||||||
// In windows, it's impossible to set a variable to the empty string.
|
// In windows, it's impossible to set a variable to the empty string.
|
||||||
// We handle this by setting it to "0" and the NUL-ing out the \0.
|
// We handle this by setting it to "0" and the NUL-ing out the \0.
|
||||||
|
@ -99,7 +96,6 @@ inline void setenv(const char* name, const char* value, int) {
|
||||||
*getenv(name) = '\0'; // works when putenv() copies nameval
|
*getenv(name) = '\0'; // works when putenv() copies nameval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning(pop)
|
# pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
@ -111,14 +107,10 @@ inline void setenv(const char* name, const char* value, int) {
|
||||||
#define unlink _unlink
|
#define unlink _unlink
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1800
|
|
||||||
#include <inttypes.h>
|
|
||||||
#else
|
|
||||||
#define PRId32 "d"
|
#define PRId32 "d"
|
||||||
#define PRIu32 "u"
|
#define PRIu32 "u"
|
||||||
#define PRId64 "I64d"
|
#define PRId64 "I64d"
|
||||||
#define PRIu64 "I64u"
|
#define PRIu64 "I64u"
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||||
#define strtoq _strtoi64
|
#define strtoq _strtoi64
|
||||||
|
|
|
@ -12,22 +12,16 @@ set (GFLAGS_FLAGFILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# common include directories and link libraries
|
# common include directories and link libraries
|
||||||
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}")
|
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
include_directories ("${gflags_SOURCE_DIR}/src")
|
|
||||||
include_directories ("${gflags_BINARY_DIR}/include")
|
|
||||||
include_directories ("${gflags_BINARY_DIR}/include/gflags")
|
|
||||||
|
|
||||||
if (BUILD_SHARED_LIBS)
|
if (BUILD_SHARED_LIBS)
|
||||||
set (type shared)
|
set (type shared)
|
||||||
if (GFLAGS_IS_A_DLL)
|
|
||||||
add_definitions(-DGFLAGS_IS_A_DLL)
|
|
||||||
endif ()
|
|
||||||
else ()
|
else ()
|
||||||
set (type static)
|
set (type static)
|
||||||
endif ()
|
endif ()
|
||||||
if (BUILD_gflags_LIB)
|
if (BUILD_gflags_LIB)
|
||||||
link_libraries (gflags_${type})
|
link_libraries (gflags-${type})
|
||||||
else ()
|
else ()
|
||||||
link_libraries (gflags_nothreads_${type})
|
link_libraries (gflags_nothreads-${type})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
@ -40,7 +34,6 @@ add_test (
|
||||||
NAME strip_flags_binary
|
NAME strip_flags_binary
|
||||||
COMMAND "${CMAKE_COMMAND}" "-DBINARY=$<TARGET_FILE:gflags_strip_flags_test>"
|
COMMAND "${CMAKE_COMMAND}" "-DBINARY=$<TARGET_FILE:gflags_strip_flags_test>"
|
||||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/gflags_strip_flags_test.cmake"
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/gflags_strip_flags_test.cmake"
|
||||||
CONFIGURATIONS Release MinSizeRel
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
@ -77,8 +70,8 @@ add_gflags_test(changeable_string_var 1 "-changeable_string_var () type: string
|
||||||
add_gflags_test(nohelp 0 "PASS" "" gflags_unittest --nohelp)
|
add_gflags_test(nohelp 0 "PASS" "" gflags_unittest --nohelp)
|
||||||
add_gflags_test(help=false 0 "PASS" "" gflags_unittest --help=false)
|
add_gflags_test(help=false 0 "PASS" "" gflags_unittest --help=false)
|
||||||
|
|
||||||
# --helpful is the same as help
|
# --helpfull is the same as help
|
||||||
add_gflags_test(helpful 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helpful)
|
add_gflags_test(helpfull 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helpfull)
|
||||||
|
|
||||||
# --helpshort should show only flags from the gflags_unittest itself
|
# --helpshort should show only flags from the gflags_unittest itself
|
||||||
add_gflags_test(helpshort 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest --helpshort)
|
add_gflags_test(helpshort 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest --helpshort)
|
||||||
|
@ -140,8 +133,8 @@ add_gflags_test(fromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittes
|
||||||
add_gflags_test(tryfromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=version)
|
add_gflags_test(tryfromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=version)
|
||||||
add_gflags_test(fromenv=help 0 "PASS" "" gflags_unittest --fromenv=help)
|
add_gflags_test(fromenv=help 0 "PASS" "" gflags_unittest --fromenv=help)
|
||||||
add_gflags_test(tryfromenv=help 0 "PASS" "" gflags_unittest --tryfromenv=help)
|
add_gflags_test(tryfromenv=help 0 "PASS" "" gflags_unittest --tryfromenv=help)
|
||||||
add_gflags_test(fromenv=helpful 1 "helpful not found in environment" "" gflags_unittest --fromenv=helpful)
|
add_gflags_test(fromenv=helpfull 1 "helpfull not found in environment" "" gflags_unittest --fromenv=helpfull)
|
||||||
add_gflags_test(tryfromenv=helpful 0 "PASS" "" gflags_unittest --tryfromenv=helpful)
|
add_gflags_test(tryfromenv=helpfull 0 "PASS" "" gflags_unittest --tryfromenv=helpfull)
|
||||||
add_gflags_test(tryfromenv=undefok 0 "PASS" "" gflags_unittest --tryfromenv=undefok --foo)
|
add_gflags_test(tryfromenv=undefok 0 "PASS" "" gflags_unittest --tryfromenv=undefok --foo)
|
||||||
add_gflags_test(tryfromenv=weirdo 1 "unknown command line flag" "" gflags_unittest --tryfromenv=weirdo)
|
add_gflags_test(tryfromenv=weirdo 1 "unknown command line flag" "" gflags_unittest --tryfromenv=weirdo)
|
||||||
add_gflags_test(tryfromenv-multiple 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=test_bool,version,unused_bool)
|
add_gflags_test(tryfromenv-multiple 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=test_bool,version,unused_bool)
|
||||||
|
@ -162,66 +155,24 @@ add_gflags_test(always_fail 1 "ERROR: failed validation of new value 'true' for
|
||||||
#add_gflags_test(deadlock_if_cant_lock 0 "PASS" "" gflags_unittest --deadlock_if_cant_lock)
|
#add_gflags_test(deadlock_if_cant_lock 0 "PASS" "" gflags_unittest --deadlock_if_cant_lock)
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# use gflags_declare.h
|
# (negative) compilation tests
|
||||||
add_executable (gflags_declare_test gflags_declare_test.cc gflags_declare_flags.cc)
|
if (BUILD_NC_TESTS)
|
||||||
|
|
||||||
add_test(NAME gflags_declare COMMAND gflags_declare_test --message "Hello gflags!")
|
|
||||||
set_tests_properties(gflags_declare PROPERTIES PASS_REGULAR_EXPRESSION "Hello gflags!")
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# qnx specific test installation (ctest not compatible)
|
|
||||||
if (QNX)
|
|
||||||
install (
|
|
||||||
DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
||||||
DESTINATION ${RUNTIME_INSTALL_DIR}/gflags_tests
|
|
||||||
)
|
|
||||||
install (
|
|
||||||
DIRECTORY ${PROJECT_SOURCE_DIR}/test/
|
|
||||||
DESTINATION ${RUNTIME_INSTALL_DIR}/gflags_tests
|
|
||||||
FILES_MATCHING
|
|
||||||
PATTERN "flagfile.*"
|
|
||||||
PATTERN "gflags_unittest_flagfile"
|
|
||||||
PATTERN "config" EXCLUDE
|
|
||||||
PATTERN "nc" EXCLUDE
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# configure Python script which configures and builds a test project
|
|
||||||
if (BUILD_NC_TESTS OR BUILD_CONFIG_TESTS)
|
|
||||||
find_package (PythonInterp)
|
find_package (PythonInterp)
|
||||||
if (NOT PYTHON_EXECUTABLE)
|
if (NOT PYTHON_EXECUTABLE)
|
||||||
message (FATAL_ERROR "No Python installation found! It is required by the (negative) compilation tests."
|
message (FATAL_ERROR "No Python installation found! It is required by the negative compilation tests."
|
||||||
" Either install Python or set BUILD_NC_TESTS and BUILD_CONFIG_TESTS to FALSE.")
|
" Either install Python or set BUILD_NC_TESTS to FALSE and try again.")
|
||||||
endif ()
|
endif ()
|
||||||
set (TMPDIR "${PROJECT_BINARY_DIR}/Testing/Temporary")
|
set (SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/nc")
|
||||||
configure_file (gflags_build.py.in "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build.py" @ONLY)
|
configure_file (gflags_nc.py.in "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nc.py" @ONLY)
|
||||||
function (add_gflags_build_test name srcdir expect_fail)
|
macro (add_gflags_nc_test name)
|
||||||
set (srcdir "${CMAKE_CURRENT_SOURCE_DIR}/${srcdir}")
|
|
||||||
add_test (
|
add_test (
|
||||||
NAME "${name}"
|
NAME nc_${name}
|
||||||
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build.py"
|
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nc.py" ${name}
|
||||||
${name} ${srcdir} ${expect_fail}
|
|
||||||
)
|
)
|
||||||
endfunction ()
|
endmacro ()
|
||||||
endif ()
|
add_gflags_nc_test (sanity)
|
||||||
|
add_gflags_nc_test (swapped_args)
|
||||||
# ----------------------------------------------------------------------------
|
add_gflags_nc_test (int_instead_of_bool)
|
||||||
# negative compilation tests
|
add_gflags_nc_test (bool_in_quotes)
|
||||||
option (BUILD_NC_TESTS "Request addition of negative compilation tests." OFF)
|
add_gflags_nc_test (define_string_with_0)
|
||||||
mark_as_advanced (BUILD_NC_TESTS)
|
|
||||||
if (BUILD_NC_TESTS)
|
|
||||||
add_gflags_build_test (nc_sanity nc 0)
|
|
||||||
add_gflags_build_test (nc_swapped_args nc 1)
|
|
||||||
add_gflags_build_test (nc_int_instead_of_bool nc 1)
|
|
||||||
add_gflags_build_test (nc_bool_in_quotes nc 1)
|
|
||||||
add_gflags_build_test (nc_define_string_with_0 nc 1)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# build configuration test
|
|
||||||
option (BUILD_CONFIG_TESTS "Request addition of package configuration tests." OFF)
|
|
||||||
mark_as_advanced (BUILD_CONFIG_TESTS)
|
|
||||||
if (BUILD_CONFIG_TESTS)
|
|
||||||
add_gflags_build_test (cmake_config config 0)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
## gflags package configuration tests
|
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
|
|
||||||
|
|
||||||
project (gflags_${TEST_NAME})
|
|
||||||
|
|
||||||
find_package (gflags REQUIRED)
|
|
||||||
|
|
||||||
add_executable (foo main.cc)
|
|
||||||
target_link_libraries (foo gflags::gflags)
|
|
|
@ -1,20 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <gflags/gflags.h>
|
|
||||||
|
|
||||||
DEFINE_string(message, "Hello World!", "The message to print");
|
|
||||||
|
|
||||||
static bool ValidateMessage(const char* flagname, const std::string &message)
|
|
||||||
{
|
|
||||||
return !message.empty();
|
|
||||||
}
|
|
||||||
DEFINE_validator(message, ValidateMessage);
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
gflags::SetUsageMessage("Test CMake configuration of gflags library (gflags-config.cmake)");
|
|
||||||
gflags::SetVersionString("0.1");
|
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
||||||
std::cout << FLAGS_message << std::endl;
|
|
||||||
gflags::ShutDownCommandLineFlags();
|
|
||||||
return 0;
|
|
||||||
}
|
|
79
test/config_for_unittests.h
Normal file
79
test/config_for_unittests.h
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
// Copyright (c) 2007, Google Inc.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following disclaimer
|
||||||
|
// in the documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
// * Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
// ---
|
||||||
|
// All Rights Reserved.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This file is needed for windows -- unittests are not part of the
|
||||||
|
// gflags dll, but still want to include config.h just like the
|
||||||
|
// dll does, so they can use internal tools and APIs for testing.
|
||||||
|
//
|
||||||
|
// The problem is that config.h declares GFLAGS_DLL_DECL to be
|
||||||
|
// for exporting symbols, but the unittest needs to *import* symbols
|
||||||
|
// (since it's not the dll).
|
||||||
|
//
|
||||||
|
// The solution is to have this file, which is just like config.h but
|
||||||
|
// sets GFLAGS_DLL_DECL to do a dllimport instead of a dllexport.
|
||||||
|
//
|
||||||
|
// The reason we need this extra GFLAGS_DLL_DECL_FOR_UNITTESTS
|
||||||
|
// variable is in case people want to set GFLAGS_DLL_DECL explicitly
|
||||||
|
// to something other than __declspec(dllexport). In that case, they
|
||||||
|
// may want to use something other than __declspec(dllimport) for the
|
||||||
|
// unittest case. For that, we allow folks to define both
|
||||||
|
// GFLAGS_DLL_DECL and GFLAGS_DLL_DECL_FOR_UNITTESTS explicitly.
|
||||||
|
//
|
||||||
|
// NOTE: This file is equivalent to config.h on non-windows systems,
|
||||||
|
// which never defined GFLAGS_DLL_DECL_FOR_UNITTESTS and always
|
||||||
|
// define GFLAGS_DLL_DECL to the empty string.
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef GFLAGS_DLL_DECL
|
||||||
|
# undef GFLAGS_DLL_DECL
|
||||||
|
#endif
|
||||||
|
#ifdef GFLAGS_DLL_DEFINE_FLAG
|
||||||
|
# undef GFLAGS_DLL_DEFINE_FLAG
|
||||||
|
#endif
|
||||||
|
#ifdef GFLAGS_DLL_DECLARE_FLAG
|
||||||
|
# undef GFLAGS_DLL_DECLARE_FLAG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GFLAGS_DLL_DECL_FOR_UNITTESTS
|
||||||
|
# define GFLAGS_DLL_DECL GFLAGS_DLL_DECL_FOR_UNITTESTS
|
||||||
|
#else
|
||||||
|
# define GFLAGS_DLL_DECL // if DLL_DECL_FOR_UNITTESTS isn't defined, use ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Import flags defined by gflags.cc
|
||||||
|
#if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||||
|
# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
|
||||||
|
#else
|
||||||
|
# define GFLAGS_DLL_DECLARE_FLAG
|
||||||
|
#endif
|
|
@ -1,43 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
CMAKE = '@CMAKE_COMMAND@'
|
|
||||||
CMAKE_BUILD_TYPE = '@CMAKE_BUILD_TYPE@'
|
|
||||||
TMPDIR = '@TMPDIR@'
|
|
||||||
SRCDIR = '@SRCDIR@'
|
|
||||||
GFLAGS_DIR = '@gflags_BINARY_DIR@'
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if len(sys.argv) != 4:
|
|
||||||
sys.stderr.write(' '.join(['usage:', sys.argv[0], '<test_name> <srcdir> <expect_fail:0|1>\n']))
|
|
||||||
sys.exit(1)
|
|
||||||
test_name = sys.argv[1]
|
|
||||||
srcdir = sys.argv[2]
|
|
||||||
expect_fail = (sys.argv[3].lower() in ['true', 'yes', 'on', '1'])
|
|
||||||
bindir = os.path.join(TMPDIR, test_name)
|
|
||||||
if TMPDIR == '':
|
|
||||||
sys.stderr.write('Temporary directory not set!\n')
|
|
||||||
sys.exit(1)
|
|
||||||
# create build directory
|
|
||||||
if os.path.isdir(bindir): shutil.rmtree(bindir)
|
|
||||||
os.makedirs(bindir)
|
|
||||||
# configure the build tree
|
|
||||||
if subprocess.call([CMAKE, '-DCMAKE_BUILD_TYPE:STRING='+CMAKE_BUILD_TYPE,
|
|
||||||
'-Dgflags_DIR:PATH='+GFLAGS_DIR,
|
|
||||||
'-DTEST_NAME:STRING='+test_name, srcdir], cwd=bindir) != 0:
|
|
||||||
sys.stderr.write('Failed to configure the build tree!\n')
|
|
||||||
sys.exit(1)
|
|
||||||
# build the test project
|
|
||||||
exit_code = subprocess.call([CMAKE, '--build', bindir, '--config', CMAKE_BUILD_TYPE], cwd=bindir)
|
|
||||||
if expect_fail == True:
|
|
||||||
if exit_code == 0:
|
|
||||||
sys.stderr.write('Build expected to fail, but it succeeded!\n')
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
sys.stderr.write('Build failed as expected\n')
|
|
||||||
exit_code = 0
|
|
||||||
sys.exit(exit_code)
|
|
|
@ -1,14 +0,0 @@
|
||||||
// The macro can already be defined when using Unity builds.
|
|
||||||
#undef GFLAGS_DLL_DECLARE_FLAG
|
|
||||||
#define GFLAGS_DLL_DECLARE_FLAG
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <gflags/gflags_declare.h>
|
|
||||||
|
|
||||||
DECLARE_string(message); // in gflags_delcare_test.cc
|
|
||||||
|
|
||||||
void print_message();
|
|
||||||
void print_message()
|
|
||||||
{
|
|
||||||
std::cout << FLAGS_message << std::endl;
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
#include <gflags/gflags.h>
|
|
||||||
|
|
||||||
DEFINE_string(message, "", "The message to print");
|
|
||||||
void print_message(); // in gflags_declare_flags.cc
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
GFLAGS_NAMESPACE::SetUsageMessage("Test compilation and use of gflags_declare.h");
|
|
||||||
GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
|
|
||||||
print_message();
|
|
||||||
return 0;
|
|
||||||
}
|
|
33
test/gflags_nc.py.in
Normal file
33
test/gflags_nc.py.in
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
CMAKE = '@CMAKE_COMMAND@'
|
||||||
|
TMPDIR = '@TEMPDIR@'
|
||||||
|
SRCDIR = '@SRCDIR@'
|
||||||
|
GFLAGS_DIR = '@gflags_BINARY_DIR@'
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
sys.stderr.write(' '.join(['usage:', sys.argv[0], '<test_name>\n']))
|
||||||
|
sys.exit(1)
|
||||||
|
test_name = sys.argv[1]
|
||||||
|
bindir = os.path.join(TMPDIR, '_'.join(['nc', test_name]))
|
||||||
|
if TMPDIR == '':
|
||||||
|
sys.stderr.write('Temporary directory not set!\n')
|
||||||
|
sys.exit(1)
|
||||||
|
# create build directory
|
||||||
|
if os.path.isdir(bindir): shutil.rmtree(bindir)
|
||||||
|
os.makedirs(bindir)
|
||||||
|
# configure the build tree
|
||||||
|
if subprocess.call([CMAKE, '-Dgflags_DIR:PATH='+GFLAGS_DIR, '-DTEST_NAME:STRING='+test_name, SRCDIR], cwd=bindir) != 0:
|
||||||
|
sys.stderr.write('Failed to configure the build tree!\n')
|
||||||
|
sys.exit(1)
|
||||||
|
# try build, which is supposed to fail (except in case of the sanity check)
|
||||||
|
if subprocess.call([CMAKE, '--build', bindir], cwd=bindir) == 0 and test_name != 'sanity':
|
||||||
|
sys.stderr.write('Build expected to fail, but it succeeded!\n')
|
||||||
|
sys.exit(1)
|
||||||
|
sys.exit(0)
|
1
test/gflags_strip_flags_test.cc
Executable file → Normal file
1
test/gflags_strip_flags_test.cc
Executable file → Normal file
|
@ -34,6 +34,7 @@
|
||||||
// script that runs 'strings' over this program and makes sure
|
// script that runs 'strings' over this program and makes sure
|
||||||
// that the help string is not in there.
|
// that the help string is not in there.
|
||||||
|
|
||||||
|
#include "config_for_unittests.h"
|
||||||
#define STRIP_FLAG_HELP 1
|
#define STRIP_FLAG_HELP 1
|
||||||
#include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
if (NOT BINARY)
|
if (NOT BINARY)
|
||||||
message (FATAL_ERROR "BINARY file to check not specified!")
|
message (FATAl_ERROR "BINARY file to check not specified!")
|
||||||
endif ()
|
endif ()
|
||||||
file (STRINGS "${BINARY}" strings REGEX "This text should be stripped out")
|
file (STRINGS "${BINARY}" strings REGEX "This text should be stripped out")
|
||||||
if (strings)
|
if (strings)
|
||||||
message (FATAL_ERROR "Text not stripped from binary like it should be: ${BINARY}")
|
message (FATAL_ERROR "Text not stripped from binary like it should be: ${BINARY}")
|
||||||
endif ()
|
endif ()
|
76
test/gflags_unittest.cc
Executable file → Normal file
76
test/gflags_unittest.cc
Executable file → Normal file
|
@ -32,11 +32,9 @@
|
||||||
// For now, this unit test does not cover all features of
|
// For now, this unit test does not cover all features of
|
||||||
// gflags.cc
|
// gflags.cc
|
||||||
|
|
||||||
|
#include "config_for_unittests.h"
|
||||||
#include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
#include <math.h> // for isinf() and isnan()
|
#include <math.h> // for isinf() and isnan()
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -46,6 +44,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "util.h"
|
||||||
TEST_INIT
|
TEST_INIT
|
||||||
EXPECT_DEATH_INIT
|
EXPECT_DEATH_INIT
|
||||||
|
|
||||||
|
@ -75,7 +74,6 @@ DECLARE_string(tryfromenv); // in gflags.cc
|
||||||
DEFINE_bool(test_bool, false, "tests bool-ness");
|
DEFINE_bool(test_bool, false, "tests bool-ness");
|
||||||
DEFINE_int32(test_int32, -1, "");
|
DEFINE_int32(test_int32, -1, "");
|
||||||
DEFINE_int64(test_int64, -2, "");
|
DEFINE_int64(test_int64, -2, "");
|
||||||
DEFINE_uint32(test_uint32, 1, "");
|
|
||||||
DEFINE_uint64(test_uint64, 2, "");
|
DEFINE_uint64(test_uint64, 2, "");
|
||||||
DEFINE_double(test_double, -1.0, "");
|
DEFINE_double(test_double, -1.0, "");
|
||||||
DEFINE_string(test_string, "initial", "");
|
DEFINE_string(test_string, "initial", "");
|
||||||
|
@ -116,7 +114,6 @@ DEFINE_string(changeable_string_var, ChangeableString(), "");
|
||||||
DEFINE_bool(unused_bool, true, "unused bool-ness");
|
DEFINE_bool(unused_bool, true, "unused bool-ness");
|
||||||
DEFINE_int32(unused_int32, -1001, "");
|
DEFINE_int32(unused_int32, -1001, "");
|
||||||
DEFINE_int64(unused_int64, -2001, "");
|
DEFINE_int64(unused_int64, -2001, "");
|
||||||
DEFINE_uint32(unused_uint32, 1000, "");
|
|
||||||
DEFINE_uint64(unused_uint64, 2000, "");
|
DEFINE_uint64(unused_uint64, 2000, "");
|
||||||
DEFINE_double(unused_double, -1000.0, "");
|
DEFINE_double(unused_double, -1000.0, "");
|
||||||
DEFINE_string(unused_string, "unused", "");
|
DEFINE_string(unused_string, "unused", "");
|
||||||
|
@ -216,7 +213,7 @@ namespace fLI {
|
||||||
int32 FLAGS_tldflag1 = FLAGS_nonotldflag1;
|
int32 FLAGS_tldflag1 = FLAGS_nonotldflag1;
|
||||||
int32 FLAGS_notldflag1 = FLAGS_nonotldflag1;
|
int32 FLAGS_notldflag1 = FLAGS_nonotldflag1;
|
||||||
static FlagRegisterer o_tldflag1(
|
static FlagRegisterer o_tldflag1(
|
||||||
"tldflag1",
|
"tldflag1", "int32",
|
||||||
"should show up in --helpshort", "gflags_unittest.cc",
|
"should show up in --helpshort", "gflags_unittest.cc",
|
||||||
&FLAGS_tldflag1, &FLAGS_notldflag1);
|
&FLAGS_tldflag1, &FLAGS_notldflag1);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +224,7 @@ namespace fLI {
|
||||||
int32 FLAGS_tldflag2 = FLAGS_nonotldflag2;
|
int32 FLAGS_tldflag2 = FLAGS_nonotldflag2;
|
||||||
int32 FLAGS_notldflag2 = FLAGS_nonotldflag2;
|
int32 FLAGS_notldflag2 = FLAGS_nonotldflag2;
|
||||||
static FlagRegisterer o_tldflag2(
|
static FlagRegisterer o_tldflag2(
|
||||||
"tldflag2",
|
"tldflag2", "int32",
|
||||||
"should show up in --helpshort", "gflags_unittest.",
|
"should show up in --helpshort", "gflags_unittest.",
|
||||||
&FLAGS_tldflag2, &FLAGS_notldflag2);
|
&FLAGS_tldflag2, &FLAGS_notldflag2);
|
||||||
}
|
}
|
||||||
|
@ -279,7 +276,6 @@ TEST(FlagTypes, FlagTypes) {
|
||||||
AssertIsType<bool>(FLAGS_test_bool);
|
AssertIsType<bool>(FLAGS_test_bool);
|
||||||
AssertIsType<int32>(FLAGS_test_int32);
|
AssertIsType<int32>(FLAGS_test_int32);
|
||||||
AssertIsType<int64>(FLAGS_test_int64);
|
AssertIsType<int64>(FLAGS_test_int64);
|
||||||
AssertIsType<uint32>(FLAGS_test_uint32);
|
|
||||||
AssertIsType<uint64>(FLAGS_test_uint64);
|
AssertIsType<uint64>(FLAGS_test_uint64);
|
||||||
AssertIsType<double>(FLAGS_test_double);
|
AssertIsType<double>(FLAGS_test_double);
|
||||||
AssertIsType<string>(FLAGS_test_string);
|
AssertIsType<string>(FLAGS_test_string);
|
||||||
|
@ -357,19 +353,6 @@ TEST(FlagFileTest, ReadFlagsFromString) {
|
||||||
false,
|
false,
|
||||||
123,
|
123,
|
||||||
123.0);
|
123.0);
|
||||||
|
|
||||||
// Test that flags can use dashes instead of underscores.
|
|
||||||
TestFlagString(
|
|
||||||
// Flag string
|
|
||||||
"-test-string=initial\n"
|
|
||||||
"--test-bool=false\n"
|
|
||||||
"--test-int32=123\n"
|
|
||||||
"--test-double=123.0\n",
|
|
||||||
// Expected values
|
|
||||||
"initial",
|
|
||||||
false,
|
|
||||||
123,
|
|
||||||
123.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests the filename part of the flagfile
|
// Tests the filename part of the flagfile
|
||||||
|
@ -607,15 +590,11 @@ TEST(SetFlagValueTest, IllegalValues) {
|
||||||
FLAGS_test_bool = true;
|
FLAGS_test_bool = true;
|
||||||
FLAGS_test_int32 = 119;
|
FLAGS_test_int32 = 119;
|
||||||
FLAGS_test_int64 = 1191;
|
FLAGS_test_int64 = 1191;
|
||||||
FLAGS_test_uint32 = 11911;
|
FLAGS_test_uint64 = 11911;
|
||||||
FLAGS_test_uint64 = 119111;
|
|
||||||
|
|
||||||
EXPECT_EQ("",
|
EXPECT_EQ("",
|
||||||
SetCommandLineOption("test_bool", "12"));
|
SetCommandLineOption("test_bool", "12"));
|
||||||
|
|
||||||
EXPECT_EQ("",
|
|
||||||
SetCommandLineOption("test_uint32", "-1970"));
|
|
||||||
|
|
||||||
EXPECT_EQ("",
|
EXPECT_EQ("",
|
||||||
SetCommandLineOption("test_int32", "7000000000000"));
|
SetCommandLineOption("test_int32", "7000000000000"));
|
||||||
|
|
||||||
|
@ -629,7 +608,6 @@ TEST(SetFlagValueTest, IllegalValues) {
|
||||||
EXPECT_EQ("", SetCommandLineOption("test_bool", ""));
|
EXPECT_EQ("", SetCommandLineOption("test_bool", ""));
|
||||||
EXPECT_EQ("", SetCommandLineOption("test_int32", ""));
|
EXPECT_EQ("", SetCommandLineOption("test_int32", ""));
|
||||||
EXPECT_EQ("", SetCommandLineOption("test_int64", ""));
|
EXPECT_EQ("", SetCommandLineOption("test_int64", ""));
|
||||||
EXPECT_EQ("", SetCommandLineOption("test_uint32", ""));
|
|
||||||
EXPECT_EQ("", SetCommandLineOption("test_uint64", ""));
|
EXPECT_EQ("", SetCommandLineOption("test_uint64", ""));
|
||||||
EXPECT_EQ("", SetCommandLineOption("test_double", ""));
|
EXPECT_EQ("", SetCommandLineOption("test_double", ""));
|
||||||
EXPECT_EQ("test_string set to \n", SetCommandLineOption("test_string", ""));
|
EXPECT_EQ("test_string set to \n", SetCommandLineOption("test_string", ""));
|
||||||
|
@ -637,8 +615,7 @@ TEST(SetFlagValueTest, IllegalValues) {
|
||||||
EXPECT_TRUE(FLAGS_test_bool);
|
EXPECT_TRUE(FLAGS_test_bool);
|
||||||
EXPECT_EQ(119, FLAGS_test_int32);
|
EXPECT_EQ(119, FLAGS_test_int32);
|
||||||
EXPECT_EQ(1191, FLAGS_test_int64);
|
EXPECT_EQ(1191, FLAGS_test_int64);
|
||||||
EXPECT_EQ(11911, FLAGS_test_uint32);
|
EXPECT_EQ(11911, FLAGS_test_uint64);
|
||||||
EXPECT_EQ(119111, FLAGS_test_uint64);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -691,19 +668,14 @@ TEST(FromEnvTest, LegalValues) {
|
||||||
EXPECT_EQ(-1, Int32FromEnv("INT_VAL2", 10));
|
EXPECT_EQ(-1, Int32FromEnv("INT_VAL2", 10));
|
||||||
EXPECT_EQ(10, Int32FromEnv("INT_VAL_UNKNOWN", 10));
|
EXPECT_EQ(10, Int32FromEnv("INT_VAL_UNKNOWN", 10));
|
||||||
|
|
||||||
setenv("INT_VAL3", "4294967295", 1);
|
setenv("INT_VAL3", "1099511627776", 1);
|
||||||
EXPECT_EQ(1, Uint32FromEnv("INT_VAL1", 10));
|
|
||||||
EXPECT_EQ(4294967295L, Uint32FromEnv("INT_VAL3", 30));
|
|
||||||
EXPECT_EQ(10, Uint32FromEnv("INT_VAL_UNKNOWN", 10));
|
|
||||||
|
|
||||||
setenv("INT_VAL4", "1099511627776", 1);
|
|
||||||
EXPECT_EQ(1, Int64FromEnv("INT_VAL1", 20));
|
EXPECT_EQ(1, Int64FromEnv("INT_VAL1", 20));
|
||||||
EXPECT_EQ(-1, Int64FromEnv("INT_VAL2", 20));
|
EXPECT_EQ(-1, Int64FromEnv("INT_VAL2", 20));
|
||||||
EXPECT_EQ(1099511627776LL, Int64FromEnv("INT_VAL4", 20));
|
EXPECT_EQ(1099511627776LL, Int64FromEnv("INT_VAL3", 20));
|
||||||
EXPECT_EQ(20, Int64FromEnv("INT_VAL_UNKNOWN", 20));
|
EXPECT_EQ(20, Int64FromEnv("INT_VAL_UNKNOWN", 20));
|
||||||
|
|
||||||
EXPECT_EQ(1, Uint64FromEnv("INT_VAL1", 30));
|
EXPECT_EQ(1, Uint64FromEnv("INT_VAL1", 30));
|
||||||
EXPECT_EQ(1099511627776ULL, Uint64FromEnv("INT_VAL4", 30));
|
EXPECT_EQ(1099511627776ULL, Uint64FromEnv("INT_VAL3", 30));
|
||||||
EXPECT_EQ(30, Uint64FromEnv("INT_VAL_UNKNOWN", 30));
|
EXPECT_EQ(30, Uint64FromEnv("INT_VAL_UNKNOWN", 30));
|
||||||
|
|
||||||
// I pick values here that can be easily represented exactly in floating-point
|
// I pick values here that can be easily represented exactly in floating-point
|
||||||
|
@ -739,11 +711,6 @@ TEST(FromEnvDeathTest, IllegalValues) {
|
||||||
EXPECT_DEATH(Int32FromEnv("INT_BAD3", 10), "error parsing env variable");
|
EXPECT_DEATH(Int32FromEnv("INT_BAD3", 10), "error parsing env variable");
|
||||||
EXPECT_DEATH(Int32FromEnv("INT_BAD4", 10), "error parsing env variable");
|
EXPECT_DEATH(Int32FromEnv("INT_BAD4", 10), "error parsing env variable");
|
||||||
|
|
||||||
EXPECT_DEATH(Uint32FromEnv("INT_BAD1", 10), "error parsing env variable");
|
|
||||||
EXPECT_DEATH(Uint32FromEnv("INT_BAD2", 10), "error parsing env variable");
|
|
||||||
EXPECT_DEATH(Uint32FromEnv("INT_BAD3", 10), "error parsing env variable");
|
|
||||||
EXPECT_DEATH(Uint32FromEnv("INT_BAD4", 10), "error parsing env variable");
|
|
||||||
|
|
||||||
setenv("BIGINT_BAD1", "18446744073709551616000", 1);
|
setenv("BIGINT_BAD1", "18446744073709551616000", 1);
|
||||||
EXPECT_DEATH(Int64FromEnv("INT_BAD1", 20), "error parsing env variable");
|
EXPECT_DEATH(Int64FromEnv("INT_BAD1", 20), "error parsing env variable");
|
||||||
EXPECT_DEATH(Int64FromEnv("INT_BAD3", 20), "error parsing env variable");
|
EXPECT_DEATH(Int64FromEnv("INT_BAD3", 20), "error parsing env variable");
|
||||||
|
@ -847,10 +814,9 @@ TEST(FlagSaverTest, CanSaveVariousTypedFlagValues) {
|
||||||
// Initializes the flags.
|
// Initializes the flags.
|
||||||
FLAGS_test_bool = false;
|
FLAGS_test_bool = false;
|
||||||
FLAGS_test_int32 = -1;
|
FLAGS_test_int32 = -1;
|
||||||
FLAGS_test_uint32 = 2;
|
FLAGS_test_int64 = -2;
|
||||||
FLAGS_test_int64 = -3;
|
FLAGS_test_uint64 = 3;
|
||||||
FLAGS_test_uint64 = 4;
|
FLAGS_test_double = 4.0;
|
||||||
FLAGS_test_double = 5.0;
|
|
||||||
FLAGS_test_string = "good";
|
FLAGS_test_string = "good";
|
||||||
|
|
||||||
// Saves the flag states.
|
// Saves the flag states.
|
||||||
|
@ -860,9 +826,8 @@ TEST(FlagSaverTest, CanSaveVariousTypedFlagValues) {
|
||||||
// Modifies the flags.
|
// Modifies the flags.
|
||||||
FLAGS_test_bool = true;
|
FLAGS_test_bool = true;
|
||||||
FLAGS_test_int32 = -5;
|
FLAGS_test_int32 = -5;
|
||||||
FLAGS_test_uint32 = 6;
|
FLAGS_test_int64 = -6;
|
||||||
FLAGS_test_int64 = -7;
|
FLAGS_test_uint64 = 7;
|
||||||
FLAGS_test_uint64 = 8;
|
|
||||||
FLAGS_test_double = 8.0;
|
FLAGS_test_double = 8.0;
|
||||||
FLAGS_test_string = "bad";
|
FLAGS_test_string = "bad";
|
||||||
|
|
||||||
|
@ -872,10 +837,9 @@ TEST(FlagSaverTest, CanSaveVariousTypedFlagValues) {
|
||||||
// Verifies the flag values were restored.
|
// Verifies the flag values were restored.
|
||||||
EXPECT_FALSE(FLAGS_test_bool);
|
EXPECT_FALSE(FLAGS_test_bool);
|
||||||
EXPECT_EQ(-1, FLAGS_test_int32);
|
EXPECT_EQ(-1, FLAGS_test_int32);
|
||||||
EXPECT_EQ(2, FLAGS_test_uint32);
|
EXPECT_EQ(-2, FLAGS_test_int64);
|
||||||
EXPECT_EQ(-3, FLAGS_test_int64);
|
EXPECT_EQ(3, FLAGS_test_uint64);
|
||||||
EXPECT_EQ(4, FLAGS_test_uint64);
|
EXPECT_DOUBLE_EQ(4.0, FLAGS_test_double);
|
||||||
EXPECT_DOUBLE_EQ(5.0, FLAGS_test_double);
|
|
||||||
EXPECT_EQ("good", FLAGS_test_string);
|
EXPECT_EQ("good", FLAGS_test_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1368,7 +1332,7 @@ TEST(ParseCommandLineFlagsWrongFields,
|
||||||
// addresses of these variables will be overwritten... Stack smash!
|
// addresses of these variables will be overwritten... Stack smash!
|
||||||
static bool current_storage;
|
static bool current_storage;
|
||||||
static bool defvalue_storage;
|
static bool defvalue_storage;
|
||||||
FlagRegisterer fr("flag_name", NULL, "filename",
|
FlagRegisterer fr("flag_name", "bool", 0, "filename",
|
||||||
¤t_storage, &defvalue_storage);
|
¤t_storage, &defvalue_storage);
|
||||||
CommandLineFlagInfo fi;
|
CommandLineFlagInfo fi;
|
||||||
EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi));
|
EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi));
|
||||||
|
@ -1521,7 +1485,7 @@ TEST(FlagsValidator, FlagSaver) {
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
static int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
// Run unit tests only if called without arguments, otherwise this program
|
// Run unit tests only if called without arguments, otherwise this program
|
||||||
// is used by an "external" usage test
|
// is used by an "external" usage test
|
||||||
|
@ -1550,7 +1514,7 @@ static int main(int argc, char **argv) {
|
||||||
// The non-recommended way:
|
// The non-recommended way:
|
||||||
FLAGS_changed_bool2 = true;
|
FLAGS_changed_bool2 = true;
|
||||||
|
|
||||||
SetUsageMessage(usage_message);
|
SetUsageMessage(usage_message.c_str());
|
||||||
SetVersionString("test_version");
|
SetVersionString("test_version");
|
||||||
ParseCommandLineFlags(&argc, &argv, true);
|
ParseCommandLineFlags(&argc, &argv, true);
|
||||||
MakeTmpdir(&FLAGS_test_tmpdir);
|
MakeTmpdir(&FLAGS_test_tmpdir);
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
## gflags negative compilation tests
|
## gflags negative compilation tests
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
|
||||||
if (NOT TEST_NAME)
|
if (NOT TEST_NAME)
|
||||||
message (FATAL_ERROR "Missing TEST_NAME CMake flag")
|
message (FATAL_ERROR "Missing TEST_NAME CMake flag")
|
||||||
endif ()
|
endif ()
|
||||||
string (TOUPPER ${TEST_NAME} TEST_NAME_UPPER)
|
string (TOUPPER ${TEST_NAME} TEST_NAME_UPPER)
|
||||||
|
|
||||||
project (gflags_${TEST_NAME})
|
project (gflags_nc_${TEST_NAME})
|
||||||
|
|
||||||
find_package (gflags REQUIRED)
|
find_package (gflags REQUIRED)
|
||||||
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/..")
|
include_directories (${gflags_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||||
|
link_libraries (gflags_nothreads)
|
||||||
add_definitions (-DTEST_${TEST_NAME_UPPER})
|
add_definitions (-DTEST_${TEST_NAME_UPPER})
|
||||||
add_executable (gflags_${TEST_NAME} gflags_nc.cc)
|
add_executable (gflags_nc_${TEST_NAME} gflags_nc.cc)
|
||||||
target_link_libraries(gflags_${TEST_NAME} gflags)
|
|
||||||
|
|
|
@ -33,33 +33,33 @@
|
||||||
|
|
||||||
#include <gflags/gflags.h>
|
#include <gflags/gflags.h>
|
||||||
|
|
||||||
#if defined(TEST_NC_SWAPPED_ARGS)
|
#if defined(TEST_SWAPPED_ARGS)
|
||||||
|
|
||||||
DEFINE_bool(some_bool_flag,
|
DEFINE_bool(some_bool_flag,
|
||||||
"the default value should go here, not the description",
|
"the default value should go here, not the description",
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
|
||||||
#elif defined(TEST_NC_INT_INSTEAD_OF_BOOL)
|
#elif defined(TEST_INT_INSTEAD_OF_BOOL)
|
||||||
|
|
||||||
DEFINE_bool(some_bool_flag_2,
|
DEFINE_bool(some_bool_flag_2,
|
||||||
0,
|
0,
|
||||||
"should have been an int32 flag but mistakenly used bool instead");
|
"should have been an int32 flag but mistakenly used bool instead");
|
||||||
|
|
||||||
#elif defined(TEST_NC_BOOL_IN_QUOTES)
|
#elif defined(TEST_BOOL_IN_QUOTES)
|
||||||
|
|
||||||
|
|
||||||
DEFINE_bool(some_bool_flag_3,
|
DEFINE_bool(some_bool_flag_3,
|
||||||
"false",
|
"false",
|
||||||
"false in in quotes, which is wrong");
|
"false in in quotes, which is wrong");
|
||||||
|
|
||||||
#elif defined(TEST_NC_SANITY)
|
#elif defined(TEST_SANITY)
|
||||||
|
|
||||||
DEFINE_bool(some_bool_flag_4,
|
DEFINE_bool(some_bool_flag_4,
|
||||||
true,
|
true,
|
||||||
"this is the correct usage of DEFINE_bool");
|
"this is the correct usage of DEFINE_bool");
|
||||||
|
|
||||||
#elif defined(TEST_NC_DEFINE_STRING_WITH_0)
|
#elif defined(TEST_DEFINE_STRING_WITH_0)
|
||||||
|
|
||||||
DEFINE_string(some_string_flag,
|
DEFINE_string(some_string_flag,
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue