fix: Change SOVERSION to <major>.<minor> for 2.x release versions
diff --git a/.gitignore b/.gitignore
index 4281522..6429423 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@
 /test/gflags_unittest_main.cc
 /test/gflags_unittest-main.cc
 /packages/
+CMakeLists.txt.user
diff --git a/BUILD b/BUILD
index 3e6d358..d5fc59b 100644
--- a/BUILD
+++ b/BUILD
@@ -47,7 +47,7 @@
     outs = [
         "config.h",
     ],
-    cmd = "sed -r -e 's,^#cmakedefine,// cmakedefine,' $(<) > $(@)",
+    cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)",
 )
 
 genrule(
@@ -58,7 +58,7 @@
     outs = [
         "gflags.h",
     ],
-    cmd = "sed -r -e 's/@[A-Z_]+@//' $(<) > $(@)",
+    cmd = "awk '{ gsub(/@(GFLAGS_ATTRIBUTE_UNUSED|INCLUDE_GFLAGS_NS_H)@/, \"\"); print; }' $(<) > $(@)",
 )
 
 genrule(
@@ -69,7 +69,7 @@
     outs = [
         "gflags_completions.h",
     ],
-    cmd = "sed -r -e 's/@GFLAGS_NAMESPACE@/gflags/' $(<) > $(@)",
+    cmd = "awk '{ gsub(/@GFLAGS_NAMESPACE@/, \"gflags\"); print; }' $(<) > $(@)",
 )
 
 genrule(
@@ -80,12 +80,11 @@
     outs = [
         "gflags_declare.h",
     ],
-    cmd = ("sed -r -e '" +
-           "s/@GFLAGS_NAMESPACE@/gflags/;" +
-           "s/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H" +
-           "|GFLAGS_INTTYPES_FORMAT_C99)@/1/;" +
-           "s/@([A-Z0-9_]+)@/0/" +
-           "' $(<) > $(@)"),
+    cmd = ("awk '{ " +
+           "gsub(/@GFLAGS_NAMESPACE@/, \"gflags\"); " +
+           "gsub(/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@/, \"1\"); " +
+           "gsub(/@([A-Z0-9_]+)@/, \"0\"); " +
+           "print; }' $(<) > $(@)"),
 )
 
 genrule(
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e9e315..14cdb90 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,75 @@
+## CMake configuration file of gflags project
+##
+## This CMakeLists.txt defines some gflags specific configuration variables
+## using the "gflags_define" utility macro. The default values of these variables
+## can be overridden either on the CMake command-line using the -D option of
+## the cmake command or in a super-project which includes the gflags source
+## tree by setting the GFLAGS_<varname> CMake variables before adding the
+## gflags source directory via CMake's "add_subdirectory" command. Only when
+## the non-cached variable GFLAGS_IS_SUBPROJECT has a value equivalent to FALSE,
+## these configuration variables are added to the CMake cache so they can be
+## edited in the CMake GUI. By default, GFLAGS_IS_SUBPROJECT is set to TRUE when
+## the CMAKE_SOURCE_DIR is not identical to the directory of this CMakeLists.txt
+## file, i.e., the top-level directory of the gflags project source tree.
+##
+## When this project is a subproject (GFLAGS_IS_SUBPROJECT is TRUE), the default
+## settings are such that only the static single-threaded library is built without
+## installation of the gflags files. The "gflags" 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.
+##
+## Example CMakeLists.txt of user project which requires separate gflags installation:
+##   cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+##
+##   project(Foo)
+##
+##   find_package(gflags REQUIRED)
+##
+##   add_executable(foo src/foo.cc)
+##   target_link_libraries(foo gflags)
+##
+## Example CMakeLists.txt of user project which requires separate single-threaded static gflags installation:
+##   cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+##
+##   project(Foo)
+##
+##   find_package(gflags COMPONENTS nothreads_static)
+##
+##   add_executable(foo src/foo.cc)
+##   target_link_libraries(foo gflags)
+##
+## Example CMakeLists.txt of super-project which contains gflags source tree:
+##   cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+##
+##   project(Foo)
+##
+##   add_subdirectory(gflags)
+##
+##   add_executable(foo src/foo.cc)
+##   target_link_libraries(foo gflags)
+##
+## Variables to configure the source files:
+## - GFLAGS_IS_A_DLL
+## - GFLAGS_NAMESPACE
+## - GFLAGS_ATTRIBUTE_UNUSED
+## - GFLAGS_INTTYPES_FORMAT
+##
+## Variables to configure the build:
+## - GFLAGS_SOVERSION
+## - GFLAGS_BUILD_SHARED_LIBS
+## - GFLAGS_BUILD_STATIC_LIBS
+## - GFLAGS_BUILD_gflags_LIB
+## - GFLAGS_BUILD_gflags_nothreads_LIB
+## - GFLAGS_BUILD_TESTING
+## - GFLAGS_BUILD_PACKAGING
+##
+## Variables to configure the installation:
+## - GFLAGS_INCLUDE_DIR
+## - GFLAGS_LIBRARY_INSTALL_DIR or LIB_INSTALL_DIR or LIB_SUFFIX
+## - GFLAGS_INSTALL_HEADERS
+## - GFLAGS_INSTALL_SHARED_LIBS
+## - GFLAGS_INSTALL_STATIC_LIBS
+
 cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
 
 if (POLICY CMP0042)
@@ -15,7 +87,7 @@
 set (PACKAGE_VERSION   "2.2.0")
 set (PACKAGE_STRING    "${PACKAGE_NAME} ${PACKAGE_VERSION}")
 set (PACKAGE_TARNAME   "${PACKAGE_NAME}-${PACKAGE_VERSION}")
-set (PACKAGE_BUGREPORT "https://github.com/schuhschuh/gflags/issues")
+set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues")
 
 project (${PACKAGE_NAME} CXX)
 if (CMAKE_VERSION VERSION_LESS 100)
@@ -34,17 +106,41 @@
     PACKAGE_VERSION_PATCH
 )
 
