diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4afa4d83a86cdc334d0c2502be5d6ed2749fdb99..7f3ca5e9deb4a76debc7d7e7caae14cb18fb6edb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,8 +1,84 @@
+#=============================================================================
+#
+#  Program:   KWSys - Kitware System Library
+#  Module:    CMakeLists.txt
+#  Language:  C++
+#  Date:      $Date$
+#  Version:   $Revision$
+#
+#  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
+#  See http://www.cmake.org/HTML/Copyright.html for details.
+#
+#     This software is distributed WITHOUT ANY WARRANTY; without even 
+#     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+#     PURPOSE.  See the above copyright notices for more information.
+#
+#=============================================================================
+
+# The Kitware System Library is intended to be included in other
+# projects.  It is completely configurable in that the library's
+# namespace can be configured and the components that are included
+# selected invididually.
+
+# Typical usage is to import the kwsys directory tree into a
+# subdirectory under a parent project.  The CMake listfile above this
+# one configures the library as follows:
+#
+#  SET(KWSYS_NAMESPACE fookwsys)
+#  SUBDIRS(kwsys)
+#
+# Optional settings are as follows:
+#
+#  KWSYS_HEADER_DIR = The directory into which to generate the kwsys headers.
+#
+#    Example:
+#
+#      SET(KWSYS_HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE})
+#      INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+#
+#  KWSYS_LIBRARY_INSTALL_DIR = The installation target directories into
+#  KWSYS_HEADER_INSTALL_DIR    which the libraries and headers from
+#                              kwsys should be installed by a "make install".
+#                              The values should be specified relative to
+#                              the installation prefix and start with a '/'.
+#    Example:
+#
+#      SET(KWSYS_LIBRARY_INSTALL_DIR /lib)
+#      SET(KWSYS_HEADER_INSTALL_DIR /include)
+#
+#  KWSYS_FORCE_OLD_STREAMS = Force use of old non-ANSI C++ streams even if
+#                            new streams are available.  This may be used
+#                            by projects that cannot configure their
+#                            streams library.
+#    Example:
+#
+#      SET(KWSYS_FORCE_OLD_STREAMS 1)
+#
+
+# Once configured, kwsys should be used as follows from C or C++ code:
+#
+#  #include <fookwsys/Directory.hxx>
+#   ...
+#  fookwsys::Directory directory;
+#
+
+#-----------------------------------------------------------------------------
+# If a namespace is not specified, use "kwsys" and enable testing.
+# This should be the case only when kwsys is not included inside
+# another project and is being tested.
 IF(NOT KWSYS_NAMESPACE)
   SET(KWSYS_NAMESPACE "kwsys")
-  SET(KWSYS_DEFAULTS 1)
+  SET(KWSYS_STANDALONE 1)
+  
+  # Enable all components.
+  SET(KWSYS_USE_Process 1)
+  SET(KWSYS_USE_Directory 1)
+  SET(KWSYS_USE_RegularExpression 1)
+  SET(KWSYS_USE_SystemTools 1)
 ENDIF(NOT KWSYS_NAMESPACE)
 
+#-----------------------------------------------------------------------------
+# The project name is that of the specified namespace.
 PROJECT(${KWSYS_NAMESPACE})
 
 # Work-around for CMake 1.6.7 bug in custom command dependencies when
@@ -12,156 +88,255 @@ IF(NOT EXECUTABLE_OUTPUT_PATH)
       "Output directory for executables.")
 ENDIF(NOT EXECUTABLE_OUTPUT_PATH)
 
-# Choose a default directory for the headers if none is given.
-IF(NOT KWSYS_HEADER_DIR)
-  SET(KWSYS_HEADER_DIR "${PROJECT_BINARY_DIR}/${KWSYS_NAMESPACE}")
-ENDIF(NOT KWSYS_HEADER_DIR)
+#-----------------------------------------------------------------------------
+# We require ANSI support from the C compiler.  Add any needed flags.
+IF(CMAKE_ANSI_CFLAGS)
+  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
+ENDIF(CMAKE_ANSI_CFLAGS)
 
