Squashed 'third_party/gflags/' changes from f0523f1..7e70988

7e70988 fix: PVS Studio warnings
754d332 fix: No extern template declaration for MSVC <12.0
82456f2 fix: Declare FlagRegisterer c’tor explicit template instanations as extern in header
3e2e349 fix: Declare FALGS_no##name variables as static
c0b1add fix: Import with GFLAGS_USE_TARGET_NAMESPACE=ON
f1ea012 fix: Import with or without gflags:: namespace
b0c4cd2 fix: Define both 'gflags' and 'gflags::gflags' alias targets
04c8ce7 fix: Indentation, use spaces instead of real tabs
d4a050d Merge pull request #247 from Mizux/master
48677f9 fix missing-field-initializers warnings on gcc
6e53655 Fix V728 excessive check
cad38c9 Set postfixes for generated libraries based on buildtype
2c49763 Fix build on some clang variants
660603a doc: Update documentation on how to use Bazel
518267d Remove installation guide's recommendation to use Bazel's bind().
f7228d7 Use CMake namespace gflags:: for export and alias target
8b39845 Remove uneeded enable_test()
9ab4d11 Add VERSION to project
e292e04 Use += for appends
6d1c363 Add Bazel-on-Windows support
7759264 repair wrong namespace problem
2334846 Removed unused functions.
60784b5 Remove using ::fLS::clstring;
57ceb0e enh: Move CMake defines to separate header, unused by Bazel
7d36353 Fix typo in BUILD
aa2d0f7 fix: Remove obsolete and unused CleanFileName code
4663c80 cmake: Add convenience uninstall target (#221)
46f73f8 Release v2.2.1
66d4386 enh: AppVeyor builds with different toolchains (copied from gtest project)
6348ea9 fix: Check HAVE_STDINT_H or HAVE_INTTYPES_H for older MSVC versions
3d5bc48 git: Ignore symbolic links created by Bazel build tool
74603f5 fix: Static code analyzer error regarding strncmp with empty kRootDir string
4a694e8 Use inttypes.h on VC++ 2013 and up
21c7bcd Fix CMake macro special variable usage (#216)
95ffb27 Fix static initialization order fiasco caused by global registry lock (#215)
80ebb42 Install dll's to correct path (#213)
652651b Fix statically linked gflags library with MSVC
9314597 Mark single argument constructors in mutex.h as explicit.
30dbc81 Changed include directory in bazel build
8935ef4 enh: Link to online documentation in README
20858a4 fix: Enable language C for older CMake versions when needed (#196)
ac6834e fix: Remove unused program_name variable
22ed2ce fix: Include utils by file instead of CMAKE_MODULE_PATH search
f8a0efe Release v2.2.0
2f336a2 doc: //external:gflags_nothreads Bazel target
c6b9377 git: Ignore builds/ subdirectory
84ab952 doc: Update use of gflags with Bazel documentation
b872d6b enh: Bazel BUILD, add WORKSPACE file (#192)
37c4c58 add: Bazel WORKSPACE file
37e2867 enh: Refactored Bazel BUILD rules
8f2c22a Revert "enh: Rename private sources, include public headers with rel path"
ea6144e enh: Rename private sources, include public headers with rel path
86d67a3 fix: Add -lpthread to link Bazel BUILD options (#189)
c94a60e enh: Configure and install pkg-config .pc file
3e7ef74 enh: Set GFLAGS_IS_A_DLL in INTERFACE_COMPILE_DEFINITIONS
1846983 fix: Ensure installation path uses forward slashes
3886da5 enh: Add option to add installation to CMake’s package registry
6c0ee00 fix: Copy missing IMPORTED_IMPLIB_<CONFIG> gflags target property
3064f63 enh: Avoid use of install(EXPORTS) FILE option
14c0e93 Convert dashes to underscores for unknown flags (#177)
cce68f0 Fix error messages to not truncate to 255 characters (#175)
f4eace1 fix: Validate modified flags only once (#173)
408061b fix make error for lacking namespace (#170)
7d31c02 Fix unsigned comparison error in gflags_reporting.cc (#168)
a69b254 Fix Windows linker errors and warnings. (#166)
15394d3 Add shared library build to the AppVeyor CI config. (#167)
e58e530 Remove filter for excluded tests from AppVeyor config. (#165)
435f949 test: Travis CI build static+shared in Release+Debug (#164)
22e4a53 fix: Run strip_flags_binary test only for release configurations (#163)
c713d2e test: Run AppVeyor build via cmake --build and run tests. (#162)
b16653e fix: Typo in gflags_strip_flags_test.cmake script
ec4b5da doc: Add AppVeyor status badge to README
f0be9c8 Add initial AppVeyor config. (#161)
78cab6c doc: Add Travis CI status badge to README
4667f41 Enable Travis CI for Linux and OSX builds (#160)
a5a1b28 Merge pull request #158 from dreamer-dead/use-type-name-enum
7ba9921 Fix wrong type comparison and outdated OfType() usage.
3051942 Fix indentation and remove outdated assert.
3c0ad4f Extract common code from FlagRegisterer to reduce size.
a1e461d Change template FlagValue::OfType() to Type() getter.
46ea10f Do not pass flag type as a char literal when registering a new flag.
fe57e5a Merge pull request #156 from dreamer-dead/fix-flag-value-typename
fa26638 Fix unittests expectations related to uint32.
5ef4c3c Fix uint32 type name.
2e4159f Merge pull request #155 from dreamer-dead/add-missing-reference
3e946c9 Add missing reference symbol to a function parameter.
546819b Merge pull request #152 from Liuchang0812/master
0c17f1e fix bug about LRLF
ac1a925 fix #151: Ubuntu package name in INSTALL instructions
d701cea Merge pull request #150 from LuminateWireless/fix-bazel-build
7ae23fd Add gendir to the include path so that building with bazel doesn't complain config.h can't be found.
8de80b9 Merge pull request #149 from hevy-CC4477/master
eff38cb fix test compilation
9353bca Merge pull request #147 from bazineta/master
81d8a92 Correct FV_MAX_INDEX
eaf0534 Support uint32 as flag type
74bcd20 Merge PR #137 with change of SOVERSION to <major>.<minor>
4534195 fix: Change SOVERSION to <major>.<minor> for 2.x release versions
5e30706 Merge pull request #143 from schuhschuh/fix-bazel-bulid-osx
687b2c5 fix #133: Use awk instead of sed which would require different options on OS X
5844199 Merge pull request #142 from schuhschuh/master
1c8285f mod: Update doc with new find_package COMPONENTS or subproject use
12d810d Merge pull request #141 from schuhschuh/master
389ef3f Merge branch 'master' of github.com:gflags/gflags
752c632 fix: Include order of config.h and gflags.h in unit test
f9e69b3 Merge pull request #140 from schuhschuh/enh-#117-gflags-subproject-support
7a21c16 cmake: Rename targets to gflags[_nothreads]_(static|shared), support find_package COMPONENTS
a4382e5 cmake: Require CMake 2.8.12 in NC tests
2de6bf3 cmake: Change CMake package configuration variable name prefix to GFLAGS_
91e16ee cmake: Add CMake variable to cache only when gflags is not a subproject
b686469 git: Add CMakeLists.txt.user Qt Creator configuration to ignore list
e50698c Merge pull request #139 from schuhschuh/master
18cb422 fix: Require CMake version 2.8.12 in test project
799e910 fix: Include private config.h in gflags_unittest.cc
abe4b10 fix: Package URLs
221f327 Revert "#136 Move test binaries to Testing/bin"
2a3454c fix: DLL import/export defines for unit tests, remove obsolete config_for_unittests.h
545e9df fix: Add missing include guards to gflags/config.h
6bd636c cmake: Clean up static library filename suffix code from PR #126
dd48d70 Merge pull request #126 from hevy-CC4477/master
9ef0d52 enh: Add usage of DEFINE_validator to test project
02f3189 #136 Move test binaries to Testing/bin
92865ce #51 #138 Use std::string instead const char * for global "constants"
8ac4bc4 fix: Pass std::string directly, no need for c_str() call
b90a325 properly export the .so minor version
3ae911f mod: Update doc
762f9cb #51 Call ShutDownCommandLineFlags for (manual) valgrind test
7a69001 #51 Use static StringFlagDestructor to destruct string objects allocated by placement new
3f968fc Merge pull request #133 from earhart/master
40b85b1 Add bazel support
f9fa305 Merge pull request #131 from sbc100/no_threads
b572a72 Define NO_THREADS in when building without threads
03bebcb Merge pull request #129 from Nazg-Gul/master
366e9d3 Fix some compilation warnings with MSVC 2015
4f100cb Resolve several missing declarations warnings
d78b00d handle generation of dynamic and static library on windows.
9db8289 #125 Fix unused typedef/variable warning for static assertion
4e61c45 #124 Remove using namespace from mutex.h

Change-Id: I61f02738b43ce97c825345375af77a44231165f4
git-subtree-dir: third_party/gflags
git-subtree-split: 7e709881881c2663569cd49a93e5c8d9228d868e
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index 9cef463..d039e5c 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -11,7 +11,7 @@
 endmacro ()
 
 # ----------------------------------------------------------------------------
-## Extract version numbers from version string.
+## Extract version numbers from version string
 function (version_numbers version major minor patch)
   if (version MATCHES "([0-9]+)(\\.[0-9]+)?(\\.[0-9]+)?(rc[1-9][0-9]*|[a-z]+)?")
     if (CMAKE_MATCH_1)
@@ -42,6 +42,77 @@
 endfunction ()
 
 # ----------------------------------------------------------------------------
+## Determine if cache entry exists
+macro (gflags_is_cached retvar varname)
+  if (DEFINED ${varname})
+    get_property (${retvar} CACHE ${varname} PROPERTY TYPE SET)
+  else ()
+    set (${retvar} FALSE)
+  endif ()
+endmacro ()
+
+# ----------------------------------------------------------------------------
+## Add gflags configuration variable
+#
+# The default value of the (cached) configuration value can be overridden either
+# on the CMake command-line or the super-project by setting the GFLAGS_<varname>
+# variable. When gflags is a subproject of another project (GFLAGS_IS_SUBPROJECT),
+# the variable is not added to the CMake cache. Otherwise it is cached.
+macro (gflags_define type varname docstring default)
+  # note that ARGC must be expanded here, as it is not a "real" variable
+  # (see the CMake documentation for the macro command)
+  if ("${ARGC}" GREATER 5)
+    message (FATAL_ERROR "gflags_variable: Too many macro arguments")
+  endif ()
+  if (NOT DEFINED GFLAGS_${varname})
+    if (GFLAGS_IS_SUBPROJECT AND "${ARGC}" EQUAL 5)
+      set (GFLAGS_${varname} "${ARGV4}")
+    else ()
+      set (GFLAGS_${varname} "${default}")
+    endif ()
+  endif ()
+  if (GFLAGS_IS_SUBPROJECT)
+    if (NOT DEFINED ${varname})
+      set (${varname} "${GFLAGS_${varname}}")
+    endif ()
+  else ()
+    set (${varname} "${GFLAGS_${varname}}" CACHE ${type} "${docstring}")
+  endif ()
+endmacro ()
+
+# ----------------------------------------------------------------------------
+## Set property of cached gflags configuration variable
+macro (gflags_property varname property value)
+  gflags_is_cached (_cached ${varname})
+  if (_cached)
+    # note that property must be expanded here, as it is not a "real" variable
+    # (see the CMake documentation for the macro command)
+    if ("${property}" STREQUAL "ADVANCED")
+      if (${value})
+        mark_as_advanced (FORCE ${varname})
+      else ()
+        mark_as_advanced (CLEAR ${varname})
+      endif ()
+    else ()
+      set_property (CACHE ${varname} PROPERTY "${property}" "${value}")
+    endif ()
+  endif ()
+  unset (_cached)
+endmacro ()
+
+# ----------------------------------------------------------------------------
+## Modify value of gflags configuration variable
+macro (gflags_set varname value)
+  gflags_is_cached (_cached ${varname})
+  if (_cached)
+    set_property (CACHE ${varname} PROPERTY VALUE "${value}")
+  else ()
+    set (${varname} "${value}")
+  endif ()
+  unset (_cached)
+endmacro ()
+
+# ----------------------------------------------------------------------------
 ## Configure public header files
 function (configure_headers out)
   set (tmp)
@@ -94,3 +165,41 @@
     WORKING_DIRECTORY "${GFLAGS_FLAGFILES_DIR}"
   )
 endmacro ()
+
+# ------------------------------------------------------------------------------
+## Register installed package with CMake
+#
+# This function adds an entry to the CMake registry for packages with the
+# path of the directory where the package configuration file of the installed
+# package is located in order to help CMake find the package in a custom
+# installation prefix. This differs from CMake's export(PACKAGE) command
+# which registers the build directory instead.
+function (register_gflags_package CONFIG_DIR)
+  if (NOT IS_ABSOLUTE "${CONFIG_DIR}")
+    set (CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_DIR}")
+  endif ()
+  string (MD5 REGISTRY_ENTRY "${CONFIG_DIR}")
+  if (WIN32)
+    install (CODE
+      "execute_process (
+         COMMAND reg add \"HKCU\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\" /v \"${REGISTRY_ENTRY}\" /d \"${CONFIG_DIR}\" /t REG_SZ /f
+         RESULT_VARIABLE RT
+         ERROR_VARIABLE  ERR
+         OUTPUT_QUIET
+       )
+       if (RT EQUAL 0)
+         message (STATUS \"Register:   Added HKEY_CURRENT_USER\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\\\\${REGISTRY_ENTRY}\")
+       else ()
+         string (STRIP \"\${ERR}\" ERR)
+         message (STATUS \"Register:   Failed to add registry entry: \${ERR}\")
+       endif ()"
+    )
+  elseif (IS_DIRECTORY "$ENV{HOME}")
+    file (WRITE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry" "${CONFIG_DIR}")
+    install (
+      FILES       "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry"
+      DESTINATION "$ENV{HOME}/.cmake/packages/${PACKAGE_NAME}"
+      RENAME      "${REGISTRY_ENTRY}"
+    )
+  endif ()
+endfunction ()