-set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
+# shared library ABI version number, can be overridden by package maintainers
+# using -DGFLAGS_SOVERSION=XXX on the command-line
+if (GFLAGS_SOVERSION)
+  set (PACKAGE_SOVERSION "${GFLAGS_SOVERSION}")
+else ()
+  # TODO: Change default SOVERSION back to PACKAGE_VERSION_MAJOR with the
+  #       next increase of major version number (i.e., 3.0.0 -> SOVERSION 3)
+  #       The <major>.<minor> SOVERSION should be used for the 2.x releases
+  #       versions only which temporarily broke the API by changing the default
+  #       namespace from "google" to "gflags".
+  set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
+endif ()
+
+# when gflags is included as subproject (e.g., as Git submodule/subtree) in the source
+# tree of a project that uses it, no variables should be added to the CMake cache;
+# users may set the non-cached variable GFLAGS_IS_SUBPROJECT before add_subdirectory(gflags)
+if (NOT DEFINED GFLAGS_IS_SUBPROJECT)
+  if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
+    set (GFLAGS_IS_SUBPROJECT FALSE)
+  else ()
+    set (GFLAGS_IS_SUBPROJECT TRUE)
+  endif ()
+endif ()
+
+# prefix for package variables in CMake configuration file
+string (TOUPPER "${PACKAGE_NAME}" PACKAGE_PREFIX)
 
 # ----------------------------------------------------------------------------
 # options
-if (NOT GFLAGS_NAMESPACE)
-  # maintain binary backwards compatibility with gflags library version <= 2.0,
-  # but at the same time enable the use of the preferred new "gflags" namespace
-  set (GFLAGS_NAMESPACE "google;${PACKAGE_NAME}" CACHE STRING "Name(s) of library namespace (separate multiple options by semicolon)")
-  mark_as_advanced (GFLAGS_NAMESPACE)
-endif ()
-set (GFLAGS_NAMESPACE_SECONDARY "${GFLAGS_NAMESPACE}")
+
+# maintain binary backwards compatibility with gflags library version <= 2.0,
+# but at the same time enable the use of the preferred new "gflags" namespace
+gflags_define (STRING NAMESPACE "Name(s) of library namespace (separate multiple options by semicolon)" "google;${PACKAGE_NAME}" "${PACKAGE_NAME}")
+gflags_property (NAMESPACE ADVANCED TRUE)
+set (GFLAGS_NAMESPACE_SECONDARY "${NAMESPACE}")
 list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY)
 if (NOT GFLAGS_NAMESPACE_SECONDARY)
   message (FATAL_ERROR "GFLAGS_NAMESPACE must be set to one (or more) valid C++ namespace identifier(s separated by semicolon \";\").")
@@ -57,46 +153,54 @@
 list (GET       GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE)
 list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0)
 