+#-----------------------------------------------------------------------------
+# Configure the standard library header wrappers based on compiler's
+# capabilities and parent project's request.
 INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake)
 INCLUDE(${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake)
-INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
 CHECK_INCLUDE_FILE_CXX("sstream" CMAKE_HAS_ANSI_STRING_STREAM)
 CHECK_INCLUDE_FILE_CXX("iosfwd" CMAKE_ANSI_IOSFWD_HEADER)
 
-IF(NOT CMAKE_ANSI_IOSFWD_HEADER)
+# Enforce 0/1 as only possible values.  Needed for the means by which
+# Configure.hxx is implemented.
+IF(CMAKE_NO_STD_NAMESPACE)
+  SET(CMAKE_NO_STD_NAMESPACE 1)
+ELSE(CMAKE_NO_STD_NAMESPACE)
+  SET(CMAKE_NO_STD_NAMESPACE 0)
+ENDIF(CMAKE_NO_STD_NAMESPACE)
+
+IF(CMAKE_ANSI_IOSFWD_HEADER)
+  SET(CMAKE_NO_ANSI_STREAM_HEADERS 0)
+ELSE(CMAKE_ANSI_IOSFWD_HEADER)
   SET(CMAKE_NO_ANSI_STREAM_HEADERS 1)
-ENDIF(NOT CMAKE_ANSI_IOSFWD_HEADER)
+ENDIF(CMAKE_ANSI_IOSFWD_HEADER)
 
-IF(NOT CMAKE_HAS_ANSI_STRING_STREAM)
+IF(CMAKE_HAS_ANSI_STRING_STREAM)
+  SET(CMAKE_NO_ANSI_STRING_STREAM 0)
+ELSE(CMAKE_HAS_ANSI_STRING_STREAM)
   SET(CMAKE_NO_ANSI_STRING_STREAM 1)
-ENDIF(NOT CMAKE_HAS_ANSI_STRING_STREAM)
+ENDIF(CMAKE_HAS_ANSI_STRING_STREAM)
 
 IF(KWSYS_FORCE_OLD_STREAMS)
   SET(CMAKE_NO_ANSI_STREAM_HEADERS 1)
   SET(CMAKE_NO_ANSI_STRING_STREAM 1)
 ENDIF(KWSYS_FORCE_OLD_STREAMS)
 
+IF(KWSYS_NAMESPACE MATCHES "^kwsys$")
+  SET(KWSYS_NAME_IS_KWSYS 1)
+ELSE(KWSYS_NAMESPACE MATCHES "^kwsys$")
+  SET(KWSYS_NAME_IS_KWSYS 0)
+ENDIF(KWSYS_NAMESPACE MATCHES "^kwsys$")
+
+# Set names that are used in creating Configure.hxx for these test
+# results.
 SET(KWSYS_NO_STD_NAMESPACE ${CMAKE_NO_STD_NAMESPACE})
 SET(KWSYS_NO_ANSI_STREAM_HEADERS ${CMAKE_NO_ANSI_STREAM_HEADERS})
 SET(KWSYS_NO_ANSI_STRING_STREAM ${CMAKE_NO_ANSI_STRING_STREAM})
-SET(KWSYS_NO_ANSI_FOR_SCOPE ${CMAKE_NO_ANSI_FOR_SCOPE})
 
-IF(CMAKE_ANSI_CFLAGS)
-  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
-ENDIF(CMAKE_ANSI_CFLAGS)
+#-----------------------------------------------------------------------------
+# Choose a directory for the generated headers.
+IF(NOT KWSYS_HEADER_DIR)
+  SET(KWSYS_HEADER_DIR "${PROJECT_BINARY_DIR}/${KWSYS_NAMESPACE}")
+ENDIF(NOT KWSYS_HEADER_DIR)
+
+#-----------------------------------------------------------------------------
+# Create STL header wrappers to block warnings in the STL headers and
+# give standard names by which they may be included.
+FOREACH(header algorithm deque iterator list map numeric queue set stack string
+               utility vector)
+  # Configure the header wrapper.
+  SET(KWSYS_STL_HEADER "${header}")
+  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_std.h.in
+                 ${KWSYS_HEADER_DIR}/std/${header}
+                 @ONLY IMMEDIATE)
+  
+  # Create an install target for the header wrapper.
+  IF(KWSYS_HEADER_INSTALL_DIR)
+    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
+      FILES ${KWSYS_HEADER_DIR}/std/${header})
+  ENDIF(KWSYS_HEADER_INSTALL_DIR)
+ENDFOREACH(header)
+
+#-----------------------------------------------------------------------------
+# Create streams header wrappers to give standard names by which they
+# may be included.
+FOREACH(header iostream fstream sstream iosfwd)
+  # Configure the header wrapper.
+  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_std_${header}.h.in
+                 ${KWSYS_HEADER_DIR}/std/${header}
+                 @ONLY IMMEDIATE)
+
+  # Create an install target for the header wrapper.
+  IF(KWSYS_HEADER_INSTALL_DIR)
+    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
+      FILES ${KWSYS_HEADER_DIR}/std/${header})
+  ENDIF(KWSYS_HEADER_INSTALL_DIR)
+ENDFOREACH(header)
+
+#-----------------------------------------------------------------------------
+# Build a list of classes and headers we need to implement the
+# selected components.  Initialize with required components.
+SET(KWSYS_CLASSES)
+SET(KWSYS_H_FILES)
+SET(KWSYS_HXX_FILES Configure)
+
+# Enforce component dependencies.
+IF(KWSYS_USE_SystemTools)
+  SET(KWSYS_USE_Directory 1)
+  SET(KWSYS_USE_RegularExpression 1)
+ENDIF(KWSYS_USE_SystemTools)
+
+# Add selected C++ classes.
+FOREACH(c Directory RegularExpression SystemTools)
+  IF(KWSYS_USE_${c})
+    SET(KWSYS_CLASSES ${KWSYS_CLASSES} ${c})
+  ENDIF(KWSYS_USE_${c})
+ENDFOREACH(c)
+
+# Add selected C components.
+IF(KWSYS_USE_Process)
+  SET(KWSYS_H_FILES ${KWSYS_H_FILES} Process)
+ENDIF(KWSYS_USE_Process)
 
