diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2aa5ceca540721ada026983915a23bdad5310f5d..9228947b667e0802d988f05893a8394e32f15e73 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,9 +73,9 @@ endif ()
 # ----------------------------------------------------------------------------
 # source files - excluding root subdirectory and/or .in suffix
 set (PUBLIC_HDRS
-  "gflags/gflags.h"
-  "gflags/gflags_declare.h"
-  "gflags/gflags_completions.h"
+  "gflags.h"
+  "gflags_declare.h"
+  "gflags_completions.h"
 )
 
 set (PRIVATE_HDRS
@@ -96,23 +96,22 @@ else ()
   set (__ATTRIBUTE__UNUSED)
 endif ()
 
-function (configure_sources out subdir)
+function (configure_sources out)
   set (tmp)
   foreach (src IN LISTS ARGN)
-    set (src "${subdir}/${src}")
-    if (EXISTS "${PROJECT_SOURCE_DIR}/${src}.in")
-      configure_file ("${PROJECT_SOURCE_DIR}/${src}.in" "${PROJECT_BINARY_DIR}/${src}" @ONLY)
-      list (APPEND tmp "${PROJECT_BINARY_DIR}/${src}")
+    if (src MATCHES ".h$" AND EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
+      configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}" @ONLY)
+      list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}/${src}")
     else ()
-      list (APPEND tmp "${PROJECT_SOURCE_DIR}/${src}")
+      list (APPEND tmp "${PROJECT_SOURCE_DIR}/src/${src}")
     endif ()
   endforeach ()
   set (${out} "${tmp}" PARENT_SCOPE)
 endfunction ()
 
-configure_sources (PUBLIC_HDRS  include ${PUBLIC_HDRS})
-configure_sources (PRIVATE_HDRS src     ${PRIVATE_HDRS})
-configure_sources (GFLAGS_SRCS  src     ${GFLAGS_SRCS})
+configure_sources (PUBLIC_HDRS  ${PUBLIC_HDRS})
+configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
+configure_sources (GFLAGS_SRCS  ${GFLAGS_SRCS})
 
 # ----------------------------------------------------------------------------
 # output directories
@@ -122,20 +121,14 @@ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
 
 # ----------------------------------------------------------------------------
 # add library target
-include_directories (
-  "${PROJECT_BINARY_DIR}/include"
-  "${PROJECT_SOURCE_DIR}/include"
-  "${PROJECT_BINARY_DIR}/src"
-  "${PROJECT_SOURCE_DIR}/src"
-)
-
 if (WIN32)
   add_definitions (-DGFLAGS_DLL_EXPORT)
 endif ()
-
+include_directories ("${PROJECT_BINARY_DIR}/include")
+include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
 add_library (gflags ${GFLAGS_SRCS})
 
 # ----------------------------------------------------------------------------
 # installation
 install (TARGETS gflags DESTINATION lib)
-install (FILES ${PUBLIC_HDRS} DESTINATION include/gflags)
+install (FILES ${PUBLIC_HDRS} DESTINATION include/${GFLAGS_NAMESPACE})
diff --git a/src/config.h.in b/src/config.h.in
index 811f8ff8caf5265b6145a90e9939b61620146326..0f966f3bb310cb361dd78a680c078de20706b843 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -55,6 +55,11 @@
 // Define to 1 if you have the <pthread.h> header file.
 #define HAVE_PTHREAD @HAVE_PTHREAD@
 
+// gcc requires this to get PRId64, etc.
+#if HAVE_INTTYPES_H && !defined(__STDC_FORMAT_MACROS)
+#  define __STDC_FORMAT_MACROS 1
+#endif
+
 // ---------------------------------------------------------------------------
 // Path separator
 #ifndef PATH_SEPARATOR
diff --git a/src/gflags.cc b/src/gflags.cc
index dc8254770d2c6a2350b4006a1bd7f3948c9b55b1..6c3c93e35e3d1d272d403e58ecff008c41bc095c 100644
--- a/src/gflags.cc
+++ b/src/gflags.cc
@@ -87,18 +87,14 @@
 // other hand, hooks into CommandLineFlagParser.  Other API functions
 // are, similarly, mostly hooks into the functionality described above.
 