-option (BUILD_SHARED_LIBS          "Request build of shared libraries."                                       OFF)
-option (BUILD_STATIC_LIBS          "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF)
-option (BUILD_gflags_LIB           "Request build of the multi-threaded gflags library."                      ON)
-option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library."                     ON)
-option (BUILD_PACKAGING            "Enable build of distribution packages using CPack."                       OFF)
-option (BUILD_TESTING              "Enable build of the unit tests and their execution using CTest."          OFF)
-option (INSTALL_HEADERS            "Request packaging of headers and other development files."                ON)
+# cached build options when gflags is not a subproject, otherwise non-cached CMake variables
+# usage: gflags_define(BOOL <name> <doc> <default> [<subproject default>])
+gflags_define (BOOL BUILD_SHARED_LIBS          "Request build of shared libraries."                                       OFF OFF)
+gflags_define (BOOL BUILD_STATIC_LIBS          "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF ON)
+gflags_define (BOOL BUILD_gflags_LIB           "Request build of the multi-threaded gflags library."                      ON  OFF)
+gflags_define (BOOL BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library."                     ON  ON)
+gflags_define (BOOL BUILD_PACKAGING            "Enable build of distribution packages using CPack."                       OFF OFF)
+gflags_define (BOOL BUILD_TESTING              "Enable build of the unit tests and their execution using CTest."          OFF OFF)
+gflags_define (BOOL INSTALL_HEADERS            "Request installation of headers and other development files."             ON  OFF)
+gflags_define (BOOL INSTALL_SHARED_LIBS        "Request installation of shared libraries."                                ON  ON)
+gflags_define (BOOL INSTALL_STATIC_LIBS        "Request installation of static libraries."                                ON  OFF)
 
-mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)
-mark_as_advanced (CMAKE_CONFIGURATION_TYPES
-                  BUILD_STATIC_LIBS
-                  INSTALL_HEADERS)
-if (APPLE)
-  mark_as_advanced(CMAKE_OSX_ARCHITECTURES
-                   CMAKE_OSX_DEPLOYMENT_TARGET
-                   CMAKE_OSX_SYSROOT)
-endif ()
+gflags_property (BUILD_STATIC_LIBS   ADVANCED TRUE)
+gflags_property (INSTALL_HEADERS     ADVANCED TRUE)
+gflags_property (INSTALL_SHARED_LIBS ADVANCED TRUE)
+gflags_property (INSTALL_STATIC_LIBS ADVANCED TRUE)
+
+if (NOT GFLAGS_IS_SUBPROJECT)
+  foreach (varname IN ITEMS CMAKE_INSTALL_PREFIX)
+    gflags_property (${varname} ADVANCED FALSE)
+  endforeach ()
+  foreach (varname IN ITEMS CMAKE_CONFIGURATION_TYPES CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
+    gflags_property (${varname} ADVANCED TRUE)
+  endforeach ()
+  if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
+    gflags_set (CMAKE_BUILD_TYPE Release)
+  endif ()
+  if (CMAKE_CONFIGURATION_TYPES)
+    gflags_property (CMAKE_BUILD_TYPE STRINGS "${CMAKE_CONFIGURATION_TYPES}")
+  endif ()
+endif () # NOT GFLAGS_IS_SUBPROJECT
 
 if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
   set (BUILD_STATIC_LIBS ON)
 endif ()
 if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
- message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")
+  message (FATAL_ERROR "At least one of [GFLAGS_]BUILD_gflags_LIB and [GFLAGS_]BUILD_gflags_nothreads_LIB must be ON.")
 endif ()
 
-if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
-  set_property (CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
+gflags_define (STRING INCLUDE_DIR "Name of include directory of installed header files relative to CMAKE_INSTALL_PREFIX/include/" "${PACKAGE_NAME}")
+gflags_property (INCLUDE_DIR ADVANCED TRUE)
+if (IS_ABSOLUTE INCLUDE_DIR)
+  message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include/")
 endif ()
-
-if (NOT GFLAGS_INCLUDE_DIR)
-  set (GFLAGS_INCLUDE_DIR "${PACKAGE_NAME}" CACHE STRING "Name of include directory of installed header files")
-  mark_as_advanced (GFLAGS_INCLUDE_DIR)
-else ()
-  if (IS_ABSOLUTE GFLAGS_INCLUDE_DIR)
-    message (FATAL_ERROR "GFLAGS_INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include")
-  endif ()
-  if (GFLAGS_INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
-    message (FATAL_ERROR "GFLAGS_INCLUDE_DIR must not start with parent directory reference (../)")
-  endif ()
+if (INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
+  message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must not start with parent directory reference (../)")
 endif ()
+set (GFLAGS_INCLUDE_DIR "${INCLUDE_DIR}")
 
 # ----------------------------------------------------------------------------
 # system checks
@@ -135,10 +239,10 @@
   endif ()
 endif ()
 
-set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
-set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")
-mark_as_advanced (GFLAGS_INTTYPES_FORMAT)
-if (NOT GFLAGS_INTTYPES_FORMAT)
+gflags_define (STRING INTTYPES_FORMAT "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "")
+gflags_property (INTTYPES_FORMAT STRINGS "C99;BSD;VC7")
+gflags_property (INTTYPES_FORMAT ADVANCED TRUE)
+if (NOT INTTYPES_FORMAT)
   set (TYPES uint32_t u_int32_t)
   if (MSVC)
     list (INSERT TYPES 0 __int32)
@@ -150,29 +254,30 @@
     endif ()
   endforeach ()
   if (HAVE_uint32_t)
-    set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)
+    gflags_set (INTTYPES_FORMAT C99)
   elseif (HAVE_u_int32_t)
-    set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)
+    gflags_set (INTTYPES_FORMAT BSD)
   elseif (HAVE___int32)
-    set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
+    gflags_set (INTTYPES_FORMAT VC7)
   else ()
-    mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)
+    gflags_property (INTTYPES_FORMAT ADVANCED FALSE)
     message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
                          " Neither uint32_t, u_int32_t, nor __int32 seem to be available."
-                         " Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
+                         " Set [GFLAGS_]INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
   endif ()
 endif ()
 # use of special characters in strings to circumvent bug #0008226
-if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")
-  set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
+if ("^${INTTYPES_FORMAT}$" STREQUAL "^WIN$")
+  gflags_set (INTTYPES_FORMAT VC7)
 endif ()
-if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
-  message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
+if (NOT INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
+  message (FATAL_ERROR "Invalid value for [GFLAGS_]INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
 endif ()
+set (GFLAGS_INTTYPES_FORMAT "${INTTYPES_FORMAT}")
 set (GFLAGS_INTTYPES_FORMAT_C99 0)
 set (GFLAGS_INTTYPES_FORMAT_BSD 0)
 set (GFLAGS_INTTYPES_FORMAT_VC7 0)
-set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)
+set ("GFLAGS_INTTYPES_FORMAT_${INTTYPES_FORMAT}" 1)
 
 if (MSVC)
   set (HAVE_strtoll 0)
@@ -184,26 +289,29 @@
   endif ()
 endif ()
 
-set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
-find_package (Threads)
-if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
-  set (HAVE_PTHREAD 1)
-  check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
+if (BUILD_gflags_LIB)
+  set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
+  find_package (Threads)
+  if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
+    set (HAVE_PTHREAD 1)
+    check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
+  else ()
+    set (HAVE_PTHREAD 0)
+  endif ()
+  if (UNIX AND NOT HAVE_PTHREAD)
+    if (CMAKE_HAVE_PTHREAD_H)
+      set (what "library")
+    else ()
+      set (what ".h file")
+    endif ()
+    message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
+                         "\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
+                         "\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
+  endif ()
 else ()
   set (HAVE_PTHREAD 0)
 endif ()
 
-if (UNIX AND NOT HAVE_PTHREAD AND BUILD_gflags_LIB)
-  if (CMAKE_HAVE_PTHREAD_H)
-    set (what "library")
-  else ()
-    set (what ".h file")
-  endif ()
-  message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
-                       "\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
-                       "\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
-endif ()
-
 # ----------------------------------------------------------------------------
 # source files - excluding root subdirectory and/or .in suffix
 set (PUBLIC_HDRS
@@ -244,19 +352,23 @@
 
 # ----------------------------------------------------------------------------
 # configure source files
-if (CMAKE_COMPILER_IS_GNUCXX)
-  set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
-else ()
-  set (GFLAGS_ATTRIBUTE_UNUSED)
+if (NOT DEFINED GFLAGS_ATTRIBUTE_UNUSED)
+  if (CMAKE_COMPILER_IS_GNUCXX)
+    set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
+  else ()
+    set (GFLAGS_ATTRIBUTE_UNUSED)
+  endif ()
 endif ()
 
 # whenever we build a shared library (DLL on Windows), configure the public
 # headers of the API for use of this library rather than the optionally
 # also build statically linked library; users can override GFLAGS_DLL_DECL
-if (BUILD_SHARED_LIBS)
-  set (GFLAGS_IS_A_DLL 1)
-else ()
-  set (GFLAGS_IS_A_DLL 0)
+if (NOT DEFINED GFLAGS_IS_A_DLL)
+  if (BUILD_SHARED_LIBS)
+    set (GFLAGS_IS_A_DLL 1)
+  else ()
+    set (GFLAGS_IS_A_DLL 0)
+  endif ()
 endif ()
 
 configure_headers (PUBLIC_HDRS  ${PUBLIC_HDRS})
@@ -265,9 +377,11 @@
 
 # ----------------------------------------------------------------------------
 # output directories
-set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
-set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
-set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
+if (NOT GFLAGS_IS_SUBPROJECT)
+  set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
+  set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
+  set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
+endif ()
 
 # ----------------------------------------------------------------------------
 # installation directories
@@ -281,13 +395,11 @@
   # The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora
   # package maintainers. Also package maintainers of other distribution
   # packages need to be able to specify the name of the library directory.
-  if (NOT LIB_INSTALL_DIR)
-    set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
+  if (NOT GFLAGS_LIBRARY_INSTALL_DIR AND LIB_INSTALL_DIR)
+    set (GFLAGS_LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}")
   endif ()
-  set (LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}"
-    CACHE PATH "Directory of installed libraries, e.g., \"lib64\""
-  )
-  mark_as_advanced (LIBRARY_INSTALL_DIR)
+  gflags_define (PATH LIBRARY_INSTALL_DIR "Directory of installed libraries, e.g., \"lib64\"" "lib${LIB_SUFFIX}")
+  gflags_property (LIBRARY_INSTALL_DIR ADVANCED TRUE)
   set (INCLUDE_INSTALL_DIR include)
   set (CONFIG_INSTALL_DIR  ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME})
 endif ()
@@ -298,22 +410,28 @@
 # static vs. shared
 foreach (TYPE IN ITEMS STATIC SHARED)
   if (BUILD_${TYPE}_LIBS)
+    string (TOLOWER "${TYPE}" type)
     # whether or not targets are a DLL
     if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$")
       set (GFLAGS_IS_A_DLL 1)
     else ()
       set (GFLAGS_IS_A_DLL 0)
     endif ()
-    string (TOLOWER "${TYPE}" type)
+    # filename suffix for static libraries on Windows
+    if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^STATIC$")
+      set (type_suffix "_${type}")
+    else ()
+      set (type_suffix "")
+    endif ()
     # multi-threaded vs. single-threaded
     foreach (opts IN ITEMS "" _nothreads)
       if (BUILD_gflags${opts}_LIB)
-        add_library (gflags${opts}-${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
+        add_library (gflags${opts}_${type} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
         set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>")
         if (INSTALL_HEADERS)
           list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")
         endif ()
-        target_include_directories (gflags${opts}-${type}
+        target_include_directories (gflags${opts}_${type}
           PUBLIC  "${include_dirs}"
           PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}"
         )
@@ -322,35 +440,67 @@
         else ()
           set (defines "GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL}")
           if (CMAKE_USE_PTHREADS_INIT)
-            target_link_libraries (gflags${opts}-${type} ${CMAKE_THREAD_LIBS_INIT})
+            target_link_libraries (gflags${opts}_${type} ${CMAKE_THREAD_LIBS_INIT})
           endif ()
         endif ()
         set_target_properties (
-          gflags${opts}-${type} PROPERTIES COMPILE_DEFINITIONS "${defines}"
-                                           OUTPUT_NAME         "gflags${opts}"
+          gflags${opts}_${type} PROPERTIES COMPILE_DEFINITIONS "${defines}"
+                                           OUTPUT_NAME         "gflags${opts}${type_suffix}"
                                            VERSION             "${PACKAGE_VERSION}"
                                            SOVERSION           "${PACKAGE_SOVERSION}"
         )
         if (HAVE_SHLWAPI_H)
-          target_link_libraries (gflags${opts}-${type} shlwapi.lib)
+          target_link_libraries (gflags${opts}_${type} shlwapi.lib)
         endif ()
-        if (NOT TARGET gflags${opts})
-          add_custom_target (gflags${opts})
+        list (APPEND TARGETS gflags${opts}_${type})
+        # add convenience make target for build of both shared and static libraries
+        if (NOT GFLAGS_IS_SUBPROJECT)
+          if (NOT TARGET gflags${opts})
+            add_custom_target (gflags${opts})
+          endif ()
+          add_dependencies (gflags${opts} gflags${opts}_${type})
         endif ()
-        add_dependencies (gflags${opts} gflags${opts}-${type})
-        list (APPEND TARGETS gflags${opts}-${type})
       endif ()
     endforeach ()
   endif ()
 endforeach ()
 
+# add ALIAS target for use in super-project, prefer static over shared, single-threaded over multi-threaded
+if (GFLAGS_IS_SUBPROJECT)
+  foreach (type IN ITEMS static shared)
+    foreach (opts IN ITEMS "_nothreads" "")
+      if (TARGET gflags${opts}_${type})
+        add_library (gflags ALIAS gflags${opts}_${type})
+        break ()
+      endif ()
+    endforeach ()
+    if (TARGET gflags)
+       break ()
+    endif ()
+  endforeach ()
+endif ()
+
 # ----------------------------------------------------------------------------
 # installation rules
 file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
 configure_file (cmake/config.cmake.in  "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
 configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
 
-install (TARGETS ${TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
+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 gflags-lib)
+    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 gflags-lib)
+    endif ()
+  endforeach ()
+endif ()
+
 if (INSTALL_HEADERS)
   install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR})
   install (
@@ -362,7 +512,7 @@
     FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
     DESTINATION ${CONFIG_INSTALL_DIR}
   )
-  install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
+  install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-targets.cmake)
   if (UNIX)
     install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
   endif ()
@@ -371,7 +521,7 @@
 # ----------------------------------------------------------------------------
 # support direct use of build tree
 set (INSTALL_PREFIX_REL2CONFIG_DIR .)
-export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
+export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-targets.cmake")
 export (PACKAGE gflags)
 configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
 
@@ -393,10 +543,13 @@
                      "\n  BUILD_SHARED_LIBS=ON"
                      "\n  BUILD_STATIC_LIBS=OFF"
                      "\n  INSTALL_HEADERS=OFF"
+                     "\n  INSTALL_SHARED_LIBS=ON"
                      "\nRecommended options for generation of development package:"
                      "\n  BUILD_SHARED_LIBS=ON"
                      "\n  BUILD_STATIC_LIBS=ON"
-                     "\n  INSTALL_HEADERS=ON")
+                     "\n  INSTALL_HEADERS=ON"
+                     "\n  INSTALL_SHARED_LIBS=ON"
+                     "\n  INSTALL_STATIC_LIBS=ON")
   endif ()
 
   # default package generators
@@ -439,7 +592,7 @@
   # RPM package information -- used in cmake/package.cmake.in also for DEB
   set (CPACK_RPM_PACKAGE_GROUP   "Development/Libraries")
   set (CPACK_RPM_PACKAGE_LICENSE "BSD")
-  set (CPACK_RPM_PACKAGE_URL     "http://schuhschuh.github.com/gflags")
+  set (CPACK_RPM_PACKAGE_URL     "http://gflags.github.io/gflags")
   set (CPACK_RPM_CHANGELOG_FILE  "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
 
   if (INSTALL_HEADERS)
diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in
index a7419c2..6b55990 100644
--- a/cmake/config.cmake.in
+++ b/cmake/config.cmake.in
@@ -1,13 +1,13 @@
 ## gflags CMake configuration file
 
 # library version information
-set (@PACKAGE_NAME@_VERSION_STRING "@PACKAGE_VERSION@")
-set (@PACKAGE_NAME@_VERSION_MAJOR  @PACKAGE_VERSION_MAJOR@)
-set (@PACKAGE_NAME@_VERSION_MINOR  @PACKAGE_VERSION_MINOR@)
-set (@PACKAGE_NAME@_VERSION_PATCH  @PACKAGE_VERSION_PATCH@)
+set (@PACKAGE_PREFIX@_VERSION_STRING "@PACKAGE_VERSION@")
+set (@PACKAGE_PREFIX@_VERSION_MAJOR  @PACKAGE_VERSION_MAJOR@)
+set (@PACKAGE_PREFIX@_VERSION_MINOR  @PACKAGE_VERSION_MINOR@)
+set (@PACKAGE_PREFIX@_VERSION_PATCH  @PACKAGE_VERSION_PATCH@)
 
 # import targets
-include ("${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-export.cmake")
+include ("${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-targets.cmake")
 
 # installation prefix
 get_filename_component (CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
@@ -18,94 +18,151 @@
 # Newer versions of CMake set the INTERFACE_INCLUDE_DIRECTORIES property
 # of the imported targets. It is hence not necessary to add this path
 # manually to the include search path for targets which link to gflags.
-set (@PACKAGE_NAME@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
+set (@PACKAGE_PREFIX@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
 
-# default settings
-if (NOT DEFINED @PACKAGE_NAME@_SHARED)
-  if (TARGET @PACKAGE_NAME@-static OR TARGET @PACKAGE_NAME@_nothreads-static)
-    set (@PACKAGE_NAME@_SHARED FALSE)
+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}!")
+    endif ()
+  endforeach ()
+  list (GET @PACKAGE_NAME@_FIND_COMPONENTS 0 @PACKAGE_NAME@_FIND_COMPONENT)
+else ()
+  set (@PACKAGE_NAME@_FIND_COMPONENT)
+endif ()
+
+# default settings of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS
+#
+# It is recommended to use either one of the following find_package commands
+# instead of setting the @PACKAGE_PREFIX@_(SHARED|NOTHREADS) variables:
+# - find_package(@PACKAGE_NAME@ REQUIRED)
+# - find_package(@PACKAGE_NAME@ COMPONENTS nothreads_static)
+# - find_package(@PACKAGE_NAME@ COMPONENTS nothreads_shared)
+# - find_package(@PACKAGE_NAME@ COMPONENTS static)
+# - find_package(@PACKAGE_NAME@ COMPONENTS shared)
+if (NOT DEFINED @PACKAGE_PREFIX@_SHARED)
+  if (DEFINED @PACKAGE_NAME@_SHARED)
+    set (@PACKAGE_PREFIX@_SHARED ${@PACKAGE_NAME@_SHARED})
+  elseif (@PACKAGE_NAME@_FIND_COMPONENT)
+    if (@PACKAGE_NAME@_FIND_COMPONENT MATCHES "shared")
+      set (@PACKAGE_PREFIX@_SHARED TRUE)
+    else ()
+      set (@PACKAGE_PREFIX@_SHARED FALSE)
+    endif ()
+  elseif (TARGET @PACKAGE_NAME@_shared OR TARGET @PACKAGE_NAME@_nothreads_shared)
+    set (@PACKAGE_PREFIX@_SHARED TRUE)
   else ()
-    set (@PACKAGE_NAME@_SHARED TRUE)
+    set (@PACKAGE_PREFIX@_SHARED FALSE)
   endif ()
 endif ()
-if (NOT DEFINED @PACKAGE_NAME@_NOTHREADS)
-  if (TARGET @PACKAGE_NAME@-static OR TARGET @PACKAGE_NAME@-shared)
-    set (@PACKAGE_NAME@_NOTHREADS FALSE)
+if (NOT DEFINED @PACKAGE_PREFIX@_NOTHREADS)
+  if (DEFINED @PACKAGE_NAME@_NOTHREADS)
+    set (@PACKAGE_PREFIX@_NOTHREADS ${@PACKAGE_NAME@_NOTHREADS})
+  elseif (@PACKAGE_NAME@_FIND_COMPONENT)
+    if (@PACKAGE_NAME@_FIND_COMPONENT MATCHES "nothreads")
+      set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
+    else ()
+      set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
+    endif ()
+  elseif (TARGET @PACKAGE_NAME@_static OR TARGET @PACKAGE_NAME@_shared)
+    set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
   else ()
-    set (@PACKAGE_NAME@_NOTHREADS TRUE)
+    set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
   endif ()
 endif ()
 
 # choose imported library target
-if (NOT @PACKAGE_NAME@_TARGET)
-  if (@PACKAGE_NAME@_SHARED)
-    if (@PACKAGE_NAME@_NOTHREADS)
-      set (@PACKAGE_NAME@_TARGET @PACKAGE_NAME@_nothreads-shared)
+if (NOT @PACKAGE_PREFIX@_TARGET)
+  if (@PACKAGE_NAME@_TARGET)
+    set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_NAME@_TARGET})
+  elseif (@PACKAGE_PREFIX@_SHARED)
+    if (@PACKAGE_PREFIX@_NOTHREADS)
+      set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_nothreads_shared)
     else ()
-      set (@PACKAGE_NAME@_TARGET @PACKAGE_NAME@-shared)
+      set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_shared)
     endif ()
   else ()
-    if (@PACKAGE_NAME@_NOTHREADS)
-      set (@PACKAGE_NAME@_TARGET @PACKAGE_NAME@_nothreads-static)
+    if (@PACKAGE_PREFIX@_NOTHREADS)
+      set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_nothreads_static)
     else ()
-      set (@PACKAGE_NAME@_TARGET @PACKAGE_NAME@-static)
+      set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_static)
     endif ()
   endif ()
 endif ()