-SET(CLASSES Directory RegularExpression SystemTools)
-SET(H Process)
-SET(HXX Configure)
-
-IF(NOT UNIX)
-  ADD_EXECUTABLE(${KWSYS_NAMESPACE}ProcessFwd9x ProcessFwd9x.c)
-  ADD_EXECUTABLE(${KWSYS_NAMESPACE}EncodeExecutable EncodeExecutable.c)
-  SET(SRCS ProcessWin32.c ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c)
-  SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
-                              PROPERTIES GENERATED 1)
-ELSE(NOT UNIX)
-  SET(SRCS ProcessUNIX.c)
-ENDIF(NOT UNIX)
-
-SET(KWSYS_INCLUDES)
-FOREACH(c ${CLASSES})
-  SET(SRCS ${SRCS} ${c}.cxx)
-  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in
-                 ${KWSYS_HEADER_DIR}/${c}.hxx
+#-----------------------------------------------------------------------------
+# Build a list of sources for the library based on components that are
+# included.
+SET(KWSYS_SRCS)
+
+# Add the proper sources for this platform's Process implementation.
+IF(KWSYS_USE_Process)
+  IF(NOT UNIX)
+    # Use the Windows implementation.  We need the encoded forwarding executable.
+    SET(KWSYS_SRCS ProcessWin32.c ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c)
+    SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
+                                PROPERTIES GENERATED 1)
+  ELSE(NOT UNIX)
+    # Use the UNIX implementation.
+    SET(KWSYS_SRCS ProcessUNIX.c)
+  ENDIF(NOT UNIX)
+ENDIF(KWSYS_USE_Process)
+
+# Configure headers of C++ classes and construct the list of sources.
+FOREACH(c ${KWSYS_CLASSES})
+  # Add this source to the list of source files for the library.
+  SET(KWSYS_SRCS ${KWSYS_SRCS} ${c}.cxx)
+  
+  # Configure the header for this class.
+  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in ${KWSYS_HEADER_DIR}/${c}.hxx
                  @ONLY IMMEDIATE)
