Compare commits

...

108 commits

Author SHA1 Message Date
Andreas Schuh
52e94563eb
test: Trigger workflow upon push on master (#370)
Some checks failed
Build and Run Tests / Test on ubuntu-latest (push) Failing after 1s
2025-03-31 23:49:02 +01:00
Andreas Schuh
c1f63a168d
doc: Replace CI badges with GitHub Action status (#369) 2025-03-31 23:39:15 +01:00
Rui Chen
70c01a642f
build: support cmake 4.0 (#367)
Signed-off-by: Rui Chen <rui@chenrui.dev>
2025-03-31 23:35:49 +01:00
Andreas Schuh
b364def945
test: Add GitHub Action to run CTest (#368)
* test: Remove Travis CI and Appveyor config files

* test: Add GitHub Action to run CTest on Ubuntu
2025-03-31 23:33:08 +01:00
JaiXJM-BB
58cf1ef6d0
cmake: Support BlackBerry QNX (#364) 2024-12-13 23:00:05 +00:00
Izzie Corley
3c4399ba46
Fix spelling in ChangeLog.txt (#362) 2024-10-11 13:35:38 +01:00
Lan Zongwei
03a4842c9c cmake: export gflags_nothreads_static into one export set by subproject default 2024-06-09 22:38:04 +01:00
Vertexwahn
82793e3f38 Fix spelling 2024-06-09 22:08:02 +01:00
Alexander Borsuk
c196ce6baa Fixed macro redifinition warning for Unity builds
Signed-off-by: Alexander Borsuk <me@alex.bio>
2024-06-09 22:07:48 +01:00
Vertexwahn
3df39f3a03 Add MODULE.bazel file to support Bzlmod 2024-06-09 22:04:34 +01:00
Biswapriyo Nath
a738fdf933 cmake: Do not add suffix with static library names in mingw
In mingw environment, this fixes static linking using pkgconfig file.
2022-07-27 22:06:09 +01:00
Joseph Shanak
b7fd838331 Update docs. Add id to --flagfile so it can be jumped to 2022-07-27 22:05:07 +01:00
Biswapriyo Nath
986e8eed00 cmake: Install pkgconfig file in mingw 2022-01-08 23:24:44 +00:00
Michael Chinen
9ca7e9ee7a
Android linking fix (#321) 2022-01-08 23:02:39 +00:00
HongboLiu
4ace06d024 make bazel use same namespace with cmake 2022-01-08 22:40:36 +00:00
Changqing Li
827c769e5f switch shebang to python3
python2 is EOL, swith shebang to python3

Signed-off-by: Changqing Li <changqing.li@windriver.com>
2020-10-30 10:16:12 +00:00
Zachary
5d5a6c5501 Include string.h for strchr and strcmp.
This fixes a continuous build
(https://travis-ci.org/github/google/perf_data_converter/jobs/714589290)
running on Ubuntu 16.04 using gcc-4.8.
2020-10-11 01:37:59 +01:00
panzhongxian
a386bd0f20 Update index.html dependency with Bazel section. 2020-09-23 11:26:36 +01:00
panzhongxian
cb68d9eeb8 Update index.html dependency with Bazel section. 2020-09-23 09:05:28 +01:00
Andreas Schuh
ae2fae5645 Merge branch 'remove-doc-submodule' 2020-09-18 17:55:31 +01:00
Andreas Schuh
1c86423887 Add doc/README.md with command to update gh-pages 2020-09-18 17:50:41 +01:00
Andreas Schuh
8843f88b69 Add 'doc/' from commit '8411df715cf522606e3b1aca386ddfc0b63d34b4'
git-subtree-dir: doc
git-subtree-mainline: 4405871443
git-subtree-split: 8411df715c
2020-09-18 17:44:46 +01:00
Andreas Schuh
4405871443 Remove doc/ submodule self-reference 2020-09-18 17:44:26 +01:00
Andrew Gasparovic
f7388c6655 Simplify found_question_marks tests 2020-06-16 22:11:03 +01:00
Andrew Gasparovic
84968c6bb2 Remove fallthrough switch case
GCC gives an implicit-fallthrough warning (included in -Wextra). C++17 has the [[fallthrough]] attribute, and GCC7+ has __attribute__ ((fallthrough)), but I didn't want to require either so I refactored the switch into if statements.
2020-06-16 22:11:03 +01:00
Tom Lundell
1137acc9e0 Remove msys dependency for Windows.
Bazel genrules require a msys shell to execute
shell commands. Replace the genrules with a
simple C++ regex replacement binary.

Fixes #303.
2020-06-13 03:44:00 +01:00
Andrew Gasparovic
ef8e134d48 Remove unreachable code
INFO: From Compiling external/com_github_gflags_gflags/src/gflags_completions.cc:
external/com_github_gflags_gflags/src/gflags_completions.cc:459:16: warning: code will never be executed [-Wunreachable-code]
      DVLOG(3) << "Result: most-common match";
               ^~
1 warning generated.
2020-06-13 00:41:51 +01:00
Ilya Lavrenov
addd749114 Set POCICY 0063 to new 2020-03-18 12:31:18 +00:00
Trevor Hickey
2e227c3daa remove attribute where it does not apply
```
gflags.h(226): warning: attribute "visibility" does not apply here
```

The visibility attribute applies to symbols like functions and variables. A definition of an enumeration type that doesn't contain a variable name doesn't create any symbols.
2020-01-16 00:49:58 +00:00
Jacky Wu
d9b184bd00 Avoid no-match message in case STRIP_FLAG_HELP been set
If the workaround in issue #43 is used along with the define of
STRIP_FLAG_HELP to 1, there would be a wrong "No modules matched"
message been print at end of the usage message.

That's because we continue the loop if we see strip flag help value and
never set the `found_match` flag to true even if we found a match.

By moving the set statement above the continue, we can avoid this wrong
message.
2019-11-13 14:07:30 +00:00
Rosen Penev
6c8f50b567 [clang-tidy] Remove redundant initialization of strings
Found with readability-redundant-string-init

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-01 09:26:51 +00:00
Rosen Penev
6d224d34b6 [clang-tidy] Replace deprecated C headers
Deprecated with C++14.

Found with modernize-deprecated-headers

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-01 09:26:51 +00:00
Mizux
0b7f8db2c6 Fix check of targets in package config when GFLAGS_USE_TARGET_NAMESPACE 2019-09-29 15:31:36 +01:00
Andreas Schuh
f40e43a628 Change order of sections in INSTALL file, mention Homebrew 2019-09-29 14:59:09 +01:00
grdowns
57c5913fb8 Add vcpkg installation instructions 2019-09-29 14:50:43 +01:00
Rosen Penev
2cac878761 package.pc.in: bin and libdir to exec_prefix
More consistent with other pkgconfig files.

No functional difference.
2019-09-17 19:13:49 +01:00
Andreas Schuh
28f50e0fed
fix: Install pkgconfig file only when INSTALL_HEADERS option is ON 2019-01-25 17:58:59 +00:00
Andreas Schuh
1005485222 fixup: Keep CMake coding style with whitespace after command name 2018-12-05 11:11:48 +00:00
Andreas Schuh
be65295633 fix: GFLAGS_* variables take precedence in gflags_define 2018-12-05 11:11:48 +00:00
Andreas Schuh
524b83d026
Merge pull request #276 from Rastaban/master
Add missing @ to cmake-config.in
2018-12-01 00:20:51 +00:00
Phil Christensen
34819405ab
Merge pull request #1 from Rastaban/Rastaban-patch-1
Add missing @ to cmake file
2018-11-30 15:50:14 -08:00
Phil Christensen
00fcadd9b8
Add missing @ to cmake file 2018-11-30 15:48:42 -08:00
Andreas Schuh
498cfa8b13
doc: Minor English language fix in release notes 2018-11-11 21:43:32 +00:00
Andreas Schuh
e171aa2d15
Release v2.2.2 2018-11-11 21:21:00 +00:00
Andreas Schuh
3d2a101c9e doc: Update README for release v2.2.2 2018-11-11 21:17:01 +00:00
Andreas Schuh
af502c8176 doc: Update ChangeLog for release v2.2.2 2018-11-11 21:09:58 +00:00
Andreas Schuh
0f439e8407 cmake: Increment project version to 2.2.2 2018-11-11 21:09:38 +00:00
Andreas Schuh
83fecd3ed0 doc: Updated CMake and Bazel examples 2018-11-11 20:45:00 +00:00
Andreas Schuh
8411df715c Update CMake and Bazel examples 2018-11-11 20:44:23 +00:00
Andreas Schuh
4c0bbc0604 fix: Use 'default' visibility for GCC 2018-11-11 20:35:02 +00:00
Andreas Schuh
0c7012d647 fix: Build with MinGW version after Nov 2016 2018-11-09 16:38:57 +00:00
Andreas Schuh
b051bace27 fix: Build with _UNICODE support on Windows 2018-11-09 16:16:24 +00:00
Andreas Schuh
7e70988188 fix: PVS Studio warnings 2018-10-15 02:15:17 -07:00
Andreas Schuh
754d3329a6 fix: No extern template declaration for MSVC <12.0 2018-10-15 00:50:48 -07:00
Andreas Schuh
82456f220f fix: Declare FlagRegisterer c’tor explicit template instanations as extern in header 2018-10-15 00:50:48 -07:00
Andreas Schuh
3e2e349307 fix: Declare FALGS_no##name variables as static 2018-10-14 00:16:13 -07:00
Andreas Schuh
c0b1add45f fix: Import with GFLAGS_USE_TARGET_NAMESPACE=ON 2018-09-28 16:28:33 +01:00
Andreas Schuh
f1ea012a41 fix: Import with or without gflags:: namespace 2018-09-28 16:28:33 +01:00
Andreas Schuh
b0c4cd29e4 fix: Define both 'gflags' and 'gflags::gflags' alias targets 2018-09-28 16:28:33 +01:00
Andreas Schuh
04c8ce76e2 fix: Indentation, use spaces instead of real tabs 2018-09-28 16:00:51 +01:00
Andreas Schuh
d4a050d173
Merge pull request #247 from Mizux/master 2018-09-28 14:52:29 +01:00
wuchenghui
48677f930d fix missing-field-initializers warnings on gcc 2018-09-28 14:50:39 +01:00
drillsar
6e536553ef Fix V728 excessive check 2018-09-28 14:49:19 +01:00
kokerf
cad38c919c Set postfixes for generated libraries based on buildtype 2018-09-28 13:23:32 +01:00
Matt Hargett
2c49763b73 Fix build on some clang variants
Some platforms' yval.h defines restrict as a macro when using clang, which causes this file to not compile.
2018-09-28 13:21:24 +01:00
Andreas Schuh
660603a3df doc: Update documentation on how to use Bazel 2018-07-05 23:24:35 +01:00
Andreas Schuh
679df49798 Merge branch 'gh-pages' of github.com:gflags/gflags into gh-pages 2018-07-05 23:23:36 +01:00
Andreas Schuh
48cdc79332 doc: Use of Bazel bind discouraged 2018-07-05 23:23:21 +01:00
Sam Liu
518267d34f Remove installation guide's recommendation to use Bazel's bind(). 2018-07-05 23:17:28 +01:00
Corentin Le Molgat
f7228d77b5 Use CMake namespace gflags:: for export and alias target
Now use gflags::gflags instead of gflags

note: seems already in use in gRPC
cf https://github.com/grpc/grpc/blob/master/cmake/gflags.cmake#L30
2018-01-31 13:46:59 +01:00
Corentin Le Molgat
8b39845d6f Remove uneeded enable_test()
cf https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/CTest.cmake#L88
2018-01-31 13:40:42 +01:00
Corentin Le Molgat
9ab4d115cb Add VERSION to project 2018-01-29 14:00:35 +01:00
Rob Earhart
e292e0452f Use += for appends 2018-01-07 10:40:06 +00:00
Rob Earhart
6d1c363dde Add Bazel-on-Windows support 2018-01-07 10:40:06 +00:00
Silver Chan
77592648e3 repair wrong namespace problem
repair wrong namespace problem
2017-11-03 12:21:22 +00:00
Sumit Gupta
23348465a0 Removed unused functions. 2017-10-08 10:52:46 +01:00
Yi Wang
60784b53e3 Remove using ::fLS::clstring; 2017-09-01 11:12:50 +02:00
Andreas Schuh
57ceb0ecc8 enh: Move CMake defines to separate header, unused by Bazel
This change avoids having to configure a private .h.in file during the Bazel build such that these files are not available to dependent projects in the GENDIR of the external gflags project.
2017-09-01 11:10:03 +02:00
Siddhartha Bagaria
7d36353579 Fix typo in BUILD 2017-08-29 14:51:00 +02:00
Andreas Schuh
aa2d0f7b4e fix: Remove obsolete and unused CleanFileName code 2017-07-13 16:28:54 +01:00
Jason Juang
4663c80d3a cmake: Add convenience uninstall target (#221)
Note: Leaves behind empty directories, no real uninstaller. Just for convenience of some.
2017-07-11 22:22:41 +01:00
Andreas Schuh
46f73f88b1 Release v2.2.1 2017-07-11 18:30:34 +01:00
Andreas Schuh
66d4386d0e enh: AppVeyor builds with different toolchains (copied from gtest project) 2017-07-11 17:47:32 +01:00
Andreas Schuh
6348ea9d7e fix: Check HAVE_STDINT_H or HAVE_INTTYPES_H for older MSVC versions 2017-07-11 17:47:32 +01:00
Andreas Schuh
3d5bc48dc8 git: Ignore symbolic links created by Bazel build tool 2017-07-11 15:32:24 +01:00
Andreas Schuh
74603f5ed3 fix: Static code analyzer error regarding strncmp with empty kRootDir string 2017-07-11 14:47:40 +01:00
Ben Vanik
4a694e8736 Use inttypes.h on VC++ 2013 and up
Warnings will spit out on newer compilers due to PRI* being redefined.
Tested with VC++ 2015 and 2017. [Blog post](https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/) describing the defines being added in 2013.
2017-05-16 11:37:59 +01:00
randomguy3
21c7bcd895 Fix CMake macro special variable usage (#216)
The argument-related variables in a macro body are not real variables,
but special substitutions. They cannot be directly referred to by name,
only expanded.
2017-05-16 11:35:11 +01:00
Mmanu Chaturvedi
95ffb27c9c Fix static initialization order fiasco caused by global registry lock (#215) 2017-05-12 22:11:28 +01:00
Arkady Shapkin
80ebb424a5 Install dll's to correct path (#213) 2017-05-11 13:02:21 +01:00
Arkady Shapkin
652651b421 Fix statically linked gflags library with MSVC
Fix #211
2017-05-06 01:47:54 +01:00
Dan Minor
9314597d4b Mark single argument constructors in mutex.h as explicit. 2017-03-29 13:01:34 +01:00
Razvan Musaloiu-E
48f409438b Removed the unused link to #varz 2017-01-06 11:53:05 +00:00
Geoffrey Lalonde
30dbc81fb5 Changed include directory in bazel build 2017-01-06 11:46:43 +00:00
Andreas Schuh
8935ef4526 enh: Link to online documentation in README 2016-11-29 10:33:53 +00:00
Andreas Schuh
20858a49e0 fix: Enable language C for older CMake versions when needed (#196)
* fix: Enable language C for older CMake versions when needed
* fix: Don’t care about buggy Android toolchain
2016-11-26 21:55:33 +00:00
Andreas Schuh
ac6834e979 fix: Remove unused program_name variable 2016-11-26 21:25:02 +00:00
Andreas Schuh
22ed2ce6c8 fix: Include utils by file instead of CMAKE_MODULE_PATH search 2016-11-26 16:01:46 +00:00
Andreas Schuh
971dd2a4fa doc: Bazel gflags_nothreads target 2016-11-25 18:48:27 +00:00
Andreas Schuh
78c66b3726 doc: Add section on how to use gflags with Bazel 2016-11-25 18:09:44 +00:00
Andreas Schuh
ea1cc83b50 doc: Use of find_package COMPONENTS or inclusion as subproject 2016-03-01 22:00:58 +00:00
Andreas Schuh
16651b7870 #115 Use HTTPS as default Git clone protocol 2016-02-19 13:43:27 +00:00
Andreas Schuh
e1d15b3340 doc: Use "gflags" as link dependency instead of ${gflags_LIBRARIES} 2015-03-25 03:13:22 +00:00
Andreas Schuh
745082dbd3 fix: Example CMake command 2015-03-24 23:09:53 +00:00
Andreas Schuh
73bb1e87c9 fix: GitHub URLs to point to gflags organization 2015-03-24 23:07:20 +00:00
Andreas Schuh
d7a69edf66 doc: Update CMake example and demonstrate use of config options 2015-03-24 19:13:18 +00:00
Andreas Schuh
3398e7b0c9 doc: Remove no longer needed include_directories command from CMake example 2015-03-24 15:04:35 +00:00
Andreas Schuh
957aa3aa62 doc: Add download and issue report instructions to project page 2015-03-24 13:13:50 +00:00
41 changed files with 1527 additions and 454 deletions

51
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,51 @@
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

6
.gitignore vendored
View file

@ -2,6 +2,7 @@
/build/
/builds/
/build-*/
/_build/
.DS_Store
CMakeCache.txt
DartConfiguration.tcl
@ -17,3 +18,8 @@ CMakeFiles/
/test/gflags_unittest-main.cc
/packages/
CMakeLists.txt.user
/bazel-bin
/bazel-genfiles
/bazel-gflags
/bazel-out
/bazel-testlogs

4
.gitmodules vendored
View file

@ -1,4 +0,0 @@
[submodule "doc"]
path = doc
url = https://github.com/gflags/gflags.git
branch = gh-pages

View file

@ -1,20 +0,0 @@
# Ubuntu 14.04 Trusty support, to get newer cmake and compilers.
sudo: required
dist: trusty
language: cpp
os:
- linux
- osx
compiler:
- clang
- gcc
env:
- CONFIG=Release
- CONFIG=Debug
script:
- mkdir out && cd out && cmake -D CMAKE_BUILD_TYPE=$CONFIG -D GFLAGS_BUILD_SHARED_LIBS=ON -D GFLAGS_BUILD_STATIC_LIBS=ON -D GFLAGS_BUILD_TESTING=ON .. && cmake --build . --config $CONFIG && ctest

20
BUILD
View file

@ -4,9 +4,23 @@
licenses(["notice"])
exports_files(["src/gflags_complections.sh", "COPYING.txt"])
exports_files([
"src/gflags_completions.sh",
"COPYING.txt",
])
load(":bazel/gflags.bzl", "gflags_sources", "gflags_library")
(hdrs, srcs) = gflags_sources(namespace=["gflags", "google"])
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)

View file

@ -14,9 +14,9 @@
##
## 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" target is in this case an ALIAS
## 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" library target.
## 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)
@ -26,7 +26,7 @@
## find_package(gflags REQUIRED)
##
## add_executable(foo src/foo.cc)
## target_link_libraries(foo gflags)
## 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)
@ -36,7 +36,7 @@
## find_package(gflags COMPONENTS nothreads_static)
##
## add_executable(foo src/foo.cc)
## target_link_libraries(foo gflags)
## 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)
@ -46,7 +46,7 @@
## add_subdirectory(gflags)
##
## add_executable(foo src/foo.cc)
## target_link_libraries(foo gflags)
## target_link_libraries(foo gflags::gflags)
##
## Variables to configure the source files:
## - GFLAGS_IS_A_DLL
@ -70,34 +70,41 @@
## - GFLAGS_INSTALL_SHARED_LIBS
## - GFLAGS_INSTALL_STATIC_LIBS
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
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
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include (utils)
include ("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
# ----------------------------------------------------------------------------
# package information
set (PACKAGE_NAME "gflags")
set (PACKAGE_VERSION "2.2.0")
set (PACKAGE_VERSION "2.2.2")
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set (PACKAGE_BUGREPORT "https://github.com/gflags/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} CXX)
if (CMAKE_VERSION VERSION_LESS 100)
project (${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES 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. http://www.cmake.org/Bug/view.php?id=14056)
# - FindThreads.cmake (--> CheckIncludeFiles.cmake <--)
# 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 ()
@ -172,6 +179,8 @@ gflags_define (BOOL INSTALL_SHARED_LIBS "Request installation of shared l
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)
@ -225,12 +234,22 @@ endif ()
if (MSVC)
set (HAVE_SYS_TYPES_H 1)
set (HAVE_STDINT_H 1)
set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
set (HAVE_INTTYPES_H 0)
set (HAVE_UNISTD_H 0)
set (HAVE_SYS_STAT_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 ()
foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
string (TOUPPER "${fname}" FNAME)
@ -239,13 +258,13 @@ else ()
check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
endif ()
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
bool_to_int (HAVE_STDINT_H)
bool_to_int (HAVE_SYS_TYPES_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 ()
gflags_define (STRING INTTYPES_FORMAT "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "")
@ -343,6 +362,7 @@ else ()
endif ()
set (PRIVATE_HDRS
"defines.h"
"config.h"
"util.h"
"mutex.h"
@ -393,14 +413,17 @@ if (NOT GFLAGS_IS_SUBPROJECT)
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
if (OS_WINDOWS)
set (RUNTIME_INSTALL_DIR Bin)
set (LIBRARY_INSTALL_DIR Lib)
set (INCLUDE_INSTALL_DIR Include)
set (CONFIG_INSTALL_DIR CMake)
if (OS_WINDOWS AND NOT MINGW)
set (RUNTIME_INSTALL_DIR "bin")
set (LIBRARY_INSTALL_DIR "lib")
set (INCLUDE_INSTALL_DIR "include")
set (CONFIG_INSTALL_DIR "lib/cmake/${PACKAGE_NAME}")
set (PKGCONFIG_INSTALL_DIR)
else ()
set (RUNTIME_INSTALL_DIR bin)
@ -430,8 +453,8 @@ foreach (TYPE IN ITEMS STATIC SHARED)
else ()
set (GFLAGS_IS_A_DLL 0)
endif ()
# filename suffix for static libraries on Windows
if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^STATIC$")
# filename suffix for static libraries on Windows for MSVC toolchain only
if (OS_WINDOWS AND NOT MINGW AND "^${TYPE}$" STREQUAL "^STATIC$")
set (type_suffix "_${type}")
else ()
set (type_suffix "")
@ -481,11 +504,15 @@ if (GFLAGS_IS_SUBPROJECT)
foreach (type IN ITEMS static shared)
foreach (opts IN ITEMS "_nothreads" "")
if (TARGET gflags${opts}_${type})
# Define "gflags" alias for super-projects treating targets of this library as part of their own project
# (also for backwards compatibility with gflags 2.2.1 which only defined this alias)
add_library (gflags ALIAS gflags${opts}_${type})
# Define "gflags::gflags" alias for projects that support both find_package(gflags) and add_subdirectory(gflags)
add_library (gflags::gflags ALIAS gflags${opts}_${type})
break ()
endif ()
endforeach ()
if (TARGET gflags)
if (TARGET gflags::gflags)
break ()
endif ()
endforeach ()
@ -501,14 +528,24 @@ configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-co
if (BUILD_SHARED_LIBS AND INSTALL_SHARED_LIBS)
foreach (opts IN ITEMS "" _nothreads)
if (BUILD_gflags${opts}_LIB)
install (TARGETS gflags${opts}_shared DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT ${EXPORT_NAME})
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 DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT ${EXPORT_NAME})
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 ()
@ -524,21 +561,45 @@ if (INSTALL_HEADERS)
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (EXPORT ${EXPORT_NAME} DESTINATION ${CONFIG_INSTALL_DIR})
if (EXPORT_NAMESPACE_SET)
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)
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}")
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 ()
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${EXPORT_NAME}.cmake")
if (EXPORT_NAMESPACE_SET)
export (
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 ()
@ -551,7 +612,6 @@ configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-con
# testing - MUST follow the generation of the build tree config file
if (BUILD_TESTING)
include (CTest)
enable_testing ()
add_subdirectory (test)
endif ()
@ -571,7 +631,8 @@ if (BUILD_PACKAGING)
"\n BUILD_STATIC_LIBS=ON"
"\n INSTALL_HEADERS=ON"
"\n INSTALL_SHARED_LIBS=ON"
"\n INSTALL_STATIC_LIBS=ON")
"\n INSTALL_STATIC_LIBS=ON"
)
endif ()
# default package generators
@ -683,3 +744,11 @@ if (BUILD_PACKAGING)
include (CPack)
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 ()

View file

@ -1,3 +1,42 @@
* 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 ctor 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
@ -127,8 +166,8 @@
- BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo)
- BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo)
- PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers)
- PORTABILITY: Update deb.sh for more recenty debuilds (csilvers)
- PORTABILITY: #include more headers to satify new gcc's (csilvers)
- PORTABILITY: Update deb.sh for more recently debuilds (csilvers)
- PORTABILITY: #include more headers to satisfy new gcc's (csilvers)
- INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers)
* Fri Oct 3 2008 - Google Inc. <opensource@google.com>
@ -208,7 +247,7 @@
- google-gflags: version 0.5
- Include all m4 macros in the distribution (csilvers)
- Python: Fix broken data_files field in setup.py (sidlon)
- Python: better string serliaizing and unparsing (abo, csimmons)
- Python: better string serializing and unparsing (abo, csimmons)
- Fix checks for NaN and inf to work with Mac OS X (csilvers)
* Thu Apr 19 2007 - Google Inc. <opensource@google.com>

View file

@ -1,18 +1,48 @@
Installing a binary distribution package
========================================
# 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. Please consult
also the package repositories of your Linux distribution.
There may, however, be binary packages available for your operating system.
Please consult also the package repositories of your Linux distribution.
For example on Debian/Ubuntu Linux, gflags can be installed using the
following command:
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:
Compiling the source code with CMake
=========================
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:
@ -65,24 +95,3 @@ GFLAGS_INTTYPES_FORMAT | String identifying format of built-in integer type
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.
Using gflags with [Bazel](http://bazel.io)
=========================
To use gflags in a Bazel 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",
)
bind(
name = "gflags",
actual = "@com_github_gflags_gflags//:gflags",
)
You can then add `//external: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.

4
MODULE.bazel Normal file
View file

@ -0,0 +1,4 @@
module(
name = "gflags",
compatibility_level = 1,
)

View file

@ -1,5 +1,32 @@
[![Build Status](https://travis-ci.org/gflags/gflags.svg?branch=master)](https://travis-ci.org/gflags/gflags)
[![Build status](https://ci.appveyor.com/api/projects/status/4ctod566ysraus74/branch/master?svg=true)](https://ci.appveyor.com/project/schuhschuh/gflags/branch/master)
[![tests](https://github.com/gflags/gflags/actions/workflows/test.yml/badge.svg)](https://github.com/gflags/gflags/actions/workflows/test.yml)
The documentation of the gflags library is available online at https://gflags.github.io/gflags/.
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
----------------
@ -39,7 +66,7 @@ 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 negligable.
this should be negligible.
Please report any further issues using the GitHub issue tracker.

View file

@ -1,43 +0,0 @@
# Configuration for continuous integration service at appveyor.com
shallow_clone: true
# Operating system (build VM template)
os: Visual Studio 2015
# scripts that are called at very beginning, before repo cloning
init:
# clone directory
clone_folder: c:\projects\gflags
matrix:
fast_finish: true
platform:
- Win32
configuration:
- Debug
- Release
install:
# show all available env vars
- set
- echo cmake on AppVeyor, %configuration%-%platform%
- cmake -version
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
build_script:
- cd c:\projects\gflags
- mkdir out && cd out
- cmake -G "Visual Studio 14 2015"
-D CMAKE_BUILD_TYPE=%configuration%
-D GFLAGS_BUILD_TESTING=ON
-D GFLAGS_BUILD_SHARED_LIBS=ON
-D GFLAGS_BUILD_STATIC_LIBS=ON
..
- cmake --build . --config %configuration%
test_script:
- ctest -C %configuration%

View file

@ -0,0 +1,5 @@
cc_binary(
name = "expand_template",
srcs = ["expand_template.cc"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,63 @@
#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;
}

View file

@ -0,0 +1,35 @@
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",
),
},
)

View file

@ -1,92 +1,108 @@
load("//bazel/expanded_template:expanded_template.bzl", "expanded_template")
# ------------------------------------------------------------------------------
# Add native rules to configure source files
def gflags_sources(namespace=["google", "gflags"]):
native.genrule(
name = "config_h",
srcs = ["src/config.h.in"],
outs = ["config.h"],
cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)"
)
native.genrule(
def gflags_sources(namespace = ["google", "gflags"]):
expanded_template(
name = "gflags_declare_h",
srcs = ["src/gflags_declare.h.in"],
outs = ["gflags/gflags_declare.h"],
cmd = ("awk '{ " +
"gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); " +
"gsub(/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@/, \"1\"); " +
"gsub(/@([A-Z0-9_]+)@/, \"0\"); " +
"print; }' $(<) > $(@)")
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)
native.genrule(
name = gflags_ns_h_file.replace('.', '_'),
srcs = ["src/gflags_ns.h.in"],
outs = ["gflags/" + gflags_ns_h_file],
cmd = ("awk '{ " +
"gsub(/@ns@/, \"" + ns + "\"); " +
"gsub(/@NS@/, \"" + ns.upper() + "\"); " +
"print; }' $(<) > $(@)")
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)
native.genrule(
expanded_template(
name = "gflags_h",
srcs = ["src/gflags.h.in"],
outs = ["gflags/gflags.h"],
cmd = ("awk '{ " +
"gsub(/@GFLAGS_ATTRIBUTE_UNUSED@/, \"\"); " +
"gsub(/@INCLUDE_GFLAGS_NS_H@/, \"" + '\n'.join(["#include \\\"gflags/{}\\\"".format(hdr) for hdr in gflags_ns_h_files]) + "\"); " +
"print; }' $(<) > $(@)")
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]),
},
)
native.genrule(
expanded_template(
name = "gflags_completions_h",
srcs = ["src/gflags_completions.h.in"],
outs = ["gflags/gflags_completions.h"],
cmd = "awk '{ gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); print; }' $(<) > $(@)"
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])
hdrs.extend([":" + hdr.replace(".", "_") for hdr in gflags_ns_h_files])
srcs = [
":config_h",
"src/config.h",
"src/gflags.cc",
"src/gflags_completions.cc",
"src/gflags_reporting.cc",
"src/mutex.h",
"src/util.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):
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_UNISTD_H",
"-DHAVE_FNMATCH_H",
"-DHAVE_STRTOLL",
"-DHAVE_STRTOQ",
"-DHAVE_PTHREAD",
"-DHAVE_RWLOCK",
"-DGFLAGS_INTTYPES_FORMAT_C99",
"-DGFLAGS_IS_A_DLL=0",
]
] + select({
"//:x64_windows": [
"-DOS_WINDOWS",
],
"//conditions:default": [
"-DHAVE_UNISTD_H",
"-DHAVE_FNMATCH_H",
"-DHAVE_PTHREAD",
],
})
linkopts = []
if threads:
linkopts.append("-lpthread")
linkopts += select({
"//:android": [],
"//:x64_windows": [],
"//conditions:default": ["-lpthread"],
})
else:
name += "_nothreads"
copts.append("-DNO_THREADS")
copts += ["-DNO_THREADS"]
native.cc_library(
name = name,
hdrs = hdrs,
srcs = srcs,
includes = ["$(GENDIR)"],
copts = copts,
linkopts = linkopts,
visibility = ["//visibility:public"]
name = name,
hdrs = hdrs,
srcs = srcs,
copts = copts,
linkopts = linkopts,
visibility = ["//visibility:public"],
include_prefix = "gflags",
)

View file

@ -0,0 +1,26 @@
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)

View file

@ -7,7 +7,21 @@ set (@PACKAGE_PREFIX@_VERSION_MINOR @PACKAGE_VERSION_MINOR@)
set (@PACKAGE_PREFIX@_VERSION_PATCH @PACKAGE_VERSION_PATCH@)
# import targets
include ("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_NAME@.cmake")
if (NOT DEFINED @PACKAGE_PREFIX@_USE_TARGET_NAMESPACE)
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
get_filename_component (CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
@ -22,8 +36,8 @@ set (@PACKAGE_PREFIX@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
if (@PACKAGE_NAME@_FIND_COMPONENTS)
foreach (@PACKAGE_NAME@_FIND_COMPONENT IN LISTS @PACKAGE_NAME@_FIND_COMPONENTS)
if (@PACKAGE_NAME@_FIND_REQUIRED_${@PACKAGE_NAME@_FIND_COMPONENT} AND NOT TARGET @PACKAGE_NAME@_${@PACKAGE_NAME@_FIND_COMPONENT})
message (FATAL_ERROR "Package @PACKAGE_NAME@ was installed without required component ${@PACKAGE_NAME@_FIND_COMPONENT}!")
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)
@ -49,7 +63,7 @@ if (NOT DEFINED @PACKAGE_PREFIX@_SHARED)
else ()
set (@PACKAGE_PREFIX@_SHARED FALSE)
endif ()
elseif (TARGET @PACKAGE_NAME@_shared OR TARGET @PACKAGE_NAME@_nothreads_shared)
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)
@ -64,7 +78,7 @@ if (NOT DEFINED @PACKAGE_PREFIX@_NOTHREADS)
else ()
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
endif ()
elseif (TARGET @PACKAGE_NAME@_static OR TARGET @PACKAGE_NAME@_shared)
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)
@ -77,15 +91,15 @@ if (NOT @PACKAGE_PREFIX@_TARGET)
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_NAME@_TARGET})
elseif (@PACKAGE_PREFIX@_SHARED)
if (@PACKAGE_PREFIX@_NOTHREADS)
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_nothreads_shared)
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_shared)
else ()
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_shared)
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared)
endif ()
else ()
if (@PACKAGE_PREFIX@_NOTHREADS)
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_nothreads_static)
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_static)
else ()
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_static)
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_static)
endif ()
endif ()
endif ()
@ -94,12 +108,12 @@ if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET})
" Try a different combination of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS.")
endif ()
# add more convenient "@PACKAGE_NAME@" import target
if (NOT TARGET @PACKAGE_NAME@)
# 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_NAME@ SHARED IMPORTED)
add_library (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ SHARED IMPORTED)
else ()
add_library (@PACKAGE_NAME@ STATIC IMPORTED)
add_library (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ STATIC IMPORTED)
endif ()
# copy INTERFACE_* properties
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
@ -112,20 +126,20 @@ if (NOT TARGET @PACKAGE_NAME@)
)
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME})
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
set_target_properties(@PACKAGE_NAME@ PROPERTIES
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_NAME@ PROPERTIES IMPORTED_CONFIGURATIONS "${_@PACKAGE_PREFIX@_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_LANGUAGES
LINK_INTERFACE_MULTIPLICITY
NO_SONAME
SONAME
@ -133,7 +147,7 @@ if (NOT TARGET @PACKAGE_NAME@)
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_NAME@ PROPERTIES
set_target_properties(${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES
IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
)
endif ()

View file

@ -1,7 +1,7 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
bindir=${prefix}/@RUNTIME_INSTALL_DIR@
libdir=${prefix}/@LIBRARY_INSTALL_DIR@
bindir=${exec_prefix}/@RUNTIME_INSTALL_DIR@
libdir=${exec_prefix}/@LIBRARY_INSTALL_DIR@
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
Name: @PACKAGE_NAME@

View file

@ -59,20 +59,24 @@ endmacro ()
# 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)
if (ARGC GREATER 5)
# 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 (GFLAGS_IS_SUBPROJECT AND ARGC EQUAL 5)
set (GFLAGS_${varname} "${ARGV4}")
if (DEFINED ${varname})
set (GFLAGS_${varname} "${${varname}}")
else ()
set (GFLAGS_${varname} "${default}")
if (GFLAGS_IS_SUBPROJECT AND "${ARGC}" EQUAL 5)
set (GFLAGS_${varname} "${ARGV4}")
else ()
set (GFLAGS_${varname} "${default}")
endif ()
endif ()
endif ()
if (GFLAGS_IS_SUBPROJECT)
if (NOT DEFINED ${varname})
set (${varname} "${GFLAGS_${varname}}")
endif ()
set (${varname} "${GFLAGS_${varname}}")
else ()
set (${varname} "${GFLAGS_${varname}}" CACHE ${type} "${docstring}")
endif ()
@ -83,7 +87,9 @@ endmacro ()
macro (gflags_property varname property value)
gflags_is_cached (_cached ${varname})
if (_cached)
if (property STREQUAL ADVANCED)
# 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 ()

1
doc

@ -1 +0,0 @@
Subproject commit 971dd2a4fadac9cdab174c523c22df79efd63aa5

0
doc/.nojekyll Normal file
View file

4
doc/README.md Normal file
View file

@ -0,0 +1,4 @@
To update the GitHub Pages at http://gflags.github.io/gflags/, use command:
```
git subtree push --prefix=doc/ origin gh-pages
```

115
doc/designstyle.css Normal file
View file

@ -0,0 +1,115 @@
body {
background-color: #ffffff;
color: black;
margin-right: 1in;
margin-left: 1in;
}
h1, h2, h3, h4, h5, h6 {
color: #3366ff;
font-family: sans-serif;
}
@media print {
/* Darker version for printing */
h1, h2, h3, h4, h5, h6 {
color: #000080;
font-family: helvetica, sans-serif;
}
}
h1 {
text-align: center;
font-size: 18pt;
}
h2 {
margin-left: -0.5in;
}
h3 {
margin-left: -0.25in;
}
h4 {
margin-left: -0.125in;
}
hr {
margin-left: -1in;
}
/* Definition lists: definition term bold */
dt {
font-weight: bold;
}
address {
text-align: right;
}
/* Use the <code> tag for bits of code and <var> for variables and objects. */
code,pre,samp,var {
color: #006000;
}
/* Use the <file> tag for file and directory paths and names. */
file {
color: #905050;
font-family: monospace;
}
/* Use the <kbd> tag for stuff the user should type. */
kbd {
color: #600000;
}
div.note p {
float: right;
width: 3in;
margin-right: 0%;
padding: 1px;
border: 2px solid #6060a0;
background-color: #fffff0;
}
UL.nobullets {
list-style-type: none;
list-style-image: none;
margin-left: -1em;
}
/*
body:after {
content: "Google Confidential";
}
*/
/* pretty printing styles. See prettify.js */
.str { color: #080; }
.kwd { color: #008; }
.com { color: #800; }
.typ { color: #606; }
.lit { color: #066; }
.pun { color: #660; }
.pln { color: #000; }
.tag { color: #008; }
.atn { color: #606; }
.atv { color: #080; }
pre.prettyprint { padding: 2px; border: 1px solid #888; }
.embsrc { background: #eee; }
@media print {
.str { color: #060; }
.kwd { color: #006; font-weight: bold; }
.com { color: #600; font-style: italic; }
.typ { color: #404; font-weight: bold; }
.lit { color: #044; }
.pun { color: #440; }
.pln { color: #000; }
.tag { color: #006; font-weight: bold; }
.atn { color: #404; }
.atv { color: #060; }
}
/* Table Column Headers */
.hdr {
color: #006;
font-weight: bold;
background-color: #dddddd; }
.hdr2 {
color: #006;
background-color: #eeeeee; }

638
doc/index.html Normal file
View file

@ -0,0 +1,638 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>How To Use Gflags (formerly Google Commandline Flags)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="designstyle.css" type="text/css" rel="stylesheet">
<style type="text/css">
<!--
ol.bluelist li {
color: #3366ff;
font-family: sans-serif;
}
ol.bluelist li p {
color: #000;
font-family: "Times Roman", times, serif;
}
ul.blacklist li {
color: #000;
font-family: "Times Roman", times, serif;
}
//-->
</style>
</head>
<body>
<h1>How To Use gflags (formerly Google Commandline Flags)</h1>
<small>(as of
<script type=text/javascript>
var lm = new Date(document.lastModified);
document.write(lm.toDateString());
</script>)
</small>
<br>
<blockquote><dl>
<dt> Table of contents </dt>
<dd> <a href="#intro">Introduction</a> </dd>
<dd> <a href="#download">Download and Installation</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="#using">Accessing the Flag</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="#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="#default">Changing the Default Flag Value</a> </dd>
<dd> <a href="#special">Special Flags</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>
</dl></blockquote>
<h2> <A NAME=intro>Introduction, and Comparison to Other Commandline
Flags Libraries</A> </h2>
<p><b>Commandline flags</b> are flags that users specify on the
command line when they run an executable. In the command</p>
<pre>
fgrep -l -f /var/tmp/foo johannes brahms
</pre>
<p><code>-l</code> and <code>-f /var/tmp/foo</code> are the two
commandline flags. (<code>johannes</code> and <code>brahms</code>,
which don't start with a dash, are <b>commandline arguments</b>.)</p>
<p>Typically, an application lists what flags the user is allowed to
pass in, and what arguments they take -- in this example,
<code>-l</code> takes no argument, and <code>-f</code> takes a
string (in particular, a filename) as an argument. Users can use a
library to help parse the commandline and store the flags in some data
structure.</p>
<p>Gflags, the commandline flags library used within Google,
differs from other libraries,
such as <code>getopt()</code>, in that flag definitions can be
scattered around the source code, and not just listed in one place
such as <code>main()</code>. In practice, this means that a single
source-code file will define and use flags that are meaningful to that
file. Any application that links in that file will get the flags, and
the gflags library will automatically handle that
flag appropriately.</p>
<p>There's significant gain in flexibility, and ease of code reuse,
due to this technique. However, there is a danger that two files will
define the same flag, and then give an error when they're linked
together.</p>
<p>The rest of this document describes how to use the commandlineflag
library. It's a C++ library, so examples are in C++. However, there
is a Python port with the same functionality, and this discussion
translates directly to Python.</p>
<h2> <A NAME=download>Download and Installation</A> </h2>
<p>The gflags library can be downloaded from <A href="https://github.com/gflags/gflags">GitHub</A>.
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 &lt;prefix&gt;/lib/cmake/gflags directory
containing the gflags-config.cmake file if &lt;prefix&gt; 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>
git_repository(
name = "com_github_gflags_gflags",
remote = "https://github.com/gflags/gflags.git",
tag = "v2.2.2"
)
</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>
<h2> <A name=define>DEFINE: Defining Flags In Program</A> </h2>
<p> Defining a flag is easy: just use the appropriate macro for the
type you want the flag to be, as defined at the bottom of
<code>gflags/gflags.h</code>. Here's an example file,
<code>foo.cc</code>:</p>
<pre>
#include &lt;gflags/gflags.h&gt;
DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
DEFINE_string(languages, "english,french,german",
"comma-separated list of languages to offer in the 'lang' menu");
</pre>
<p><code>DEFINE_bool</code> defines a boolean flag. Here are the
types supported:</p>
<ul>
<li> <code>DEFINE_bool</code>: boolean
<li> <code>DEFINE_int32</code>: 32-bit integer
<li> <code>DEFINE_int64</code>: 64-bit integer
<li> <code>DEFINE_uint64</code>: unsigned 64-bit integer
<li> <code>DEFINE_double</code>: double
<li> <code>DEFINE_string</code>: C++ string
</ul>
<p>Note that there are no 'complex' types like lists: the "languages"
flag in our example is a list of strings, but is defined of type
"string", not "list_of_string" or similar. This is by design. We'd
rather use only simple types for the flags, and allow for complex,
arbitrary parsing routines to parse them, than to try to put the logic
inside the flags library proper.</p>
<p>All DEFINE macros take the same three arguments: the name of the
flag, its default value, and a 'help' string that describes its use.
The 'help' string is displayed when the user runs the application with
the <A HREF="#special"><code>--help</code> flag</A>.</p>
<p>You can define a flag in any source-code file in your executable.
Only define a flag once! If you want to access a flag in more than
one source file, DEFINE it in one file, and <A
HREF="#declare">DECLARE</A> it in the others. Even better, DEFINE it
in <code>foo.cc</code> and DECLARE it in <code>foo.h</code>; then
everyone who <code>#includes foo.h</code> can use the flag.</p>
<p>
Defining flags in libraries rather than in main() is powerful, but
does have some costs. One is that a library might not have a good
default value for its flags, for example if the flag holds a
filename that might not exist in some environments. To mitigate such problems,
you can use <a href="#validate">flag validators</a> to ensure prompt
notification (in the form of a crash) of an invalid flag value.
</p>
<p>Note that while most functions in this library are defined in the
<code>google</code> namespace, <code>DEFINE_foo</code> (and
<code>DECLARE_foo</code>, <A HREF="#declare">below</A>), should always
be in the global namespace.</p>
<h2> <A name=using>Accessing the Flag</A> </h2>
<p>All defined flags are available to the program as just a normal
variable, with the prefix <code>FLAGS_</code> prepended. In the above
example, the macros define two variables, <code>FLAGS_big_menu</code>
(a bool), and <code>FLAGS_languages</code> (a C++ string).</p>
<p>You can read and write to the flag just like any other
variable:</p>
<pre>
if (FLAGS_consider_made_up_languages)
FLAGS_languages += ",klingon"; // implied by --consider_made_up_languages
if (FLAGS_languages.find("finnish") != string::npos)
HandleFinnish();
</pre>
<p>You can also get and set flag values via special functions in
<code>gflags.h</code>. That's a rarer use case, though.</p>
<h2> <A name=declare>DECLARE: Using the Flag in a Different File</A> </h2>
<p>Accessing a flag in the manner of the previous section only works
if the flag was <code>DEFINE</code>-ed at the top of the file. If it
wasn't, you'll get an 'unknown variable' error.</p>
<p>The <code>DECLARE_type</code> macro is available when you want to
use a flag that's defined in another file. For instance, if I were
writing <code>bar.cc</code> but wanted to access the big_menu, flag, I
would put this near the top of <code>bar.cc</code>:</p>
<pre>
DECLARE_bool(big_menu);
</pre>
<p>This is functionally equivalent to saying <code>extern
FLAGS_big_menu</code>.</p>
<p>Note that such an extern declaration introduces a dependency
between your file and the file that defines the <code>big_menu</code>
flag: <code>foo.cc</code>, in this case. Such implicit dependencies
can be difficult to manage in large projects. For that reason we
recommend the following guideline:</p>
<blockquote>
If you DEFINE a flag in <code>foo.cc</code>, either don't DECLARE it
at all, only DECLARE it in tightly related tests, or only DECLARE
it in <code>foo.h</code>.
</blockquote>
<p>You should go the do-not-DECLARE route when the flag is only needed
by <code>foo.cc</code>, and not in any other file. If you want to
modify the value of the flag in the related test file to see if it is
functioning as expected, DECLARE it in the <code>foo_test.cc</code>
file.
<p>If the flag does span multiple files, DECLARE it in the associated
<code>.h</code> file, and make others <code>#include</code> that
<code>.h</code> file if they want to access the flag. The
<code>#include</code> will make explicit the dependency between the
two files. This causes the flag to be a global variable.</p>
<h2> <A name=validate>RegisterFlagValidator: Sanity-checking Flag Values</A> </h2>
<p>After DEFINE-ing a flag, you may optionally register a validator
function with the flag. If you do this, after the flag is parsed from
the commandline, and whenever its value is changed via a call to
<code>SetCommandLineOption()</code>, the validator function is called
with the new value as an argument. The validator function should
return 'true' if the flag value is valid, and false otherwise.
If the function returns false for the new setting of the
flag, the flag will retain its current value. If it returns false for the
default value, ParseCommandLineFlags will die.
<p>Here is an example use of this functionality:</p>
<pre>
static bool ValidatePort(const char* flagname, int32 value) {
if (value > 0 && value < 32768) // value is ok
return true;
printf("Invalid value for --%s: %d\n", flagname, (int)value);
return false;
}
DEFINE_int32(port, 0, "What port to listen on");
DEFINE_validator(port, &ValidatePort);
</pre>
<p>By doing the registration at global initialization time (right
after the DEFINE_int32), we ensure that the registration happens before
the commandline is parsed at the beginning of <code>main()</code>.</p>
<p>The above used <code>DEFINE_validator</code> macro calls the
<code>RegisterFlagValidator()</code> function which returns true if the
registration is successful. It returns false if the registration fails
because a) the first argument does not refer to a commandline flag, or
b) a different validator has already been registered for this flag.
The return value is available as global static boolean variable named
<code>&lt;flag&gt;_validator_registered</code>.</p>
<h2> <A name=together>Putting It Together: How to Set Up Flags</A> </h2>
<p>The final piece is the one that tells the executable to process the
commandline flags, and set the <code>FLAGS_*</code> variables to the
appropriate, non-default value based on what is seen on the
commandline. This is equivalent to the <code>getopt()</code> call in
the getopt library, but has much less overhead to use. In fact, it's
just a single function call:</p>
<pre>
gflags::ParseCommandLineFlags(&argc, &argv, true);
</pre>
<p>Usually, this code is at the beginning of <code>main()</code>.
<code>argc</code> and <code>argv</code> are exactly as passed in to
<code>main()</code>. This routine might modify them, which is why
pointers to them are passed in.</p>
<p>The last argument is called "remove_flags". If true, then
<code>ParseCommandLineFlags</code> removes the flags and their
arguments from <code>argv</code>, and modifies <code>argc</code>
appropriately. In this case, after the function call,
<code>argv</code> will hold only commandline arguments, and not
commandline flags.</p>
<p>If, on the other hand, <code>remove_flags</code> is false, then
<code>ParseCommandLineFlags</code> will leave argc unchanged, but will
rearrange the arguments in argv so that the flags are all at the
beginning. For example, if the input is <code>"/bin/foo" "arg1" "-q"
"arg2"</code> (which is legal but weird), the function will rearrange
<code>argv</code> so it reads <code>"/bin/foo", "-q", "arg1",
"arg2"</code>. In this case, <code>ParseCommandLineFlags</code>
returns the index into argv that holds the first commandline argument:
that is, the index past the last flag. (In this example, it would
return 2, since <code>argv[2]</code> points to <code>arg1</code>.)</p>
<p>In either case, the <code>FLAGS_*</code> variables are modified
based on what was <A HREF="#commandline">passed in on the
commandline</A>.</p>
<h2> <A name=commandline>Setting Flags on the Command Line</A> </h2>
<p>The reason you make something a flag instead of a compile-time
constant, is so users can specify a non-default value on the
commandline. Here's how they might do it for an application that
links in <code>foo.cc</code>:</p>
<pre>
app_containing_foo --nobig_menu -languages="chinese,japanese,korean" ...
</pre>
<p>This sets <code>FLAGS_big_menu = false;</code> and
<code>FLAGS_languages = "chinese,japanese,korean"</code>, when
<code>ParseCommandLineFlags</code> is run.</p>
<p>Note the atypical syntax for setting a boolean flag to false:
putting "no" in front of its name. There's a fair bit of flexibility
to how flags may be specified. Here's an example of all the ways to
specify the "languages" flag:</p>
<ul>
<li> <code>app_containing_foo --languages="chinese,japanese,korean"</code>
<li> <code>app_containing_foo -languages="chinese,japanese,korean"</code>
<li> <code>app_containing_foo --languages "chinese,japanese,korean"</code>
<li> <code>app_containing_foo -languages "chinese,japanese,korean"</code>
</ul>
<p>For boolean flags, the possibilities are slightly different:</p>
<ul>
<li> <code>app_containing_foo --big_menu</code>
<li> <code>app_containing_foo --nobig_menu</code>
<li> <code>app_containing_foo --big_menu=true</code>
<li> <code>app_containing_foo --big_menu=false</code>
</ul>
<p>(as well as the single-dash variant on all of these).</p>
<p>Despite this flexibility, we recommend using only a single form:
<code>--variable=value</code> for non-boolean flags, and
<code>--variable/--novariable</code> for boolean flags. This
consistency will make your code more readable, and is also the format
required for certain special-use cases like <A
HREF="#flagfiles">flagfiles</A>.</p>
<p>It is a fatal error to specify a flag on the commandline that has
not been DEFINED somewhere in the executable. If you need that
functionality for some reason -- say you want to use the same set of
flags for several executables, but not all of them DEFINE every flag
in your list -- you can specify <A
HREF="#special"><code>--undefok</code></A> to suppress the error.</p>
<p>As in getopt(), <code>--</code> by itself will terminate flags
processing. So in <code>foo -f1 1 -- -f2 2</code>, <code>f1</code> is
considered a flag, but <code>-f2</code> is not.</p>
<p>If a flag is specified more than once, only the last specification
is used; the others are ignored.</p>
<p>Note that flags do not have single-letter synonyms, like they do in
the getopt library, nor do we allow "combining" flags behind a
single dash, as in <code>ls -la</code>.</p>
<h2> <A name=default>Changing the Default Flag Value</A> </h2>
<p>Sometimes a flag is defined in a library, and you want to change
its default value in one application but not others. It's simple to
do this: just assign a new value to the flag in <code>main()</code>,
before calling <code>ParseCommandLineFlags()</code>:</p>
<pre>
DECLARE_bool(lib_verbose); // mylib has a lib_verbose flag, default is false
int main(int argc, char** argv) {
FLAGS_lib_verbose = true; // in my app, I want a verbose lib by default
ParseCommandLineFlags(...);
}
</pre>
<p>For this application, users can still set the flag value on the
commandline, but if they do not, the flag's value will default to
true.</p>
<h2> <A name="special">Special Flags</a> </h2>
<p>There are a few flags defined by the commandlineflags module
itself, and are available to all applications that use
commandlineflags. These fall into
three categories. First are the 'reporting' flags that, when found, cause
the application to print some information about itself and exit.</p>
<table><tr valign=top>
<td><code>--help</code></td>
<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>
</tr><tr valign=top>
<td><code>--helpful</code></td>
<td>same as -help, but unambiguously asks for all flags
(in case -help changes in the future)</td>
</tr><tr valign=top>
<td><code>--helpshort</code></td>
<td>shows only flags for the file with the same name as the executable
(usually the one containing <code>main()</code>)</td>
</tr><tr valign=top>
<td><code>--helpxml</code></td>
<td>like --help, but output is in xml for easier parsing</td>
</tr><tr valign=top>
<td><code>--helpon=FILE &nbsp;</code></td>
<td>shows only flags defined in FILE.*</td>
</tr><tr valign=top>
<td><code>--helpmatch=S</code></td>
<td>shows only flags defined in *S*.*</td>
</tr><tr valign=top>
<td><code>--helppackage</code></td>
<td>shows flags defined in files in same directory as <code>main()</code></td>
</tr><tr valign=top>
<td><code>--version</code></td>
<td>prints version info for the executable</td>
</tr></table>
<p>Second are the flags that affect how other flags are parsed.</p>
<table><tr valign=top>
<td><code>--undefok=flagname,flagname,...</code></td>
<td>for those names listed as the argument to <code>--undefok</code>,
suppress the normal error-exit that occurs when
<code>--name</code> is seen on the commandline, but
<code>name</code> has not been DEFINED anywhere in the
application
</table>
<p>Third are the 'recursive' flags, that cause other flag values to be
set: <code>--fromenv</code>, <code>--tryfromenv</code>,
<code>--flagfile</code>. These are described below in more
detail.</p>
<h3> <code>--fromenv</code> </h3>
<p><code>--fromenv=foo,bar</code> says to read the values for the
<code>foo</code> and <code>bar</code> flags from the environment.
In concert with this flag, you must actually set the values in the
environment, via a line like one of the two below:</p>
<pre>
export FLAGS_foo=xxx; export FLAGS_bar=yyy # sh
setenv FLAGS_foo xxx; setenv FLAGS_bar yyy # tcsh
</pre>
<p>This is equivalent to specifying <code>--foo=xxx</code>,
<code>--bar=yyy</code> on the commandline.</p>
<p>Note it is a fatal error to say <code>--fromenv=foo</code> if
<code>foo</code> is not DEFINED somewhere in the application. (Though
you can suppress this error via <code>--undefok=foo</code>, just like
for any other flag.)</p>
<p>It is also a fatal error to say <code>--fromenv=foo</code> if
<code>FLAGS_foo</code> is not actually defined in the environment.</p>
<h3> <code>--tryfromenv</code> </h3>
<p><code>--tryfromenv</code> is exactly like <code>--fromenv</code>,
except it is <b>not</b> a fatal error to say
<code>--tryfromenv=foo</code> if <code>FLAGS_foo</code> is not
actually defined in the environment. Instead, in such cases,
<code>FLAGS_foo</code> just keeps its default value as specified in
the application.</p>
<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>
<h3 id="flagfiles"> <code>--flagfile</code> </h3>
<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
that file as if these flags had been specified on the commandline.</p>
<p>In its simplest form, <code>f</code> should just be a list of flag
assignments, one per line. Unlike on the commandline, the equals sign
separating a flagname from its argument is <i>required</i> for
flagfiles. An example flagfile, <code>/tmp/myflags</code>:</p>
<pre>
--nobig_menus
--languages=english,french
</pre>
<p>With this flagfile, the following two lines are equivalent:<p>
<pre>
./myapp --foo --nobig_menus --languages=english,french --bar
./myapp --foo --flagfile=/tmp/myflags --bar
</pre>
<p>Note that many errors are silently suppressed in flagfiles. In
particular, unrecognized flagnames are silently ignored, as are flags
that are missing a required value (e.g., a flagfile that just says
<code>--languages</code>).</p>
<p>The general format of a flagfile is a bit more complicated than the
simple, common case above. It is: a sequence of filenames, one per
line, followed by a sequence of flags, one per line, repeated as many
times as desired. Filenames in a flagfile can use wildcards
(<code>*</code> and <code>?</code>), and the sequence of flags located
after a sequence of filenames is processed only if the current
executable's name matches one of the filenames. It is possible to
start the flagfile with a sequence of flags instead of a sequence of
filenames; if such a sequence of flags is present, these flags are
applied to the current executable no matter what it is.</p>
<p>Lines that start with a <code>#</code> are ignored as comments.
Leading whitespace is also ignored in flagfiles, as are blank
lines.</p>
<p>It is possible for a flagfile to use the <code>--flagfile</code>
flag to include another flagfile.</p>
<p>Flags are always processed in the expected order. That is,
processing begins by examining the flags specified directly on the
command line. If a flagfile is specified, its contents are processed,
and then processing continues with remaining flags from the command
line.</p>
<h2> <A name="api">The API</a> </h2>
<p>In addition to accessing <code>FLAGS_foo</code> directly, it is
possible to access the flags programmatically, through an API. It is
also possible to access information about a flag, such as its default
value and help-string. A <code>FlagSaver</code> makes it easy to
modify flags and then automatically undo the modifications later.
Finally, there are somewhat unrelated, but useful, routines to easily
access parts of <code>argv</code> outside main, including the program
name (<code>argv[0]</code>).</p>
<p>For more information about these routines, and other useful helper
methods such as <code>gflags::SetUsageMessage()</code> and
<code>gflags::SetVersionString</code>, see <code>gflags.h</code>.</p>
<h2> <A name="misc">Miscellaneous Notes</code> </h2>
<p>If your application has code like this:</p>
<pre>
#define STRIP_FLAG_HELP 1 // this must go before the #include!
#include &lt;gflags/gflags.h&gt;
</pre>
<p>we will remove the help messages from the compiled source. This can
reduce the size of the resulting binary somewhat, and may also be
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>
<address>
Craig Silverstein, Andreas Schuh<br>
<script type=text/javascript>
var lm = new Date(document.lastModified);
document.write(lm.toDateString());
</script>
</address>
</body>
</html>

59
src/config.h Normal file
View file

@ -0,0 +1,59 @@
// 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_

View file

@ -1,114 +0,0 @@
/* 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!
#ifndef GFLAGS_CONFIG_H_
#define GFLAGS_CONFIG_H_
// ---------------------------------------------------------------------------
// 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@
// ---------------------------------------------------------------------------
// 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)
# 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_

48
src/defines.h.in Normal file
View file

@ -0,0 +1,48 @@
/* 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_

View file

@ -90,18 +90,18 @@
#include "config.h"
#include "gflags/gflags.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <cassert>
#include <cctype>
#include <cerrno>
#if defined(HAVE_FNMATCH_H)
# include <fnmatch.h>
#elif defined(HAVE_SHLWAPI_H)
# define NO_SHLWAPI_ISOS
# include <shlwapi.h>
#endif
#include <stdarg.h> // For va_list and related operations
#include <stdio.h>
#include <string.h>
#include <cstdarg> // For va_list and related operations
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
@ -225,7 +225,6 @@ class FlagValue {
bool Equal(const FlagValue& x) const;
FlagValue* New() const; // creates a new one with default value
void CopyFrom(const FlagValue& x);
int ValueSize() const;
// Calls the given validate-fn on value_buffer_, and returns
// whatever it returns. But first casts validate_fn_proto to a
@ -485,23 +484,6 @@ 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(uint32),
sizeof(int64),
sizeof(uint64),
sizeof(double),
sizeof(string),
};
return valuesize[type_];
}
// --------------------------------------------------------------------
// CommandLineFlag
// This represents a single flag, including its name, description,
@ -580,26 +562,14 @@ CommandLineFlag::~CommandLineFlag() {
}
const char* CommandLineFlag::CleanFileName() const {
// Compute top-level directory & file that this appears in
// search full path backwards.
// Stop going backwards at kRootDir; and skip by the first slash.
static const char kRootDir[] = ""; // can set this to root directory,
if (sizeof(kRootDir)-1 == 0) // no prefix to strip
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;
// This function has been used to strip off a common prefix from
// flag source file names. Because flags can be defined in different
// shared libraries, there may not be a single common prefix.
// Further, this functionality hasn't been active for many years.
// Need a better way to produce more user friendly help output or
// "anonymize" file paths in help output, respectively.
// Follow issue at: https://github.com/gflags/gflags/issues/86
return filename();
}
void CommandLineFlag::FillCommandLineFlagInfo(
@ -726,7 +696,6 @@ class FlagRegistry {
static FlagRegistry* global_registry_; // a singleton registry
Mutex lock_;
static Mutex global_registry_lock_;
static void InitGlobalRegistry();
@ -929,10 +898,10 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag,
// Get the singleton FlagRegistry object
FlagRegistry* FlagRegistry::global_registry_ = NULL;
Mutex FlagRegistry::global_registry_lock_(Mutex::LINKER_INITIALIZED);
FlagRegistry* FlagRegistry::GlobalRegistry() {
MutexLock acquire_lock(&global_registry_lock_);
static Mutex lock(Mutex::LINKER_INITIALIZED);
MutexLock acquire_lock(&lock);
if (!global_registry_) {
global_registry_ = new FlagRegistry;
}
@ -973,7 +942,6 @@ class CommandLineFlagParser {
// Stage 3: validate all the commandline flags that have validators
// registered and were not set/modified by ParseNewCommandLineFlags.
void ValidateFlags(bool all);
void ValidateAllFlags();
void ValidateUnmodifiedFlags();
// Stage 4: report any errors and return true if any were found.
@ -1061,9 +1029,6 @@ static string ReadFileIntoString(const char* filename) {
uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
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
registry_->Lock();
@ -1071,17 +1036,15 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
char* arg = (*argv)[i];
// Like getopt(), we permute non-option flags to be at the end.
if (arg[0] != '-' || // must be a program argument
(arg[0] == '-' && arg[1] == '\0')) { // "-" is an argument, not a flag
if (arg[0] != '-' || arg[1] == '\0') { // must be a program argument: "-" is an argument, not a flag
memmove((*argv) + i, (*argv) + i+1, (*argc - (i+1)) * sizeof((*argv)[i]));
(*argv)[*argc-1] = arg; // we go last
first_nonopt--; // we've been pushed onto the stack
i--; // to undo the i++ in the loop
continue;
}
if (arg[0] == '-') arg++; // allow leading '-'
if (arg[0] == '-') arg++; // or leading '--'
arg++; // skip leading '-'
if (arg[0] == '-') arg++; // or leading '--'
// -- alone means what it does for GNU: stop options parsing
if (*arg == '\0') {
@ -1261,10 +1224,6 @@ void CommandLineFlagParser::ValidateFlags(bool all) {
}
}
void CommandLineFlagParser::ValidateAllFlags() {
ValidateFlags(true);
}
void CommandLineFlagParser::ValidateUnmodifiedFlags() {
ValidateFlags(false);
}
@ -1382,8 +1341,8 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked(
|| fnmatch(glob.c_str(), ProgramInvocationName(), FNM_PATHNAME) == 0
|| fnmatch(glob.c_str(), ProgramInvocationShortName(), FNM_PATHNAME) == 0
#elif defined(HAVE_SHLWAPI_H)
|| PathMatchSpec(glob.c_str(), ProgramInvocationName())
|| PathMatchSpec(glob.c_str(), ProgramInvocationShortName())
|| PathMatchSpecA(glob.c_str(), ProgramInvocationName())
|| PathMatchSpecA(glob.c_str(), ProgramInvocationShortName())
#endif
) {
flags_are_relevant = true;

View file

@ -86,7 +86,7 @@
// We always want to export variables defined in user code
#ifndef GFLAGS_DLL_DEFINE_FLAG
# ifdef _MSC_VER
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
# else
# define GFLAGS_DLL_DEFINE_FLAG
@ -223,7 +223,7 @@ extern GFLAGS_DLL_DECL bool GetCommandLineFlagInfo(const char* name, CommandLine
// if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
extern GFLAGS_DLL_DECL CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
enum GFLAGS_DLL_DECL FlagSettingMode {
enum FlagSettingMode {
// update the flag's value (can call this multiple times).
SET_FLAGS_VALUE,
// update the flag's value, but *only if* it has not yet been updated
@ -441,6 +441,27 @@ class GFLAGS_DLL_DECL FlagRegisterer {
FlagType* current_storage, FlagType* 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
// before #including this file, we remove the help message from the
// binary file. This can reduce the size of the resulting binary
@ -478,7 +499,7 @@ extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
static const type FLAGS_nono##name = value; \
/* We always want to export defined variables, dll or no */ \
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
type FLAGS_no##name = FLAGS_nono##name; \
static type FLAGS_no##name = FLAGS_nono##name; \
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
#name, MAYBE_STRIPPED_HELP(help), __FILE__, \
&FLAGS_##name, &FLAGS_no##name); \

View file

@ -39,16 +39,16 @@
// 2a) If there are no matching flags, do nothing.
// 2b) If all matching flags share a common prefix longer than the
// completion word, output just that matching prefix
// 3) Categorize those flags to produce a rough ordering of relevence.
// 3) Categorize those flags to produce a rough ordering of relevance.
// 4) Potentially trim the set of flags returned to a smaller number
// that bash is happier with
// 5) Output the matching flags in groups ordered by relevence.
// 5) Output the matching flags in groups ordered by relevance.
// 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // for strlen
#include <cstdio>
#include <cstdlib>
#include <cstring> // for strlen
#include <set>
#include <string>
@ -170,7 +170,7 @@ static string GetLongFlagLine(
// 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.
// - force_no_update: Any time we output lines, all of which share a
// common prefix, bash will 'helpfully' not even bother to show the
// common prefix, bash will 'helpfuly' not even bother to show the
// output, instead changing the current word to be that common prefix.
// If it's clear this shouldn't happen, we'll set this boolean
struct CompletionOptions {
@ -179,11 +179,16 @@ struct CompletionOptions {
bool flag_description_substring_search;
bool return_all_matching_flags;
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
// reason. For example, flags that are defined in the binary's module
// are expected to be much more relevent than flags defined in some
// are expected to be much more relevant than flags defined in some
// 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
// be placed in any of the 'lower' sets.
@ -202,7 +207,7 @@ struct NotableFlags {
static void PrintFlagCompletionInfo(void) {
string cursor_word = FLAGS_tab_completion_word;
string canonical_token;
CompletionOptions options = { };
CompletionOptions options = CompletionOptions();
CanonicalizeCursorWordAndSearchOptions(
cursor_word,
&canonical_token,
@ -320,12 +325,10 @@ static void CanonicalizeCursorWordAndSearchOptions(
}
break;
}
switch (found_question_marks) { // all fallthroughs
case 3: options->flag_description_substring_search = true;
case 2: options->flag_location_substring_search = true;
case 1: options->flag_name_substring_search = true;
};
if (found_question_marks > 2) options->flag_description_substring_search = true;
if (found_question_marks > 1) options->flag_location_substring_search = true;
if (found_question_marks > 0) options->flag_name_substring_search = true;
options->return_all_matching_flags = (found_plusses > 0);
}
@ -407,7 +410,7 @@ static bool DoesSingleFlagMatch(
// 3) Categorize matches (and helper method)
// Given a set of matching flags, categorize them by
// likely relevence to this specific binary
// likely relevance to this specific binary
static void CategorizeAllMatchingFlags(
const set<const CommandLineFlagInfo *> &all_matches,
const string &search_token,
@ -448,10 +451,6 @@ static void CategorizeAllMatchingFlags(
// In the package, since there was no slash after the package portion
notable_flags->package_flags.insert(*it);
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() &&
pos != string::npos && slash != string::npos) {
// In a subdirectory of the package
@ -545,8 +544,7 @@ static void FinalizeCompletionOutput(
vector<DisplayInfoGroup> output_groups;
bool perfect_match_found = false;
if (lines_so_far < max_desired_lines &&
!notable_flags->perfect_match_flag.empty()) {
if (!notable_flags->perfect_match_flag.empty()) {
perfect_match_found = true;
DisplayInfoGroup group =
{ "",

View file

@ -45,7 +45,7 @@
// handling.
//
// ** Overview of Bash completions:
// Bash can be told to programatically determine completions for the
// Bash can be told to programmatically determine completions for the
// current 'cursor word'. It does this by (in this case) invoking a
// command with some additional arguments identifying the command
// 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
// description as can fit on a single terminal line width, as specified
// by the flag --tab_completion_columns). Furthermore, we'll try to
// make bash order the output such that the most useful or relevent
// make bash order the output such that the most useful or relevant
// flags are the most likely to be shown at the top.
//
// ** Additional features:

View file

@ -58,6 +58,8 @@
#ifndef GFLAGS_DLL_DECL
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
# define GFLAGS_DLL_DECL __declspec(dllimport)
# elif defined(__GNUC__) && __GNUC__ >= 4
# define GFLAGS_DLL_DECL __attribute__((visibility("default")))
# else
# define GFLAGS_DLL_DECL
# endif
@ -67,6 +69,8 @@
#ifndef GFLAGS_DLL_DECLARE_FLAG
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
# elif defined(__GNUC__) && __GNUC__ >= 4
# define GFLAGS_DLL_DECLARE_FLAG __attribute__((visibility("default")))
# else
# define GFLAGS_DLL_DECLARE_FLAG
# endif
@ -144,7 +148,6 @@ typedef std::string clstring;
#define DECLARE_string(name) \
/* We always want to import declared variables, dll or no */ \
namespace fLS { \
using ::fLS::clstring; \
extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \
} \
using fLS::FLAGS_##name

View file

@ -48,10 +48,10 @@
// called after all flag-values have been assigned, that is, after
// parsing the command-line.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cassert>
#include <string>
#include <vector>
@ -63,7 +63,7 @@
// 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 (helpfull, false, "show help on all flags -- same as -help");
DEFINE_bool (helpful, false, "show help on all flags -- same as -help");
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(helpmatch, "", "show help on modules whose name contains the specified substr");
@ -123,7 +123,7 @@ string DescribeOneFlag(const CommandLineFlagInfo& flag) {
flag.description.c_str());
const char* c_string = main_part.c_str();
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?
while (1) {
assert(static_cast<size_t>(chars_left)
@ -275,9 +275,9 @@ static void ShowUsageWithFlagsMatching(const char *argv0,
++flag) {
if (substrings.empty() ||
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 (flag->description == kStrippedFlagHelp) continue;
found_match = true; // this flag passed the match!
if (flag->filename != last_filename) { // new file
if (Dirname(flag->filename) != Dirname(last_filename)) { // new dir!
if (!first_directory)
@ -296,10 +296,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;
if (restrict != NULL && *restrict != '\0') {
substrings.push_back(restrict);
if (restrict_ != NULL && *restrict_ != '\0') {
substrings.push_back(restrict_);
}
ShowUsageWithFlagsMatching(argv0, substrings);
}
@ -353,7 +353,7 @@ static void ShowVersion() {
static void AppendPrognameStrings(vector<string>* substrings,
const char* progname) {
string r("");
string r;
r += PATH_SEPARATOR;
r += progname;
substrings->push_back(r + ".");
@ -383,14 +383,14 @@ void HandleCommandLineHelpFlags() {
ShowUsageWithFlagsMatching(progname, substrings);
gflags_exitfunc(1);
} else if (FLAGS_help || FLAGS_helpfull) {
} else if (FLAGS_help || FLAGS_helpful) {
// show all options
ShowUsageWithFlagsRestrict(progname, ""); // empty restrict
gflags_exitfunc(1);
} else if (!FLAGS_helpon.empty()) {
string restrict = PATH_SEPARATOR + FLAGS_helpon + ".";
ShowUsageWithFlagsRestrict(progname, restrict.c_str());
string restrict_ = PATH_SEPARATOR + FLAGS_helpon + ".";
ShowUsageWithFlagsRestrict(progname, restrict_.c_str());
gflags_exitfunc(1);
} else if (!FLAGS_helpmatch.empty()) {

View file

@ -166,7 +166,7 @@ class Mutex {
// It inhibits work being done by the destructor, which makes it
// safer for code that tries to acqiure this mutex in their global
// destructor.
inline Mutex(LinkerInitialized);
explicit inline Mutex(LinkerInitialized);
// Destructor
inline ~Mutex();
@ -197,7 +197,7 @@ class Mutex {
inline void SetIsSafe() { is_safe_ = true; }
// Catch the error of writing Mutex when intending MutexLock.
Mutex(Mutex* /*ignored*/) {}
explicit Mutex(Mutex* /*ignored*/) {}
// Disallow "evil" constructors
Mutex(const Mutex&);
void operator=(const Mutex&);

View file

@ -77,6 +77,7 @@ extern int GFLAGS_DLL_DECL safe_vsnprintf(char *str, size_t size,
# pragma warning(push)
# pragma warning(disable: 4996) // ignore getenv security warning
#endif
#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
inline void setenv(const char* name, const char* value, int) {
// 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.
@ -98,6 +99,7 @@ inline void setenv(const char* name, const char* value, int) {
*getenv(name) = '\0'; // works when putenv() copies nameval
}
}
#endif
#ifdef _MSC_VER
# pragma warning(pop)
#endif
@ -109,10 +111,14 @@ inline void setenv(const char* name, const char* value, int) {
#define unlink _unlink
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1800
#include <inttypes.h>
#else
#define PRId32 "d"
#define PRIu32 "u"
#define PRId64 "I64d"
#define PRIu64 "I64u"
#endif
#if !defined(__MINGW32__) && !defined(__MINGW64__)
#define strtoq _strtoi64

View file

@ -77,8 +77,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(help=false 0 "PASS" "" gflags_unittest --help=false)
# --helpfull is the same as help
add_gflags_test(helpfull 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helpfull)
# --helpful is the same as help
add_gflags_test(helpful 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helpful)
# --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)
@ -140,8 +140,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(fromenv=help 0 "PASS" "" gflags_unittest --fromenv=help)
add_gflags_test(tryfromenv=help 0 "PASS" "" gflags_unittest --tryfromenv=help)
add_gflags_test(fromenv=helpfull 1 "helpfull not found in environment" "" gflags_unittest --fromenv=helpfull)
add_gflags_test(tryfromenv=helpfull 0 "PASS" "" gflags_unittest --tryfromenv=helpfull)
add_gflags_test(fromenv=helpful 1 "helpful not found in environment" "" gflags_unittest --fromenv=helpful)
add_gflags_test(tryfromenv=helpful 0 "PASS" "" gflags_unittest --tryfromenv=helpful)
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-multiple 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=test_bool,version,unused_bool)
@ -168,6 +168,24 @@ add_executable (gflags_declare_test gflags_declare_test.cc gflags_declare_flags.
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)

View file

@ -1,10 +1,10 @@
## gflags package configuration tests
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
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)
target_link_libraries (foo gflags::gflags)

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os
import sys

View file

@ -1,3 +1,5 @@
// The macro can already be defined when using Unity builds.
#undef GFLAGS_DLL_DECLARE_FLAG
#define GFLAGS_DLL_DECLARE_FLAG
#include <iostream>

View file

@ -5,8 +5,8 @@ void print_message(); // in gflags_declare_flags.cc
int main(int argc, char **argv)
{
gflags::SetUsageMessage("Test compilation and use of gflags_declare.h");
gflags::ParseCommandLineFlags(&argc, &argv, true);
GFLAGS_NAMESPACE::SetUsageMessage("Test compilation and use of gflags_declare.h");
GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
print_message();
return 0;
}

View file

@ -1,6 +1,6 @@
## gflags negative compilation tests
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
if (NOT TEST_NAME)
message (FATAL_ERROR "Missing TEST_NAME CMake flag")