-if (NOT TARGET ${@PACKAGE_NAME@_TARGET})
-  message (FATAL_ERROR "Your @PACKAGE_NAME@ installation does not contain a ${@PACKAGE_NAME@_TARGET} library target!"
-                       " Try a different combination of @PACKAGE_NAME@_SHARED and @PACKAGE_NAME@_NOTHREADS.")
+if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET})
+  message (FATAL_ERROR "Your @PACKAGE_NAME@ installation does not contain a ${@PACKAGE_PREFIX@_TARGET} library target!"
+                       " Try a different combination of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS.")
 endif ()
 
 # add more convenient "@PACKAGE_NAME@" import target
 if (NOT TARGET @PACKAGE_NAME@)
-  if (@PACKAGE_NAME@_SHARED)
+  if (@PACKAGE_PREFIX@_SHARED)
     add_library (@PACKAGE_NAME@ SHARED IMPORTED)
   else ()
     add_library (@PACKAGE_NAME@ STATIC IMPORTED)
   endif ()
-  # INTERFACE_INCLUDE_DIRECTORIES
-  get_target_property (_@PACKAGE_NAME@_INCLUDES ${@PACKAGE_NAME@_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
-  if (_@PACKAGE_NAME@_INCLUDES)
-    set_target_properties(@PACKAGE_NAME@ PROPERTIES
-      INTERFACE_INCLUDE_DIRECTORIES "${_@PACKAGE_NAME@_INCLUDES}"
-    )
-  endif ()
-  unset (_@PACKAGE_NAME@_INCLUDES)
-  # set configuration specific properties
-  get_target_property (_@PACKAGE_NAME@_CONFIGURATIONS ${@PACKAGE_NAME@_TARGET} IMPORTED_CONFIGURATIONS)
-  set_target_properties (@PACKAGE_NAME@ PROPERTIES IMPORTED_CONFIGURATIONS "${_@PACKAGE_NAME@_CONFIGURATIONS}")
-  foreach (_@PACKAGE_NAME@_CONFIG IN LISTS _@PACKAGE_NAME@_CONFIGURATIONS)
-    # IMPORTED_LOCATION_<config>
-    get_target_property (_@PACKAGE_NAME@_LOCATION ${@PACKAGE_NAME@_TARGET} IMPORTED_LOCATION_${_@PACKAGE_NAME@_CONFIG})
-    if (_@PACKAGE_NAME@_LOCATION)
+  # copy INTERFACE_* properties
+  foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
+    COMPILE_DEFINITIONS
+    COMPILE_FEATURES
+    COMPILE_OPTIONS
+    INCLUDE_DIRECTORIES
+    LINK_LIBRARIES
+    POSITION_INDEPENDENT_CODE
+  )
+    get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME})
+    if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
       set_target_properties(@PACKAGE_NAME@ PROPERTIES
-        IMPORTED_LOCATION_${_@PACKAGE_NAME@_CONFIG} "${_@PACKAGE_NAME@_LOCATION}"
+        INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
       )
     endif ()