-  SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
-      ${KWSYS_HEADER_DIR}/${c}.hxx)
+
+  # Create an install target for the header.
+  IF(KWSYS_HEADER_INSTALL_DIR)
+    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
+                  FILES  ${KWSYS_HEADER_DIR}/${c}.hxx)
+  ENDIF(KWSYS_HEADER_INSTALL_DIR)
 ENDFOREACH(c)
 
-FOREACH(h ${H})
-  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.h.in
-                 ${KWSYS_HEADER_DIR}/${h}.h
+# Configure C headers.
+FOREACH(h ${KWSYS_H_FILES})
+  # Configure the header into the given directory.
+  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.h.in ${KWSYS_HEADER_DIR}/${h}.h
                  @ONLY IMMEDIATE)
-  SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
-      ${KWSYS_HEADER_DIR}/${h}.h)
+
+  # Create an install target for the header.
+  IF(KWSYS_HEADER_INSTALL_DIR)
+    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
+                  FILES  ${KWSYS_HEADER_DIR}/${h}.h)
+  ENDIF(KWSYS_HEADER_INSTALL_DIR)
 ENDFOREACH(h)
 
-FOREACH(h ${HXX})
-  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.hxx.in
-                 ${KWSYS_HEADER_DIR}/${h}.hxx
+# Configure other C++ headers.
+FOREACH(h ${KWSYS_HXX_FILES})
+  # Configure the header into the given directory.
+  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.hxx.in ${KWSYS_HEADER_DIR}/${h}.hxx
                  @ONLY IMMEDIATE)
-  SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
-      ${KWSYS_HEADER_DIR}/${h}.hxx)
-ENDFOREACH(h)
 
-ADD_LIBRARY(${KWSYS_NAMESPACE} ${SRCS})
+  # Create an install target for the header.
+  IF(KWSYS_HEADER_INSTALL_DIR)
+    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
+                  FILES  ${KWSYS_HEADER_DIR}/${h}.hxx)
+  ENDIF(KWSYS_HEADER_INSTALL_DIR)
+ENDFOREACH(h)
 
-ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
-INCLUDE_DIRECTORIES(BEFORE ${KWSYS_HEADER_DIR})
+#-----------------------------------------------------------------------------
+# Add the library with the configured name and list of sources.
+ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_SRCS})
 
+# Create an install target for the library.
 IF(KWSYS_LIBRARY_INSTALL_DIR)
   INSTALL_TARGETS(${KWSYS_LIBRARY_INSTALL_DIR} ${KWSYS_NAMESPACE})
 ENDIF(KWSYS_LIBRARY_INSTALL_DIR)
 
-IF(KWSYS_INCLUDE_INSTALL_DIR)
-  INSTALL_FILES(${KWSYS_INCLUDE_INSTALL_DIR}/${KWSYS_NAMESPACE}
-                FILES ${KWSYS_INCLUDES})
-ENDIF(KWSYS_INCLUDE_INSTALL_DIR)
+# For building kwsys itself, we use a macro defined on the command
+# line to configure the namespace in the C and C++ source files.  The
+# source files must also include their headers without the namespae
+# prefix, so we add the header directory to the include path directly.
+ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
+INCLUDE_DIRECTORIES(BEFORE ${KWSYS_HEADER_DIR})
 
 #-----------------------------------------------------------------------------