-// This comes first to ensure we define __STDC_FORMAT_MACROS in time.
-#include <config.h>
-#if HAVE_INTTYPES_H && !defined(__STDC_FORMAT_MACROS)
-# define __STDC_FORMAT_MACROS 1   // gcc requires this to get PRId64, etc.
-#endif
+#include "config.h"
+#include "gflags.h"
 
-#include <gflags/gflags.h>
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #if HAVE_FNMATCH_H
-# include <fnmatch.h>
+#  include <fnmatch.h>
 #endif
 #include <stdarg.h> // For va_list and related operations
 #include <stdio.h>
@@ -109,13 +105,10 @@
 #include <string>
 #include <utility>     // for pair<>
 #include <vector>
+
 #include "mutex.h"
 #include "util.h"
 
-#ifndef PATH_SEPARATOR
-#  define PATH_SEPARATOR  '/'
-#endif
-
 
 // Special flags, type 1: the 'recursive' flags.  They set another flag's val.
 DEFINE_string(flagfile, "",
diff --git a/include/gflags/gflags.h.in b/src/gflags.h.in
similarity index 99%
rename from include/gflags/gflags.h.in
rename to src/gflags.h.in
index 58d72f93451b835230353d7c05513e939c039092..46c7d0cf4b0170b3a792d4f839168c11bcd79a93 100644
--- a/include/gflags/gflags.h.in
+++ b/src/gflags.h.in
@@ -103,7 +103,9 @@
 
 #include <string>
 #include <vector>
-#include <gflags/gflags_declare.h>    // IWYU pragma: export
+
+#include <@GFLAGS_NAMESPACE@/gflags_declare.h> // IWYU pragma: export
+
 
 namespace @GFLAGS_NAMESPACE@ {
 
diff --git a/src/gflags_completions.cc b/src/gflags_completions.cc
index a1438fa9bef48136fa204172bd64daeb83bc2442..3a476230ff974b2fa9e42ce877dcd8ab5d9f004c 100644
--- a/src/gflags_completions.cc
+++ b/src/gflags_completions.cc
@@ -47,7 +47,8 @@
 //     5b) Trim most flag's descriptions to fit on a single terminal line
 
 
-#include <config.h>
+#include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>   // for strlen
@@ -57,7 +58,7 @@
 #include <utility>
 #include <vector>
 
-#include <gflags/gflags.h>
+#include "gflags.h"
 #include "util.h"
 
 using std::set;
diff --git a/include/gflags/gflags_completions.h.in b/src/gflags_completions.h.in
similarity index 100%
rename from include/gflags/gflags_completions.h.in
rename to src/gflags_completions.h.in
diff --git a/include/gflags/gflags_declare.h.in b/src/gflags_declare.h.in
similarity index 100%
rename from include/gflags/gflags_declare.h.in
rename to src/gflags_declare.h.in
diff --git a/src/gflags_reporting.cc b/src/gflags_reporting.cc
index c097606cf2edba801ebb33dd56ce9eff9cfe1670..595af97235f477d6fc456fe2db474c6424c3ce51 100644
--- a/src/gflags_reporting.cc
+++ b/src/gflags_reporting.cc
@@ -48,15 +48,17 @@
 // called after all flag-values have been assigned, that is, after
 // parsing the command-line.
 
-#include <config.h>
+#include "config.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <assert.h>
 #include <string>
 #include <vector>
-#include <gflags/gflags.h>
-#include <gflags/gflags_completions.h>
+
+#include "gflags.h"
+#include "gflags_completions.h"
 #include "util.h"
 
 
diff --git a/src/util.h b/src/util.h
index 646d5a81fb13761405f3ba080616f0411ebd29d5..caa50cf9b7697ab654bb7532e6edd2c4df4a75cd 100644
--- a/src/util.h
+++ b/src/util.h
@@ -34,6 +34,8 @@
 #ifndef GFLAGS_UTIL_H_
 #define GFLAGS_UTIL_H_
 
+#include "config.h"
+
 #include <assert.h>
 #include <config.h>
 #if HAVE_INTTYPES_H