-    unset (_@PACKAGE_NAME@_LOCATION)
-    # IMPORTED_LINK_INTERFACE_LANGUAGES_<config> (static)
-    get_target_property (_@PACKAGE_NAME@_LANGUAGES ${@PACKAGE_NAME@_TARGET} IMPORTED_LINK_INTERFACE_LANGUAGES_${_@PACKAGE_NAME@_CONFIG})
-    if (_@PACKAGE_NAME@_LANGUAGES)
-      set_target_properties(@PACKAGE_NAME@ PROPERTIES
-        IMPORTED_LINK_INTERFACE_LANGUAGES_${_@PACKAGE_NAME@_CONFIG} "${_@PACKAGE_NAME@_LANGUAGES}"
-      )
-    endif ()
-    unset (_@PACKAGE_NAME@_LANGUAGES)
-    # IMPORTED_SONAME_<config> (shared)
-    get_target_property (_@PACKAGE_NAME@_SONAME ${@PACKAGE_NAME@_TARGET} IMPORTED_SONAME_${_@PACKAGE_NAME@_CONFIG})
-    if (_@PACKAGE_NAME@_SONAME)
-      set_target_properties(@PACKAGE_NAME@ PROPERTIES
-        IMPORTED_SONAME_${_@PACKAGE_NAME@_CONFIG} "${_@PACKAGE_NAME@_SONAME}"
-      )
-    endif ()
-    unset (_@PACKAGE_NAME@_SONAME)
   endforeach ()