-# Create STL header wrappers to block warnings in the STL headers.
-FOREACH(header algorithm deque iterator list map numeric queue set stack string
-               utility vector)
-  SET(KWSYS_STL_HEADER "${header}")
-  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_std.h.in
-                 ${KWSYS_HEADER_DIR}/std/${header}
-                 @ONLY IMMEDIATE)
-  IF(KWSYS_INCLUDE_INSTALL_DIR)
-    INSTALL_FILES(${KWSYS_INCLUDE_INSTALL_DIR}/${KWSYS_NAMESPACE}
-      FILES ${KWSYS_HEADER_DIR}/std/${header})
-  ENDIF(KWSYS_INCLUDE_INSTALL_DIR)
-ENDFOREACH(header)
+# Process execution on windows needs to build a forwarding executable
+# that works around a Win9x bug.  We encode the executable into a C
+# file and build it into the library.  Win9x platforms reproduce the
+# executable into a temporary directory when it is needed.
+IF(KWSYS_USE_Process)
+  IF(NOT UNIX)
+    # Build the forwarding executable itself and a program that will
+    # encode it into a C file.
+    ADD_EXECUTABLE(${KWSYS_NAMESPACE}ProcessFwd9x ProcessFwd9x.c)
+    ADD_EXECUTABLE(${KWSYS_NAMESPACE}EncodeExecutable EncodeExecutable.c)
 