-  unset (_@PACKAGE_NAME@_CONFIGURATIONS)
+  # 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}")
+  foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
+    LOCATION
+    LINK_DEPENDENT_LIBRARIES
+    LINK_INTERFACE_LIBRARIES
+    LINK_INTERFACE_LANGUAGES 
+    LINK_INTERFACE_MULTIPLICITY
+    NO_SONAME
+    SONAME
+  )
+    foreach (_@PACKAGE_PREFIX@_CONFIG IN LISTS _@PACKAGE_PREFIX@_CONFIGURATIONS)
+      get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG})
+      if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
+        set_target_properties(@PACKAGE_NAME@ PROPERTIES
+          IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
+        )
+      endif ()
+    endforeach ()
+  endforeach ()
+  unset (_@PACKAGE_PREFIX@_CONFIGURATIONS)
+  unset (_@PACKAGE_PREFIX@_CONFIG)
+  unset (_@PACKAGE_PREFIX@_PROPERTY_NAME)
+  unset (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
 endif ()
 
 # alias for default import target to be compatible with older CMake package configurations
-set (@PACKAGE_NAME@_LIBRARIES "${@PACKAGE_NAME@_TARGET}")
+set (@PACKAGE_PREFIX@_LIBRARIES "${@PACKAGE_PREFIX@_TARGET}")
+
+# set @PACKAGE_NAME@_* variables for backwards compatibility
+if (NOT "^@PACKAGE_NAME@$" STREQUAL "^@PACKAGE_PREFIX@$")
+  foreach (_@PACKAGE_PREFIX@_VARIABLE IN ITEMS
+    VERSION_STRING
+    VERSION_MAJOR
+    VERSION_MINOR
+    VERSION_PATCH
+    INCLUDE_DIR
+    LIBRARIES
+    TARGET
+  )
+    set (@PACKAGE_NAME@_${_@PACKAGE_PREFIX@_VARIABLE} "${@PACKAGE_PREFIX@_${_@PACKAGE_PREFIX@_VARIABLE}}")
+  endforeach ()
+  unset (_@PACKAGE_PREFIX@_VARIABLE)
+endif ()
 
 # unset private variables
+unset (@PACKAGE_NAME@_FIND_COMPONENT)
 unset (_INSTALL_PREFIX)
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index 9cef463..038baf3 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,73 @@
 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)
+  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)
+    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)
diff --git a/doc b/doc
index 16651b7..ea1cc83 160000
--- a/doc
+++ b/doc
@@ -1 +1 @@
-Subproject commit 16651b78706e7ac3a1697146dd3b41f885ac73f1
+Subproject commit ea1cc83b50dc44df1f38891d9c95e99e2f127a80
diff --git a/src/config.h.in b/src/config.h.in
index a8708da..ee92210 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -2,6 +2,10 @@
 
 // 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
 
@@ -110,3 +114,6 @@
 #  endif
 #  include "windows_port.h"
 #endif
+
+
+#endif // GFLAGS_CONFIG_H_
diff --git a/src/gflags.cc b/src/gflags.cc
index a35bbfe..85b1ef7 100644
--- a/src/gflags.cc
+++ b/src/gflags.cc
@@ -1454,65 +1454,58 @@
 
 // These values are not protected by a Mutex because they are normally
 // set only once during program startup.
-static const char* argv0 = "UNKNOWN";      // just the program name
-static const char* cmdline = "";           // the entire command-line
+static string argv0("UNKNOWN");  // just the program name
+static string cmdline;           // the entire command-line
+static string program_usage;
 static vector<string> argvs;
 static uint32 argv_sum = 0;
-static const char* program_usage = NULL;
 
 void SetArgv(int argc, const char** argv) {
   static bool called_set_argv = false;
-  if (called_set_argv)         // we already have an argv for you
-    return;
-
+  if (called_set_argv) return;
   called_set_argv = true;
 
-  assert(argc > 0);            // every program has at least a progname
-  argv0 = strdup(argv[0]);     // small memory leak, but fn only called once
-  assert(argv0);
+  assert(argc > 0); // every program has at least a name
+  argv0 = argv[0];
 
-  string cmdline_string;       // easier than doing strcats
+  cmdline.clear();
   for (int i = 0; i < argc; i++) {
-    if (i != 0) {
-      cmdline_string += " ";
-    }
-    cmdline_string += argv[i];
+    if (i != 0) cmdline += " ";
+    cmdline += argv[i];
     argvs.push_back(argv[i]);
   }
-  cmdline = strdup(cmdline_string.c_str());  // another small memory leak
-  assert(cmdline);
 
   // Compute a simple sum of all the chars in argv
-  for (const char* c = cmdline; *c; c++)
+  argv_sum = 0;
+  for (string::const_iterator c = cmdline.begin(); c != cmdline.end(); ++c) {
     argv_sum += *c;
+  }
 }
 
 const vector<string>& GetArgvs() { return argvs; }