-FOREACH(header iostream fstream sstream iosfwd)
-  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_std_${header}.h.in
-                 ${KWSYS_HEADER_DIR}/std/${header}
-                 @ONLY IMMEDIATE)
-  IF(KWSYS_INCLUDE_INSTALL_DIR)
-    INSTALL_FILES(${KWSYS_INCLUDE_INSTALL_DIR}/${KWSYS_NAMESPACE}
-      FILES ${KWSYS_HEADER_DIR}/std/${header})
-  ENDIF(KWSYS_INCLUDE_INSTALL_DIR)
-ENDFOREACH(header)
+    # Construct the location of the executable to be encoded.
+    SET(BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
+    IF(EXECUTABLE_OUTPUT_PATH)
+      SET(BIN_DIR ${EXECUTABLE_OUTPUT_PATH})
+    ENDIF(EXECUTABLE_OUTPUT_PATH)
+    
+    SET(MAKE_SYSTEM)
+    SET(CFG_INTDIR "/${CMAKE_CFG_INTDIR}")
+    IF(CMAKE_BUILD_TOOL MATCHES "make")
+      SET(CFG_INTDIR "")
+    ENDIF(CMAKE_BUILD_TOOL MATCHES "make")
 
-IF(KWSYS_DEFAULTS)
+    # Take advantage of a better custom command syntax if possible.
+    SET(CMD ${BIN_DIR}${CFG_INTDIR}/${KWSYS_NAMESPACE}EncodeExecutable.exe)
+    SET(FWD ${BIN_DIR}${CFG_INTDIR}/${KWSYS_NAMESPACE}ProcessFwd9x.exe)
+    IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
+      ADD_CUSTOM_COMMAND(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
+        COMMAND ${CMD}
+        ARGS ${FWD} ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
+  	   ${KWSYS_NAMESPACE} ProcessFwd9x
+        DEPENDS ${CMD} ${FWD})
+    ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
+      ADD_CUSTOM_COMMAND(
+        TARGET ${KWSYS_NAMESPACE}
+        SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/ProcessFwd9x.c
+        COMMAND ${CMD}
+        ARGS ${FWD} ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
+  	   ${KWSYS_NAMESPACE} ProcessFwd9x
+        OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
+        DEPENDS ${CMD} ${FWD})
+    ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
+    
+    # Make sure build occurs in proper order.
+    ADD_DEPENDENCIES(${KWSYS_NAMESPACE} ${KWSYS_NAMESPACE}ProcessFwd9x
+                     ${KWSYS_NAMESPACE}EncodeExecutable)
+  ENDIF(NOT UNIX)
+ENDIF(KWSYS_USE_Process)
+
+#-----------------------------------------------------------------------------
+# Setup testing if not being built as part of another project.
+IF(KWSYS_STANDALONE)
   INCLUDE_DIRECTORIES(${KWSYS_HEADER_DIR}/..)
   ADD_EXECUTABLE(testProcess testProcess.c)
   ADD_EXECUTABLE(test1 test1.cxx)
   TARGET_LINK_LIBRARIES(testProcess ${KWSYS_NAMESPACE})
   TARGET_LINK_LIBRARIES(test1 ${KWSYS_NAMESPACE})
-ENDIF(KWSYS_DEFAULTS)
-
-IF(NOT UNIX)
-  SET(BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
-  IF(EXECUTABLE_OUTPUT_PATH)
-    SET(BIN_DIR ${EXECUTABLE_OUTPUT_PATH})
-  ENDIF(EXECUTABLE_OUTPUT_PATH)
-
-  SET(MAKE_SYSTEM)
-  SET(CFG_INTDIR "/${CMAKE_CFG_INTDIR}")
-  IF(CMAKE_BUILD_TOOL MATCHES "make")
-    SET(CFG_INTDIR "")
-  ENDIF(CMAKE_BUILD_TOOL MATCHES "make")
-
-  SET(CMD ${BIN_DIR}${CFG_INTDIR}/${KWSYS_NAMESPACE}EncodeExecutable.exe)
-  SET(FWD ${BIN_DIR}${CFG_INTDIR}/${KWSYS_NAMESPACE}ProcessFwd9x.exe)
-  IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
-    ADD_CUSTOM_COMMAND(
-      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
-      COMMAND ${CMD}
-      ARGS ${FWD} ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
-	   ${KWSYS_NAMESPACE} ProcessFwd9x
-      DEPENDS ${CMD} ${FWD})
-  ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
-    ADD_CUSTOM_COMMAND(
-      TARGET ${KWSYS_NAMESPACE}
-      SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/ProcessFwd9x.c
-      COMMAND ${CMD}
-      ARGS ${FWD} ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
-	   ${KWSYS_NAMESPACE} ProcessFwd9x
-      OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
-      DEPENDS ${CMD} ${FWD})
-  ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
-  ADD_DEPENDENCIES(${KWSYS_NAMESPACE} ${KWSYS_NAMESPACE}ProcessFwd9x
-                   ${KWSYS_NAMESPACE}EncodeExecutable)
-ENDIF(NOT UNIX)
+ENDIF(KWSYS_STANDALONE)
diff --git a/Configure.hxx.in b/Configure.hxx.in
index d656abc173d2135e88f5873941907cda3d2d1234..6456778ca63f16e2ef4e9d38f1195fbb93e3f70a 100644
--- a/Configure.hxx.in
+++ b/Configure.hxx.in
@@ -17,20 +17,53 @@
 #ifndef @KWSYS_NAMESPACE@_Configure_hxx
 #define @KWSYS_NAMESPACE@_Configure_hxx
 
-/* This configuration should match for all instances of kwsys.  */
-#cmakedefine KWSYS_NO_STD_NAMESPACE
-#cmakedefine KWSYS_NO_ANSI_STREAM_HEADERS
-#cmakedefine KWSYS_NO_ANSI_STRING_STREAM
-#cmakedefine KWSYS_NO_ANSI_FOR_SCOPE
+/* Defined if kwsys namespace is "kwsys".  */
+#if @KWSYS_NAME_IS_KWSYS@
+# define @KWSYS_NAMESPACE@_NAME_IS_KWSYS
+#endif
+
+/* Defined if no ANSI C++ stream headers are present.  */
+#if @KWSYS_NO_ANSI_STREAM_HEADERS@
+# define @KWSYS_NAMESPACE@_NO_ANSI_STREAM_HEADERS
+#endif
+
+/* Defined if no ANSI C++ <sstream> header is present.  */
+#if @KWSYS_NO_ANSI_STRING_STREAM@
+# define @KWSYS_NAMESPACE@_NO_ANSI_STRING_STREAM
+#endif
 
+/* Defined if no std namespace is present.  */
+#if @KWSYS_NO_STD_NAMESPACE@
+# define @KWSYS_NAMESPACE@_NO_STD_NAMESPACE
+#endif
+
+/* Defined if std namespace is the GCC hack.  */
 #if defined(__GNUC__) && (__GNUC__ < 3)
-# define KWSYS_FAKE_STD_NAMESPACE
+# define @KWSYS_NAMESPACE@_FAKE_STD_NAMESPACE
 #endif
 
-#if defined(KWSYS_NO_STD_NAMESPACE)
-# define kwsys_std
+/* Define the std namespace macro.  */
+#if defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE)
+# define @KWSYS_NAMESPACE@_std
 #else
-# define kwsys_std std
+# define @KWSYS_NAMESPACE@_std std
+#endif
+
+/* If building a C++ file in kwsys itself, give the source file
+   access to the macros without a configured namespace.  */
+#if defined(KWSYS_NAMESPACE)
+# if !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+#  define kwsys_std @KWSYS_NAMESPACE@_std
+# endif
+# if defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE)
+#  define KWSYS_NO_STD_NAMESPACE
+# endif
+# if defined(@KWSYS_NAMESPACE@_NO_ANSI_STREAM_HEADERS)
+#  define KWSYS_NO_ANSI_STREAM_HEADERS
+# endif
+# if defined(@KWSYS_NAMESPACE@_NO_ANSI_STRING_STREAM)
+#  define KWSYS_NO_ANSI_STRING_STREAM
+# endif
 #endif
 
 #endif
diff --git a/RegularExpression.hxx.in b/RegularExpression.hxx.in
index dcd965e8e5295ff4316c04a5de473795528f34d5..e4c3707cb72a85b962d941442e68d6b5c4242adf 100644
--- a/RegularExpression.hxx.in
+++ b/RegularExpression.hxx.in
@@ -39,6 +39,11 @@
 
 #include <@KWSYS_NAMESPACE@/std/string>
 
+/* Define this macro temporarily to keep the code readable.  */
+#if !defined (KWSYS_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+# define kwsys_std @KWSYS_NAMESPACE@_std
+#endif
+
 namespace @KWSYS_NAMESPACE@
 {
 
@@ -382,4 +387,9 @@ inline kwsys_std::string RegularExpression::match(int n) const
 
 } // namespace @KWSYS_NAMESPACE@
 
+/* Undefine temporary macro.  */
+#if !defined (KWSYS_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+# undef kwsys_std
+#endif
+
 #endif
diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in
index 0e35c7779123c495d3b92dad7ecb81f08fbbde46..1c7756bc146c26595cbfe9f0470c2aebd7c33bdb 100644
--- a/SystemTools.hxx.in
+++ b/SystemTools.hxx.in
@@ -21,6 +21,11 @@
 #include <@KWSYS_NAMESPACE@/std/string>
 #include <@KWSYS_NAMESPACE@/std/vector>
 
+/* Define this macro temporarily to keep the code readable.  */
+#if !defined (KWSYS_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+# define kwsys_std @KWSYS_NAMESPACE@_std
+#endif
+
 namespace @KWSYS_NAMESPACE@
 {
 
@@ -287,4 +292,9 @@ protected:
 
 } // namespace @KWSYS_NAMESPACE@
 
+/* Undefine temporary macro.  */
+#if !defined (KWSYS_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+# undef kwsys_std
+#endif
+
 #endif
diff --git a/kwsys_std_fstream.h.in b/kwsys_std_fstream.h.in
index 6988f6a8bf8a97d3fce65dd5949f86a2d8f61179..5dd66c0569d8d5c5d38e3a93259574bebfb272c5 100644
--- a/kwsys_std_fstream.h.in
+++ b/kwsys_std_fstream.h.in
@@ -24,11 +24,11 @@
 #pragma warning (disable: 4702)
 #endif
 
-#if !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
+#if !defined(@KWSYS_NAMESPACE@_NO_ANSI_STREAM_HEADERS)
 # include <fstream>
 #else
 # include <fstream.h>
-# if !defined(KWSYS_NO_STD_NAMESPACE) && !defined(KWSYS_FAKE_STD_NAMESPACE)
+# if !defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_FAKE_STD_NAMESPACE)
 namespace std
 {
   using ::ostream;
diff --git a/kwsys_std_iosfwd.h.in b/kwsys_std_iosfwd.h.in
index a0bd917bbbdfe02f8f5e04e11a18a8f53d1a3c08..06fbb3d112fa25b41599ab9817c21eee173a29c5 100644
--- a/kwsys_std_iosfwd.h.in
+++ b/kwsys_std_iosfwd.h.in
@@ -24,7 +24,7 @@
 #pragma warning (disable: 4702)
 #endif
 
-#if !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
+#if !defined(@KWSYS_NAMESPACE@_NO_ANSI_STREAM_HEADERS)
 # include <iosfwd>
 #else
 class fstream;
@@ -33,7 +33,7 @@ class ios;
 class istream;
 class ofstream;
 class ostream;
-# if !defined(KWSYS_NO_STD_NAMESPACE) && !defined(KWSYS_FAKE_STD_NAMESPACE)
+# if !defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_FAKE_STD_NAMESPACE)
 namespace std
 {
   using ::fstream;
diff --git a/kwsys_std_iostream.h.in b/kwsys_std_iostream.h.in
index c5d7b5ef7a2af3c1400f5fca21ffb4e9918953e2..5ca2f1d0e0150245b770a5c926d8b3dc2fb6bc28 100644
--- a/kwsys_std_iostream.h.in
+++ b/kwsys_std_iostream.h.in
@@ -24,11 +24,11 @@
 #pragma warning (disable: 4702)
 #endif
 
-#if !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
+#if !defined(@KWSYS_NAMESPACE@_NO_ANSI_STREAM_HEADERS)
 # include <iostream>
 #else
 # include <iostream.h>
-# if !defined(KWSYS_NO_STD_NAMESPACE) && !defined(KWSYS_FAKE_STD_NAMESPACE)
+# if !defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_FAKE_STD_NAMESPACE)
 namespace std
 {
   using ::ostream;
diff --git a/kwsys_std_sstream.h.in b/kwsys_std_sstream.h.in
index a9838da459171b58e0839d56fbec4eeff50cf6e5..0642a6d752a2d9bca2b94d74fbf74d913558b944 100644
--- a/kwsys_std_sstream.h.in
+++ b/kwsys_std_sstream.h.in
@@ -19,7 +19,12 @@
 
 #include <@KWSYS_NAMESPACE@/Configure.hxx>
 
-#if !defined(KWSYS_NO_ANSI_STRING_STREAM)
+/* Define this macro temporarily to keep the code readable.  */
+#if !defined (KWSYS_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+# define kwsys_std @KWSYS_NAMESPACE@_std
+#endif
+
+#if !defined(@KWSYS_NAMESPACE@_NO_ANSI_STRING_STREAM)
 # ifdef _MSC_VER
 #  pragma warning (push, 1)
 #  pragma warning (disable: 4702)
@@ -33,11 +38,11 @@
 #  pragma warning (push, 1)
 #  pragma warning (disable: 4702)
 # endif
-# if !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
+# if !defined(@KWSYS_NAMESPACE@_NO_ANSI_STREAM_HEADERS)
 #  include <strstream>
 # else
 #  include <strstream.h>
-#  if !defined(KWSYS_NO_STD_NAMESPACE) && !defined(KWSYS_FAKE_STD_NAMESPACE)
+#  if !defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_FAKE_STD_NAMESPACE)
 namespace std
 {
   using ::ostream;
@@ -60,7 +65,7 @@ namespace std
 
 # include <@KWSYS_NAMESPACE@/std/string>
 
-# if !defined(KWSYS_NO_STD_NAMESPACE)
+# if !defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE)
 namespace std
 {
 # endif
@@ -114,10 +119,15 @@ private:
   void operator=(const istringstream&);
 };
 
-# if !defined(KWSYS_NO_STD_NAMESPACE)
+# if !defined(@KWSYS_NAMESPACE@_NO_STD_NAMESPACE)
 }
 # endif
 
 #endif
 
+/* Undefine temporary macro.  */
+#if !defined (KWSYS_NAMESPACE) && !defined(@KWSYS_NAMESPACE@_NAME_IS_KWSYS)
+# undef kwsys_std
+#endif
+
 #endif