-const char* GetArgv()            { return cmdline; }
-const char* GetArgv0()           { return argv0; }
+const char* GetArgv()            { return cmdline.c_str(); }
+const char* GetArgv0()           { return argv0.c_str(); }
 uint32 GetArgvSum()              { return argv_sum; }
 const char* ProgramInvocationName() {             // like the GNU libc fn
   return GetArgv0();
 }
 const char* ProgramInvocationShortName() {        // like the GNU libc fn
-  const char* slash = strrchr(argv0, '/');
+  size_t pos = argv0.rfind('/');
 #ifdef OS_WINDOWS
-  if (!slash)  slash = strrchr(argv0, '\\');
+  if (pos == string::npos) pos = argv0.rfind('\\');
 #endif
-  return slash ? slash + 1 : argv0;
+  return (pos == string::npos ? argv0.c_str() : (argv0.c_str() + pos + 1));
 }
 
 void SetUsageMessage(const string& usage) {
-  if (program_usage != NULL)
-    ReportError(DIE, "ERROR: SetUsageMessage() called twice\n");
-  program_usage = strdup(usage.c_str());      // small memory leak
+  program_usage = usage;
 }
 
 const char* ProgramUsage() {
-  if (program_usage) {
-    return program_usage;
+  if (program_usage.empty()) {
+    return "Warning: SetUsageMessage() never called";
   }
-  return "Warning: SetUsageMessage() never called";
+  return program_usage.c_str();
 }
 
 // --------------------------------------------------------------------
@@ -1520,16 +1513,14 @@
 // VersionString()
 // --------------------------------------------------------------------
 
-static const char* version_string = NULL;
+static string version_string;
 
 void SetVersionString(const string& version) {
-  if (version_string != NULL)
-    ReportError(DIE, "ERROR: SetVersionString() called twice\n");
-  version_string = strdup(version.c_str());   // small memory leak
+  version_string = version;
 }
 
 const char* VersionString() {
-  return version_string ? version_string : "";
+  return version_string.c_str();
 }
 
 
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 77b582f..2119943 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -22,9 +22,9 @@
   set (type static)
 endif ()
 if (BUILD_gflags_LIB)
-  link_libraries (gflags-${type})
+  link_libraries (gflags_${type})
 else ()
-  link_libraries (gflags_nothreads-${type})
+  link_libraries (gflags_nothreads_${type})
 endif ()
 
 # ----------------------------------------------------------------------------
diff --git a/test/config/CMakeLists.txt b/test/config/CMakeLists.txt
index b5bc282..c54f54b 100644
--- a/test/config/CMakeLists.txt
+++ b/test/config/CMakeLists.txt
@@ -1,6 +1,6 @@
 ## gflags package configuration tests
 
-cmake_minimum_required (VERSION 2.8)
+cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
 
 project (gflags_${TEST_NAME})
 
diff --git a/test/config/main.cc b/test/config/main.cc
index 5edd9a1..3c033e3 100644
--- a/test/config/main.cc
+++ b/test/config/main.cc
@@ -3,9 +3,16 @@
 
 DEFINE_string(message, "Hello World!", "The message to print");
 
+static bool ValidateMessage(const char* flagname, const std::string &message)
+{
+  return !message.empty();
+}
+DEFINE_validator(message, ValidateMessage);
+
 int main(int argc, char **argv)
 {
   gflags::SetUsageMessage("Test CMake configuration of gflags library (gflags-config.cmake)");
+  gflags::SetVersionString("0.1");
   gflags::ParseCommandLineFlags(&argc, &argv, true);
   std::cout << FLAGS_message << std::endl;
   gflags::ShutDownCommandLineFlags();
diff --git a/test/config_for_unittests.h b/test/config_for_unittests.h
deleted file mode 100644
index 914571b..0000000
--- a/test/config_for_unittests.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2007, Google Inc.
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-// 
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// All Rights Reserved.
-//
-//
-// This file is needed for windows -- unittests are not part of the
-// gflags dll, but still want to include config.h just like the
-// dll does, so they can use internal tools and APIs for testing.
-//
-// The problem is that config.h declares GFLAGS_DLL_DECL to be
-// for exporting symbols, but the unittest needs to *import* symbols
-// (since it's not the dll).
-//
-// The solution is to have this file, which is just like config.h but
-// sets GFLAGS_DLL_DECL to do a dllimport instead of a dllexport.
-//
-// The reason we need this extra GFLAGS_DLL_DECL_FOR_UNITTESTS
-// variable is in case people want to set GFLAGS_DLL_DECL explicitly
-// to something other than __declspec(dllexport).  In that case, they
-// may want to use something other than __declspec(dllimport) for the
-// unittest case.  For that, we allow folks to define both
-// GFLAGS_DLL_DECL and GFLAGS_DLL_DECL_FOR_UNITTESTS explicitly.
-//
-// NOTE: This file is equivalent to config.h on non-windows systems,
-// which never defined GFLAGS_DLL_DECL_FOR_UNITTESTS and always
-// define GFLAGS_DLL_DECL to the empty string.
-
-#include "config.h"
-
-#ifdef GFLAGS_DLL_DECL
-#  undef GFLAGS_DLL_DECL
-#endif
-#ifdef GFLAGS_DLL_DEFINE_FLAG
-#  undef GFLAGS_DLL_DEFINE_FLAG
-#endif
-#ifdef GFLAGS_DLL_DECLARE_FLAG
-#  undef GFLAGS_DLL_DECLARE_FLAG
-#endif
-
-#ifdef GFLAGS_DLL_DECL_FOR_UNITTESTS
-#  define GFLAGS_DLL_DECL  GFLAGS_DLL_DECL_FOR_UNITTESTS
-#else
-#  define GFLAGS_DLL_DECL  // if DLL_DECL_FOR_UNITTESTS isn't defined, use ""
-#endif
-
-// Import flags defined by gflags.cc
-#if GFLAGS_IS_A_DLL && defined(_MSC_VER)
-#  define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
-#else
-#  define GFLAGS_DLL_DECLARE_FLAG
-#endif
\ No newline at end of file
diff --git a/test/gflags_declare_flags.cc b/test/gflags_declare_flags.cc
old mode 100644
new mode 100755
index 2491686..3d952a8
--- a/test/gflags_declare_flags.cc
+++ b/test/gflags_declare_flags.cc
@@ -1,3 +1,5 @@
+#define GFLAGS_DLL_DECLARE_FLAG
+
 #include <iostream>
 #include <gflags/gflags_declare.h>
 
diff --git a/test/gflags_strip_flags_test.cc b/test/gflags_strip_flags_test.cc
old mode 100644
new mode 100755
index 25ef53a..143f0c6
--- a/test/gflags_strip_flags_test.cc
+++ b/test/gflags_strip_flags_test.cc
@@ -34,7 +34,6 @@
 // script that runs 'strings' over this program and makes sure
 // that the help string is not in there.
 
-#include "config_for_unittests.h"
 #define STRIP_FLAG_HELP 1
 #include <gflags/gflags.h>
 
diff --git a/test/gflags_unittest.cc b/test/gflags_unittest.cc
old mode 100644
new mode 100755
index cc3049b..427af8c
--- a/test/gflags_unittest.cc
+++ b/test/gflags_unittest.cc
@@ -32,9 +32,11 @@
 // For now, this unit test does not cover all features of
 // gflags.cc
 
-#include "config_for_unittests.h"
 #include <gflags/gflags.h>
 
+#include "config.h"
+#include "util.h"
+
 #include <math.h>       // for isinf() and isnan()
 #include <stdio.h>
 #include <stdlib.h>
@@ -44,7 +46,6 @@
 #endif
 #include <vector>
 #include <string>
-#include "util.h"
 TEST_INIT
 EXPECT_DEATH_INIT
 
@@ -1514,7 +1515,7 @@
   // The non-recommended way:
   FLAGS_changed_bool2 = true;
 
-  SetUsageMessage(usage_message.c_str());
+  SetUsageMessage(usage_message);
   SetVersionString("test_version");
   ParseCommandLineFlags(&argc, &argv, true);
   MakeTmpdir(&FLAGS_test_tmpdir);
diff --git a/test/nc/CMakeLists.txt b/test/nc/CMakeLists.txt
index e425d91..d00b07d 100644
--- a/test/nc/CMakeLists.txt
+++ b/test/nc/CMakeLists.txt
@@ -1,6 +1,6 @@
 ## gflags negative compilation tests
 
-cmake_minimum_required (VERSION 2.8)
+cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
 
 if (NOT TEST_NAME)
   message (FATAL_ERROR "Missing TEST_NAME CMake flag")
@@ -13,4 +13,4 @@
 include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/..")
 add_definitions (-DTEST_${TEST_NAME_UPPER})
 add_executable (gflags_${TEST_NAME} gflags_nc.cc)
-target_link_libraries(gflags_${TEST_NAME} ${gflags_LIBRARIES})
+target_link_libraries(gflags_${TEST_NAME} gflags)