From c688b401d3adaacc820ef4b589010e8aefa808b1 Mon Sep 17 00:00:00 2001
From: Marc Chevrier <marc.chevrier@gmail.com>
Date: Sun, 4 Aug 2019 10:49:16 +0200
Subject: [PATCH] cmstd: Modernize CMake system headers

Provide a standardized way to handle the C++ "standard" headers
customized to be used with current CMake C++ standard constraints.
Offer under directory `cm` headers which can be used as direct
replacements of the standard ones.  For example:

    #include <cm/string_view>

can be used safely for CMake development in place of the `<string_view>`
standard header.

Fixes: #19491
---
 CMakeLists.txt                                | 13 ++++
 Source/CMakeLists.txt                         |  6 +-
 Source/CPack/WiX/cmCPackWIXGenerator.cxx      |  3 +-
 Source/CPack/WiX/cmWIXFilesSourceWriter.cxx   |  4 +-
 Source/CPack/cmCPackDebGenerator.cxx          |  4 +-
 Source/CPack/cmCPackExternalGenerator.cxx     |  2 +-
 Source/CPack/cmCPackExternalGenerator.h       |  1 +
 Source/CPack/cmCPackGenerator.h               |  3 +-
 Source/CPack/cmCPackOSXX11Generator.cxx       |  3 +-
 Source/CPack/cmCPackSTGZGenerator.cxx         |  3 +-
 Source/CTest/cmCTestBuildCommand.h            |  2 +-
 Source/CTest/cmCTestCVS.cxx                   |  4 +-
 Source/CTest/cmCTestConfigureCommand.h        |  2 +-
 Source/CTest/cmCTestCoverageCommand.h         |  2 +-
 .../cmCTestEmptyBinaryDirectoryCommand.h      |  2 +-
 Source/CTest/cmCTestMemCheckCommand.h         |  2 +-
 Source/CTest/cmCTestReadCustomFilesCommand.h  |  2 +-
 Source/CTest/cmCTestRunScriptCommand.h        |  2 +-
 Source/CTest/cmCTestRunTest.cxx               |  2 +-
 Source/CTest/cmCTestScriptHandler.cxx         |  2 +-
 Source/CTest/cmCTestSleepCommand.h            |  2 +-
 Source/CTest/cmCTestStartCommand.h            |  2 +-
 Source/CTest/cmCTestSubmitCommand.cxx         |  2 +-
 Source/CTest/cmCTestTestCommand.h             |  2 +-
 Source/CTest/cmCTestTestHandler.cxx           |  2 +-
 Source/CTest/cmCTestUpdateCommand.h           |  2 +-
 Source/CTest/cmCTestUpdateHandler.cxx         |  2 +-
 Source/CTest/cmCTestUploadCommand.h           |  2 +-
 Source/cmAlgorithms.h                         | 77 ------------------
 Source/cmArgumentParser.h                     |  2 +-
 Source/cmBinUtilsLinuxELFLinker.cxx           |  2 +-
 Source/cmBinUtilsMacOSMachOLinker.cxx         |  2 +-
 Source/cmBinUtilsWindowsPELinker.cxx          |  2 +-
 Source/cmCTest.cxx                            |  2 +-
 Source/cmCommands.cxx                         |  2 +-
 Source/cmComputeLinkDepends.cxx               |  2 +-
 Source/cmCryptoHash.cxx                       |  2 +-
 Source/cmCryptoHash.h                         |  2 +-
 Source/cmCustomCommandLines.h                 |  2 +-
 Source/cmDefinitions.cxx                      |  2 +-
 Source/cmDefinitions.h                        |  5 +-
 Source/cmDependsJavaParserHelper.cxx          |  2 +-
 Source/cmELF.cxx                              |  2 +-
 Source/cmExportCommand.h                      |  2 +-
 Source/cmExportFileGenerator.cxx              |  2 +-
 Source/cmExportLibraryDependenciesCommand.cxx |  2 +-
 Source/cmFSPermissions.h                      |  4 +-
 Source/cmFileCommand.cxx                      |  5 +-
 Source/cmFileCopier.h                         |  3 +-
 Source/cmFileTimes.cxx                        |  6 +-
 Source/cmFindPackageCommand.cxx               |  2 +-
 Source/cmForEachCommand.cxx                   |  5 +-
 Source/cmFunctionBlocker.h                    |  2 +-
 Source/cmFunctionCommand.cxx                  |  5 +-
 Source/cmGeneratorExpressionEvaluationFile.h  |  3 +-
 Source/cmGeneratorExpressionNode.cxx          |  3 +-
 Source/cmGeneratorTarget.cxx                  |  3 +-
 Source/cmGlobalNinjaGenerator.cxx             |  2 +-
 Source/cmGlobalUnixMakefileGenerator3.cxx     |  2 +-
 Source/cmGlobalVisualStudio7Generator.cxx     |  3 +-
 Source/cmGlobalVisualStudioGenerator.cxx      |  3 +-
 Source/cmGlobalXCodeGenerator.cxx             |  2 +-
 Source/cmIfCommand.cxx                        |  5 +-
 Source/cmIncludeDirectoryCommand.h            |  2 +-
 Source/cmInstallCommand.h                     |  2 +-
 Source/cmLinkDirectoriesCommand.h             |  2 +-
 Source/cmListCommand.cxx                      |  3 +-
 Source/cmLoadCacheCommand.h                   |  2 +-
 Source/cmLoadCommandCommand.cxx               |  2 +-
 Source/cmLocalGenerator.cxx                   |  3 +-
 Source/cmLocalUnixMakefileGenerator3.cxx      |  2 +-
 Source/cmMachO.cxx                            |  2 +-
 Source/cmMacroCommand.cxx                     |  5 +-
 Source/cmMakefile.cxx                         |  5 +-
 Source/cmMakefile.h                           |  2 +-
 .../cmMakefileExecutableTargetGenerator.cxx   |  2 +-
 Source/cmMakefileLibraryTargetGenerator.cxx   |  2 +-
 Source/cmMakefileUtilityTargetGenerator.cxx   |  2 +-
 Source/cmNinjaNormalTargetGenerator.cxx       |  2 +-
 Source/cmNinjaTargetGenerator.cxx             |  2 +-
 Source/cmOutputConverter.h                    |  3 +-
 Source/cmParseArgumentsCommand.cxx            |  2 +-
 Source/cmProjectCommand.h                     |  2 +-
 Source/cmQtAutoGen.h                          |  2 +-
 Source/cmQtAutoGenGlobalInitializer.cxx       |  2 +-
 Source/cmQtAutoGenInitializer.cxx             |  2 +-
 Source/cmQtAutoGenInitializer.h               |  3 +-
 Source/cmQtAutoGenerator.cxx                  |  3 +-
 Source/cmQtAutoGenerator.h                    |  3 +-
 Source/cmQtAutoMocUic.cxx                     | 10 ++-
 Source/cmQtAutoMocUic.h                       |  3 +-
 Source/cmQtAutoRcc.cxx                        |  3 +-
 Source/cmRuntimeDependencyArchive.cxx         |  2 +-
 Source/cmServer.cxx                           |  3 +-
 Source/cmServer.h                             |  3 +-
 Source/cmServerProtocol.cxx                   |  2 +-
 Source/cmSetTargetPropertiesCommand.h         |  2 +-
 Source/cmSourceGroupCommand.h                 |  2 +-
 Source/cmState.cxx                            |  2 +-
 Source/cmStateDirectory.cxx                   | 11 +--
 Source/cmStateSnapshot.cxx                    |  6 +-
 Source/cmStateSnapshot.h                      |  2 +-
 Source/cmString.hxx                           |  2 +-
 Source/cmStringAlgorithms.h                   |  4 +-
 Source/cmStringCommand.cxx                    |  4 +-
 Source/cmSubcommandTable.h                    |  3 +-
 Source/cmSystemTools.h                        |  2 +-
 Source/cmTarget.cxx                           |  2 +-
 Source/cmTargetCompileDefinitionsCommand.h    |  2 +-
 Source/cmTargetCompileFeaturesCommand.h       |  2 +-
 Source/cmTargetCompileOptionsCommand.h        |  2 +-
 Source/cmTargetIncludeDirectoriesCommand.h    |  2 +-
 Source/cmTargetLinkDirectoriesCommand.h       |  2 +-
 Source/cmTargetLinkLibrariesCommand.h         |  2 +-
 Source/cmTargetLinkOptionsCommand.h           |  2 +-
 Source/cmTargetPrecompileHeadersCommand.h     |  2 +-
 Source/cmTargetSourcesCommand.h               |  2 +-
 Source/cmTryCompileCommand.h                  |  2 +-
 Source/cmTryRunCommand.h                      |  2 +-
 Source/cmUVProcessChain.cxx                   |  2 +-
 Source/cmVisualStudio10TargetGenerator.cxx    |  2 +-
 Source/cmVisualStudioGeneratorOptions.cxx     |  6 +-
 Source/cmWhileCommand.cxx                     |  5 +-
 Source/cmWorkerPool.cxx                       |  2 +-
 Source/cmWorkerPool.h                         |  2 +-
 Source/cmWriteFileCommand.cxx                 |  3 +-
 Source/cm_static_string_view.hxx              |  2 +-
 Source/cm_sys_stat.h                          |  2 +-
 Source/cmake.cxx                              | 10 ++-
 Tests/CMakeLib/testArgumentParser.cxx         |  2 +-
 Tests/CMakeLib/testOptional.cxx               |  5 +-
 Tests/CMakeLib/testString.cxx                 |  2 +-
 Tests/CMakeLib/testStringAlgorithms.cxx       |  3 +-
 Tests/CMakeLib/testUVProcessChain.cxx         |  2 +-
 Utilities/IWYU/mapping.imp                    |  1 -
 Utilities/std/.gitattributes                  |  1 +
 Utilities/std/CMakeLists.txt                  | 10 +++
 .../std/cm/bits/string_view.cxx               |  2 +-
 Utilities/std/cm/iterator                     | 78 +++++++++++++++++++
 .../cm_memory.hxx => Utilities/std/cm/memory  |  9 ++-
 .../std/cm/optional                           | 15 ++--
 .../std/cm/shared_mutex                       | 38 +++++++--
 .../std/cm/string_view                        | 11 +--
 .../std/cm/utility                            | 13 ++--
 bootstrap                                     | 28 ++++++-
 145 files changed, 390 insertions(+), 272 deletions(-)
 create mode 100644 Utilities/std/.gitattributes
 create mode 100644 Utilities/std/CMakeLists.txt
 rename Source/cm_string_view.cxx => Utilities/std/cm/bits/string_view.cxx (99%)
 create mode 100644 Utilities/std/cm/iterator
 rename Source/cm_memory.hxx => Utilities/std/cm/memory (85%)
 rename Source/cm_optional.hxx => Utilities/std/cm/optional (97%)
 rename Source/cm_thread.hxx => Utilities/std/cm/shared_mutex (52%)
 rename Source/cm_string_view.hxx => Utilities/std/cm/string_view (98%)
 rename Source/cm_utility.hxx => Utilities/std/cm/utility (75%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21e8c467c8..da99a6ee8d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -368,11 +368,24 @@ macro (CMAKE_BUILD_UTILITIES)
   # Setup third-party libraries.
   # Everything in the tree should be able to include files from the
   # Utilities directory.
+  if (CMAKE_SYSTEM_NAME STREQUAL "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    # using -isystem option generate error "template with C linkage"
+    include_directories("${CMake_SOURCE_DIR}/Utilities/std")
+  else()
+    include_directories(SYSTEM "${CMake_SOURCE_DIR}/Utilities/std")
+  endif()
+
   include_directories(
     ${CMake_BINARY_DIR}/Utilities
     ${CMake_SOURCE_DIR}/Utilities
     )
 
+  #---------------------------------------------------------------------
+  # Build CMake std library for CMake and CTest.
+  set(CMAKE_STD_LIBRARY cmstd)
+  add_subdirectory(Utilities/std)
+  CMAKE_SET_TARGET_FOLDER(cmstd "Utilities/std")
+
   # check for the use of system libraries versus builtin ones
   # (a macro defined in this file)
   CMAKE_HANDLE_SYSTEM_LIBRARIES()
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 65cd6c9fe4..c7648f11ba 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -439,9 +439,6 @@ set(SRCS
   cmXMLWriter.h
   cmake.cxx
   cmake.h
-  cm_string_view.cxx
-  cm_string_view.hxx
-  cm_static_string_view.hxx
 
   cmCommand.cxx
   cmCommand.h
@@ -683,13 +680,13 @@ set(SRCS
   cmWriteFileCommand.cxx
   cmWriteFileCommand.h
 
+  cm_static_string_view.hxx
   cm_get_date.h
   cm_get_date.c
   cm_utf8.h
   cm_utf8.c
   cm_codecvt.hxx
   cm_codecvt.cxx
-  cm_thread.hxx
 
   cmDuration.h
   cmDuration.cxx
@@ -855,6 +852,7 @@ endforeach()
 # create a library used by the command line and the GUI
 add_library(CMakeLib ${SRCS})
 target_link_libraries(CMakeLib cmsys
+  ${CMAKE_STD_LIBRARY}
   ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES}
   ${CMAKE_TAR_LIBRARIES}
   ${CMAKE_CURL_LIBRARIES}
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index f78483260c..683f275d12 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -11,8 +11,9 @@
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 #include "cmUuid.h"
-#include "cm_string_view.hxx"
+
 #include <algorithm>
+#include <cm/string_view>
 
 #include "cmWIXDirectoriesSourceWriter.h"
 #include "cmWIXFeaturesSourceWriter.h"
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
index dd3caf9d3d..7705d839dc 100644
--- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
@@ -9,10 +9,10 @@
 #include "cmSystemTools.h"
 #include "cmUuid.h"
 
-#include "cm_sys_stat.h"
-
 #include "cmCMakeToWixPath.h"
 
+#include "cm_sys_stat.h"
+
 cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
                                                std::string const& filename,
                                                GuidType componentGuidType)
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx
index 0e64b5a86d..4f299f72a4 100644
--- a/Source/CPack/cmCPackDebGenerator.cxx
+++ b/Source/CPack/cmCPackDebGenerator.cxx
@@ -10,9 +10,11 @@
 #include "cmGeneratedFileStream.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
-#include "cm_sys_stat.h"
 
 #include "cmsys/Glob.hxx"
+
+#include "cm_sys_stat.h"
+
 #include <cstring>
 #include <map>
 #include <ostream>
diff --git a/Source/CPack/cmCPackExternalGenerator.cxx b/Source/CPack/cmCPackExternalGenerator.cxx
index 5dc6acef39..05e5c214a3 100644
--- a/Source/CPack/cmCPackExternalGenerator.cxx
+++ b/Source/CPack/cmCPackExternalGenerator.cxx
@@ -17,7 +17,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 int cmCPackExternalGenerator::InitializeInternal()
 {
diff --git a/Source/CPack/cmCPackExternalGenerator.h b/Source/CPack/cmCPackExternalGenerator.h
index 176d6a9d9f..b77e45bc10 100644
--- a/Source/CPack/cmCPackExternalGenerator.h
+++ b/Source/CPack/cmCPackExternalGenerator.h
@@ -4,6 +4,7 @@
 #define cmCPackExternalGenerator_h
 
 #include "cmCPackGenerator.h"
+
 #include "cm_sys_stat.h"
 
 #include <memory>
diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h
index fc00b09000..33026c1d9d 100644
--- a/Source/CPack/cmCPackGenerator.h
+++ b/Source/CPack/cmCPackGenerator.h
@@ -10,9 +10,10 @@
 #include <string>
 #include <vector>
 
+#include "cm_sys_stat.h"
+
 #include "cmCPackComponentGroup.h"
 #include "cmSystemTools.h"
-#include "cm_sys_stat.h"
 
 class cmCPackLog;
 class cmGlobalGenerator;
diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx
index 992299a6f2..cd65694c83 100644
--- a/Source/CPack/cmCPackOSXX11Generator.cxx
+++ b/Source/CPack/cmCPackOSXX11Generator.cxx
@@ -4,13 +4,14 @@
 
 #include <sstream>
 
+#include "cm_sys_stat.h"
+
 #include "cmCPackGenerator.h"
 #include "cmCPackLog.h"
 #include "cmDuration.h"
 #include "cmGeneratedFileStream.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
-#include "cm_sys_stat.h"
 
 cmCPackOSXX11Generator::cmCPackOSXX11Generator() = default;
 
diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx
index eb48c378cb..eb1e24c735 100644
--- a/Source/CPack/cmCPackSTGZGenerator.cxx
+++ b/Source/CPack/cmCPackSTGZGenerator.cxx
@@ -8,11 +8,12 @@
 #include <string>
 #include <vector>
 
+#include "cm_sys_stat.h"
+
 #include "cmArchiveWrite.h"
 #include "cmCPackGenerator.h"
 #include "cmCPackLog.h"
 #include "cmSystemTools.h"
-#include "cm_sys_stat.h"
 
 cmCPackSTGZGenerator::cmCPackSTGZGenerator()
   : cmCPackArchiveGenerator(cmArchiveWrite::CompressGZip, "paxr", ".sh")
diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h
index a62c301e4f..14f70bf81a 100644
--- a/Source/CTest/cmCTestBuildCommand.h
+++ b/Source/CTest/cmCTestBuildCommand.h
@@ -12,7 +12,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmCTestBuildHandler;
 class cmCTestGenericHandler;
diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx
index b9b90c867c..5baeecd360 100644
--- a/Source/CTest/cmCTestCVS.cxx
+++ b/Source/CTest/cmCTestCVS.cxx
@@ -7,10 +7,12 @@
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 #include "cmXMLWriter.h"
-#include "cm_string_view.hxx"
 
 #include "cmsys/FStream.hxx"
 #include "cmsys/RegularExpression.hxx"
+
+#include <cm/string_view>
+
 #include <utility>
 
 cmCTestCVS::cmCTestCVS(cmCTest* ct, std::ostream& log)
diff --git a/Source/CTest/cmCTestConfigureCommand.h b/Source/CTest/cmCTestConfigureCommand.h
index 4677c835d8..36ca7d545e 100644
--- a/Source/CTest/cmCTestConfigureCommand.h
+++ b/Source/CTest/cmCTestConfigureCommand.h
@@ -11,7 +11,7 @@
 #include <string>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmCTestGenericHandler;
 
diff --git a/Source/CTest/cmCTestCoverageCommand.h b/Source/CTest/cmCTestCoverageCommand.h
index 24b96c02db..75aefdfabd 100644
--- a/Source/CTest/cmCTestCoverageCommand.h
+++ b/Source/CTest/cmCTestCoverageCommand.h
@@ -12,7 +12,7 @@
 #include <string>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmCTestGenericHandler;
 
diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
index 84250cbcf1..4232b9edc4 100644
--- a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
+++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
@@ -12,7 +12,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmExecutionStatus;
 
diff --git a/Source/CTest/cmCTestMemCheckCommand.h b/Source/CTest/cmCTestMemCheckCommand.h
index 837a687e27..5dad4e7dca 100644
--- a/Source/CTest/cmCTestMemCheckCommand.h
+++ b/Source/CTest/cmCTestMemCheckCommand.h
@@ -7,7 +7,7 @@
 
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCTestTestCommand.h"
 #include "cmCommand.h"
diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.h b/Source/CTest/cmCTestReadCustomFilesCommand.h
index db2ac5e2c4..8199cbcbe1 100644
--- a/Source/CTest/cmCTestReadCustomFilesCommand.h
+++ b/Source/CTest/cmCTestReadCustomFilesCommand.h
@@ -12,7 +12,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmExecutionStatus;
 
diff --git a/Source/CTest/cmCTestRunScriptCommand.h b/Source/CTest/cmCTestRunScriptCommand.h
index 6961f6e813..d262a830a0 100644
--- a/Source/CTest/cmCTestRunScriptCommand.h
+++ b/Source/CTest/cmCTestRunScriptCommand.h
@@ -12,7 +12,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmExecutionStatus;
 
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
index 3629a50c26..d8a5923765 100644
--- a/Source/CTest/cmCTestRunTest.cxx
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -20,7 +20,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 cmCTestRunTest::cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler)
   : MultiTestHandler(multiHandler)
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index 354e3c4188..c988e3ac7c 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -5,7 +5,7 @@
 #include "cmsys/Directory.hxx"
 #include "cmsys/Process.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCTest.h"
 #include "cmCTestBuildCommand.h"
diff --git a/Source/CTest/cmCTestSleepCommand.h b/Source/CTest/cmCTestSleepCommand.h
index 7b170810b9..b98079d2e8 100644
--- a/Source/CTest/cmCTestSleepCommand.h
+++ b/Source/CTest/cmCTestSleepCommand.h
@@ -12,7 +12,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmExecutionStatus;
 
diff --git a/Source/CTest/cmCTestStartCommand.h b/Source/CTest/cmCTestStartCommand.h
index 7c71f3646c..598c937af2 100644
--- a/Source/CTest/cmCTestStartCommand.h
+++ b/Source/CTest/cmCTestStartCommand.h
@@ -13,7 +13,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmExecutionStatus;
 
diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx
index d16aac0290..2e2cf1abd1 100644
--- a/Source/CTest/cmCTestSubmitCommand.cxx
+++ b/Source/CTest/cmCTestSubmitCommand.cxx
@@ -13,7 +13,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmExecutionStatus;
 
diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h
index d74136cf80..a9ba3abac3 100644
--- a/Source/CTest/cmCTestTestCommand.h
+++ b/Source/CTest/cmCTestTestCommand.h
@@ -11,7 +11,7 @@
 #include <string>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmCTestGenericHandler;
 
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 10f9f9b172..ee0d8c8f7b 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -2,7 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestTestHandler.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmCTest.h"
diff --git a/Source/CTest/cmCTestUpdateCommand.h b/Source/CTest/cmCTestUpdateCommand.h
index 55c4b8038b..5b0e07e768 100644
--- a/Source/CTest/cmCTestUpdateCommand.h
+++ b/Source/CTest/cmCTestUpdateCommand.h
@@ -11,7 +11,7 @@
 #include <string>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmCTestGenericHandler;
 
diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx
index a6a354259e..c4cb233f98 100644
--- a/Source/CTest/cmCTestUpdateHandler.cxx
+++ b/Source/CTest/cmCTestUpdateHandler.cxx
@@ -20,7 +20,7 @@
 #include <chrono>
 #include <sstream>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 static const char* cmCTestUpdateHandlerUpdateStrings[] = {
   "Unknown", "CVS", "SVN", "BZR", "GIT", "HG", "P4"
diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h
index 9e49769087..39314f24ae 100644
--- a/Source/CTest/cmCTestUploadCommand.h
+++ b/Source/CTest/cmCTestUploadCommand.h
@@ -12,7 +12,7 @@
 #include <string>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 class cmCTestGenericHandler;
 
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 60b746c74a..06ea9f625b 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -238,81 +238,4 @@ typename Range::const_iterator cmFindNot(Range const& r, T const& t)
   return std::find_if(r.begin(), r.end(), [&t](T const& i) { return i != t; });
 }
 
-template <class Iter>
-std::reverse_iterator<Iter> cmMakeReverseIterator(Iter it)
-{
-  return std::reverse_iterator<Iter>(it);
-}
-
-namespace cm {
-
-#if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
-
-using std::size;
-
-#else
-
-// std::size backport from C++17.
-template <class C>
-#  if !defined(_MSC_VER) || _MSC_VER >= 1900
-constexpr
-#  endif
-  auto
-  size(C const& c) -> decltype(c.size())
-{
-  return c.size();
-}
-
-template <typename T, size_t N>
-#  if !defined(_MSC_VER) || _MSC_VER >= 1900
-constexpr
-#  endif
-  std::size_t
-  size(const T (&)[N]) throw()
-{
-  return N;
-}
-
-#endif
-
-template <typename T>
-int isize(const T& t)
-{
-  return static_cast<int>(cm::size(t));
-}
-
-#if __cplusplus >= 201402L || defined(_MSVC_LANG) && _MSVC_LANG >= 201402L
-
-using std::cbegin;
-using std::cend;
-
-#else
-
-// std::c{begin,end} backport from C++14
-template <class C>
-#  if defined(_MSC_VER) && _MSC_VER < 1900
-auto cbegin(C const& c)
-#  else
-constexpr auto cbegin(C const& c) noexcept(noexcept(std::begin(c)))
-#  endif
-  -> decltype(std::begin(c))
-{
-  return std::begin(c);
-}
-
-template <class C>
-#  if defined(_MSC_VER) && _MSC_VER < 1900
-auto cend(C const& c)
-#  else
-constexpr auto cend(C const& c) noexcept(noexcept(std::end(c)))
-#  endif
-  -> decltype(std::end(c))
-{
-  return std::end(c);
-}
-
-#endif
-
-} // namespace cm
-
 #endif
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h
index 6cfe946336..b6798bca88 100644
--- a/Source/cmArgumentParser.h
+++ b/Source/cmArgumentParser.h
@@ -6,7 +6,7 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <cassert>
 #include <functional>
diff --git a/Source/cmBinUtilsLinuxELFLinker.cxx b/Source/cmBinUtilsLinuxELFLinker.cxx
index 6316a29394..a1125a92c9 100644
--- a/Source/cmBinUtilsLinuxELFLinker.cxx
+++ b/Source/cmBinUtilsLinuxELFLinker.cxx
@@ -15,7 +15,7 @@
 
 #include <sstream>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 static std::string ReplaceOrigin(const std::string& rpath,
                                  const std::string& origin)
diff --git a/Source/cmBinUtilsMacOSMachOLinker.cxx b/Source/cmBinUtilsMacOSMachOLinker.cxx
index 7ff8584682..b1f718b674 100644
--- a/Source/cmBinUtilsMacOSMachOLinker.cxx
+++ b/Source/cmBinUtilsMacOSMachOLinker.cxx
@@ -12,7 +12,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 cmBinUtilsMacOSMachOLinker::cmBinUtilsMacOSMachOLinker(
   cmRuntimeDependencyArchive* archive)
diff --git a/Source/cmBinUtilsWindowsPELinker.cxx b/Source/cmBinUtilsWindowsPELinker.cxx
index 5a9ad66866..bfafaeb674 100644
--- a/Source/cmBinUtilsWindowsPELinker.cxx
+++ b/Source/cmBinUtilsWindowsPELinker.cxx
@@ -12,7 +12,7 @@
 #include <sstream>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #ifdef _WIN32
 #  include <windows.h>
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 5e17ce8b4a..1031f407d2 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -29,7 +29,7 @@
 #  include <unistd.h> // IWYU pragma: keep
 #endif
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmCTestBuildAndTestHandler.h"
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 38fcf5ba8a..262590bcdb 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -1,7 +1,7 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommands.h"
 #include "cmPolicies.h"
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 2ee4ca272f..ce2c0aea20 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -23,7 +23,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 /*
 
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index f9f9581cdf..ff683add81 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -6,7 +6,7 @@
 #include "cm_rhash.h"
 #include "cmsys/FStream.hxx"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 static unsigned int const cmCryptoHashAlgoToId[] = {
   /* clang-format needs this comment to break after the opening brace */
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 145ff9198b..05552bd6ae 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -5,7 +5,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <cstddef>
 #include <memory>
diff --git a/Source/cmCustomCommandLines.h b/Source/cmCustomCommandLines.h
index 213aeb106f..ead579280a 100644
--- a/Source/cmCustomCommandLines.h
+++ b/Source/cmCustomCommandLines.h
@@ -9,7 +9,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_string_view.hxx" // IWYU pragma: keep
+#include <cm/string_view> // IWYU pragma: keep
 
 /** Data structure to represent a single command line.  */
 class cmCustomCommandLine : public std::vector<std::string>
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 2a117c1494..32f47b00e6 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -2,7 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmDefinitions.h"
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <cassert>
 #include <functional>
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 008821dda1..72e88b5304 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -5,11 +5,12 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cm_string_view.hxx"
-
 #include "cmLinkedTree.h"
+
 #include "cmString.hxx"
 
+#include <cm/string_view>
+
 #include <functional>
 #include <string>
 #include <unordered_map>
diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx
index 63a96d01e5..18b49b8682 100644
--- a/Source/cmDependsJavaParserHelper.cxx
+++ b/Source/cmDependsJavaParserHelper.cxx
@@ -5,8 +5,8 @@
 #include "cmDependsJavaLexer.h"
 #include "cmSystemTools.h"
 
-#include "cm_string_view.hxx"
 #include "cmsys/FStream.hxx"
+#include <cm/string_view>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index 12f996df53..06b55118b5 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -4,8 +4,8 @@
 
 #include "cmAlgorithms.h"
 #include "cm_kwiml.h"
-#include "cm_memory.hxx"
 #include "cmsys/FStream.hxx"
+#include <cm/memory>
 #include <cstddef>
 #include <map>
 #include <memory>
diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h
index 50463afdbb..819a3c39ab 100644
--- a/Source/cmExportCommand.h
+++ b/Source/cmExportCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index e588f7bfe8..f9a28cd521 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -24,7 +24,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 static std::string cmExportFileGeneratorEscape(std::string const& str)
 {
diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx
index bab394a7cd..fd2401e31a 100644
--- a/Source/cmExportLibraryDependenciesCommand.cxx
+++ b/Source/cmExportLibraryDependenciesCommand.cxx
@@ -6,7 +6,7 @@
 #include <map>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmExecutionStatus.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/cmFSPermissions.h b/Source/cmFSPermissions.h
index 7a6e708660..fef72e6164 100644
--- a/Source/cmFSPermissions.h
+++ b/Source/cmFSPermissions.h
@@ -5,10 +5,10 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cm_sys_stat.h"
-
 #include <string>
 
+#include "cm_sys_stat.h"
+
 namespace cmFSPermissions {
 
 // Table of permissions flags.
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 4701d29d01..c7a0e55127 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -20,7 +20,9 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+
+#include "cm_sys_stat.h"
 
 #include "cmAlgorithms.h"
 #include "cmArgumentParser.h"
@@ -44,7 +46,6 @@
 #include "cmSubcommandTable.h"
 #include "cmSystemTools.h"
 #include "cmTimestamp.h"
-#include "cm_sys_stat.h"
 #include "cmake.h"
 
 #if !defined(CMAKE_BOOTSTRAP)
diff --git a/Source/cmFileCopier.h b/Source/cmFileCopier.h
index 263a365619..8fc481ce03 100644
--- a/Source/cmFileCopier.h
+++ b/Source/cmFileCopier.h
@@ -6,9 +6,10 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cmFileTimeCache.h"
-#include "cm_sys_stat.h"
 #include "cmsys/RegularExpression.hxx"
 
+#include "cm_sys_stat.h"
+
 #include <string>
 #include <vector>
 
diff --git a/Source/cmFileTimes.cxx b/Source/cmFileTimes.cxx
index 3824e9b023..54ac4edd5d 100644
--- a/Source/cmFileTimes.cxx
+++ b/Source/cmFileTimes.cxx
@@ -2,11 +2,11 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmFileTimes.h"
 
-#include "cm_sys_stat.h"
-
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+
+#include "cm_sys_stat.h"
 
 #if defined(_WIN32)
 #  include "cmSystemTools.h"
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index fea7e08b85..17e9869e8c 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -18,7 +18,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmMakefile.h"
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index d563a1d711..44392baa75 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -6,9 +6,10 @@
 #include <cstdlib>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/string_view>
+
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
 
 #include "cmExecutionStatus.h"
 #include "cmFunctionBlocker.h"
diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h
index 87bdccdc6d..59bb8927fb 100644
--- a/Source/cmFunctionBlocker.h
+++ b/Source/cmFunctionBlocker.h
@@ -7,7 +7,7 @@
 
 #include <vector>
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include "cmListFileCache.h"
 
diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
index fdc5e50f78..b3ddfe01f3 100644
--- a/Source/cmFunctionCommand.cxx
+++ b/Source/cmFunctionCommand.cxx
@@ -5,9 +5,10 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/string_view>
+
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
 
 #include "cmAlgorithms.h"
 #include "cmExecutionStatus.h"
diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h
index 06ebeac8ed..c3bc4c85b9 100644
--- a/Source/cmGeneratorExpressionEvaluationFile.h
+++ b/Source/cmGeneratorExpressionEvaluationFile.h
@@ -10,9 +10,10 @@
 #include <string>
 #include <vector>
 
+#include "cm_sys_stat.h"
+
 #include "cmGeneratorExpression.h"
 #include "cmPolicies.h"
-#include "cm_sys_stat.h"
 
 class cmLocalGenerator;
 
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 6cb7a962a6..d5248677ee 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -29,12 +29,13 @@
 #include "cmsys/RegularExpression.hxx"
 #include "cmsys/String.h"
 
+#include <cm/iterator>
+
 #include <algorithm>
 #include <cassert>
 #include <cerrno>
 #include <cstdlib>
 #include <cstring>
-#include <iterator>
 #include <map>
 #include <memory>
 #include <set>
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 3a321c559f..136996ea7d 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -17,6 +17,8 @@
 #include <unordered_set>
 #include <utility>
 
+#include <cm/string_view>
+
 #include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
 #include "cmCustomCommand.h"
@@ -42,7 +44,6 @@
 #include "cmTarget.h"
 #include "cmTargetLinkLibraryType.h"
 #include "cmTargetPropertyComputer.h"
-#include "cm_string_view.hxx"
 #include "cmake.h"
 
 class cmMessenger;
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 9ce6324749..7bba874a7b 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -12,7 +12,7 @@
 #include <iterator>
 #include <sstream>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmDocumentationEntry.h"
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index c7a0330eae..0b211b8b2f 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -7,7 +7,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmDocumentationEntry.h"
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index b3557758d7..92316d336a 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -11,10 +11,11 @@
 #include "cmState.h"
 #include "cmStringAlgorithms.h"
 #include "cmUuid.h"
-#include "cm_string_view.hxx"
 #include "cmake.h"
 #include "cmsys/Encoding.hxx"
 
+#include <cm/string_view>
+
 #include <assert.h>
 #include <vector>
 #include <windows.h>
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index a0ce74081e..61e8f58133 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -10,7 +10,8 @@
 #include <shellapi.h>
 #include <windows.h>
 
-#include "cmAlgorithms.h"
+#include <cm/iterator>
+
 #include "cmCallVisualStudioMacro.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 4d41fd7c8b..643cc997d4 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -9,7 +9,7 @@
 #include <iomanip>
 #include <sstream>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index f719041411..b36d96b0f7 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -2,9 +2,10 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmIfCommand.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/string_view>
+
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
 
 #include "cmConditionEvaluator.h"
 #include "cmExecutionStatus.h"
diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h
index 4df94ebc2c..bcaae9d857 100644
--- a/Source/cmIncludeDirectoryCommand.h
+++ b/Source/cmIncludeDirectoryCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h
index 28bf443f54..9ffb84213b 100644
--- a/Source/cmInstallCommand.h
+++ b/Source/cmInstallCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h
index 1a439debbf..489d90fce5 100644
--- a/Source/cmLinkDirectoriesCommand.h
+++ b/Source/cmLinkDirectoriesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 826abf55be..7bf35c350d 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -16,7 +16,8 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+
 #include "cm_static_string_view.hxx"
 
 #include "cmAlgorithms.h"
diff --git a/Source/cmLoadCacheCommand.h b/Source/cmLoadCacheCommand.h
index 45e52f022a..37f037273b 100644
--- a/Source/cmLoadCacheCommand.h
+++ b/Source/cmLoadCacheCommand.h
@@ -9,7 +9,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx
index 6f5df468a2..1e026327dc 100644
--- a/Source/cmLoadCommandCommand.cxx
+++ b/Source/cmLoadCommandCommand.cxx
@@ -10,7 +10,7 @@
 
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCPluginAPI.cxx"
 #include "cmCPluginAPI.h"
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index afcd69f48c..840f55fcb9 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -30,7 +30,6 @@
 #include "cmTarget.h"
 #include "cmTestGenerator.h"
 #include "cmVersion.h"
-#include "cm_string_view.hxx"
 #include "cmake.h"
 #include "cmsys/RegularExpression.hxx"
 
@@ -39,6 +38,8 @@
 #  include "cmCryptoHash.h"
 #endif
 
+#include <cm/string_view>
+
 #include <algorithm>
 #include <cassert>
 #include <cstdio>
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index f80695dfc2..6c1dfc92d8 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -9,7 +9,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmCustomCommand.h" // IWYU pragma: keep
diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx
index bec3ad839c..ee5eb0028f 100644
--- a/Source/cmMachO.cxx
+++ b/Source/cmMachO.cxx
@@ -9,7 +9,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 // Include the Mach-O format information system header.
 #include <mach-o/fat.h>
diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx
index af97761fcd..ba9947a335 100644
--- a/Source/cmMacroCommand.cxx
+++ b/Source/cmMacroCommand.cxx
@@ -5,9 +5,10 @@
 #include <cstdio>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/string_view>
+
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
 
 #include "cmAlgorithms.h"
 #include "cmExecutionStatus.h"
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index c59393938c..c67c3670c7 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -10,12 +10,11 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
-#include <iterator>
-#include <memory>
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/iterator>
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmCommandArgumentParserHelper.h"
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 6d695a7689..bf405a5980 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -17,7 +17,7 @@
 #include <unordered_map>
 #include <vector>
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include "cmAlgorithms.h"
 #include "cmListFileCache.h"
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index e44ca7b0aa..91bd47e101 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -8,7 +8,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index b37a933caf..faa0d6753a 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -8,7 +8,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmGeneratedFileStream.h"
diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx
index d4045b392e..47e26655ea 100644
--- a/Source/cmMakefileUtilityTargetGenerator.cxx
+++ b/Source/cmMakefileUtilityTargetGenerator.cxx
@@ -7,7 +7,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorTarget.h"
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 97742c1b19..bd5abd1b98 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -10,7 +10,7 @@
 #include <sstream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmCustomCommand.h" // IWYU pragma: keep
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 37e9e0e90a..8c88f6c0f9 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -11,7 +11,7 @@
 #include <ostream>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index 671efe740f..c2053c7a91 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -6,7 +6,8 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cmStateSnapshot.h"
-#include "cm_string_view.hxx"
+
+#include <cm/string_view>
 
 #include <string>
 
diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx
index 0b320b6587..c802fb45c7 100644
--- a/Source/cmParseArgumentsCommand.cxx
+++ b/Source/cmParseArgumentsCommand.cxx
@@ -14,7 +14,7 @@
 #include "cmRange.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 static std::string EscapeArg(const std::string& arg)
 {
diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h
index 8b9bcc8c32..ffbd3305ba 100644
--- a/Source/cmProjectCommand.h
+++ b/Source/cmProjectCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h
index 71969ee7d9..2a28c1ef8e 100644
--- a/Source/cmQtAutoGen.h
+++ b/Source/cmQtAutoGen.h
@@ -5,7 +5,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <memory>
 #include <string>
diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx
index abc69d0af3..576a034cc4 100644
--- a/Source/cmQtAutoGenGlobalInitializer.cxx
+++ b/Source/cmQtAutoGenGlobalInitializer.cxx
@@ -17,7 +17,7 @@
 #include "cmSystemTools.h"
 #include "cmTarget.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include <utility>
 
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index ad4e4d58e6..904572262b 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -41,7 +41,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 namespace {
 
diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h
index bedda30f2e..7ce9fad9e9 100644
--- a/Source/cmQtAutoGenInitializer.h
+++ b/Source/cmQtAutoGenInitializer.h
@@ -6,7 +6,8 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmGeneratedFileStream.h"
 #include "cmQtAutoGen.h"
-#include "cm_string_view.hxx"
+
+#include <cm/string_view>
 
 #include <map>
 #include <memory>
diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx
index 086b68cb8b..eb829faea9 100644
--- a/Source/cmQtAutoGenerator.cxx
+++ b/Source/cmQtAutoGenerator.cxx
@@ -2,7 +2,8 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmQtAutoGenerator.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+
 #include "cmsys/FStream.hxx"
 
 #include "cmGlobalGenerator.h"
diff --git a/Source/cmQtAutoGenerator.h b/Source/cmQtAutoGenerator.h
index 371b25c58d..f60acb0531 100644
--- a/Source/cmQtAutoGenerator.h
+++ b/Source/cmQtAutoGenerator.h
@@ -7,7 +7,8 @@
 
 #include "cmFileTime.h"
 #include "cmQtAutoGen.h"
-#include "cm_string_view.hxx"
+
+#include <cm/string_view>
 
 #include <mutex>
 #include <string>
diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx
index 4e4875eed1..5cd1ba17f8 100644
--- a/Source/cmQtAutoMocUic.cxx
+++ b/Source/cmQtAutoMocUic.cxx
@@ -2,6 +2,12 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmQtAutoMocUic.h"
 
+#include <algorithm>
+#include <set>
+#include <utility>
+
+#include <cm/memory>
+
 #include "cmAlgorithms.h"
 #include "cmCryptoHash.h"
 #include "cmGeneratedFileStream.h"
@@ -9,13 +15,9 @@
 #include "cmQtAutoGen.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
-#include "cm_memory.hxx"
 #include "cmake.h"
 #include "cmsys/FStream.hxx"
 
-#include <algorithm>
-#include <set>
-#include <utility>
 #if defined(__APPLE__)
 #  include <unistd.h>
 #endif
diff --git a/Source/cmQtAutoMocUic.h b/Source/cmQtAutoMocUic.h
index 43123f2ca5..15b66ca248 100644
--- a/Source/cmQtAutoMocUic.h
+++ b/Source/cmQtAutoMocUic.h
@@ -9,9 +9,10 @@
 #include "cmQtAutoGen.h"
 #include "cmQtAutoGenerator.h"
 #include "cmWorkerPool.h"
-#include "cm_string_view.hxx"
 #include "cmsys/RegularExpression.hxx"
 
+#include <cm/string_view>
+
 #include <atomic>
 #include <cstddef>
 #include <map>
diff --git a/Source/cmQtAutoRcc.cxx b/Source/cmQtAutoRcc.cxx
index cd3e0345c8..1bf8ca418d 100644
--- a/Source/cmQtAutoRcc.cxx
+++ b/Source/cmQtAutoRcc.cxx
@@ -11,7 +11,8 @@
 #include "cmQtAutoGen.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
-#include "cm_string_view.hxx"
+
+#include <cm/string_view>
 
 #include <algorithm>
 
diff --git a/Source/cmRuntimeDependencyArchive.cxx b/Source/cmRuntimeDependencyArchive.cxx
index 1b3f3870cf..ed2e3e481d 100644
--- a/Source/cmRuntimeDependencyArchive.cxx
+++ b/Source/cmRuntimeDependencyArchive.cxx
@@ -27,7 +27,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #if defined(_WIN32)
 static void AddVisualStudioPath(std::vector<std::string>& paths,
diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx
index 9df1883cc6..f150cf37cf 100644
--- a/Source/cmServer.cxx
+++ b/Source/cmServer.cxx
@@ -20,7 +20,8 @@
 #include <mutex>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/shared_mutex>
 
 void on_signal(uv_signal_t* signal, int signum)
 {
diff --git a/Source/cmServer.h b/Source/cmServer.h
index ab2ad239fd..9b1260436d 100644
--- a/Source/cmServer.h
+++ b/Source/cmServer.h
@@ -5,11 +5,12 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cm_jsoncpp_value.h"
-#include "cm_thread.hxx"
 #include "cm_uv.h"
 
 #include "cmUVHandlePtr.h"
 
+#include <cm/shared_mutex>
+
 #include <memory>
 #include <string>
 #include <vector>
diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx
index d576f36464..f889129ef2 100644
--- a/Source/cmServerProtocol.cxx
+++ b/Source/cmServerProtocol.cxx
@@ -23,7 +23,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 // Get rid of some windows macros:
 #undef max
diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h
index 7e4606e5be..e77b7527c0 100644
--- a/Source/cmSetTargetPropertiesCommand.h
+++ b/Source/cmSetTargetPropertiesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmSourceGroupCommand.h b/Source/cmSourceGroupCommand.h
index 87a611468a..6273d92742 100644
--- a/Source/cmSourceGroupCommand.h
+++ b/Source/cmSourceGroupCommand.h
@@ -9,7 +9,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 7463bf8d80..93ad2d78bd 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -9,7 +9,7 @@
 #include <cstring>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCacheManager.h"
 #include "cmCommand.h"
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx
index ede00a0219..1262f53d97 100644
--- a/Source/cmStateDirectory.cxx
+++ b/Source/cmStateDirectory.cxx
@@ -5,9 +5,10 @@
 
 #include <algorithm>
 #include <cassert>
-#include <iterator>
 #include <vector>
 
+#include <cm/iterator>
+
 #include "cmAlgorithms.h"
 #include "cmProperty.h"
 #include "cmPropertyMap.h"
@@ -177,7 +178,7 @@ cmStringRange GetPropertyContent(T const& content, U contentEndPosition)
 {
   auto end = content.begin() + contentEndPosition;
 
-  auto rbegin = cmMakeReverseIterator(end);
+  auto rbegin = cm::make_reverse_iterator(end);
   rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
 
   return cmMakeRange(rbegin.base(), end);
@@ -189,7 +190,7 @@ cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces,
 {
   auto entryEnd = content.begin() + contentEndPosition;
 
-  auto rbegin = cmMakeReverseIterator(entryEnd);
+  auto rbegin = cm::make_reverse_iterator(entryEnd);
   rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
 
   auto it = backtraces.begin() + std::distance(content.begin(), rbegin.base());
@@ -270,7 +271,7 @@ void cmStateDirectory::PrependIncludeDirectoriesEntry(
     this->Snapshot_.Position->IncludeDirectoryPosition;
 
   auto rend = this->DirectoryState->IncludeDirectories.rend();
-  auto rbegin = cmMakeReverseIterator(entryEnd);
+  auto rbegin = cm::make_reverse_iterator(entryEnd);
   rbegin = std::find(rbegin, rend, cmPropertySentinal);
 
   auto entryIt = rbegin.base();
@@ -440,7 +441,7 @@ void cmStateDirectory::PrependLinkDirectoriesEntry(
     this->Snapshot_.Position->LinkDirectoriesPosition;
 
   auto rend = this->DirectoryState->LinkDirectories.rend();
-  auto rbegin = cmMakeReverseIterator(entryEnd);
+  auto rbegin = cm::make_reverse_iterator(entryEnd);
   rbegin = std::find(rbegin, rend, cmPropertySentinal);
 
   auto entryIt = rbegin.base();
diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx
index 28d5170bf6..645907c21e 100644
--- a/Source/cmStateSnapshot.cxx
+++ b/Source/cmStateSnapshot.cxx
@@ -5,10 +5,10 @@
 
 #include <algorithm>
 #include <cassert>
-#include <iterator>
 #include <string>
 
-#include "cmAlgorithms.h"
+#include <cm/iterator>
+
 #include "cmDefinitions.h"
 #include "cmListFileCache.h"
 #include "cmPropertyMap.h"
@@ -279,7 +279,7 @@ void InitializeContentFromParent(T& parentContent, T& thisContent,
   auto parentBegin = parentContent.begin();
   auto parentEnd = parentContent.end();
 
-  auto parentRbegin = cmMakeReverseIterator(parentEnd);
+  auto parentRbegin = cm::make_reverse_iterator(parentEnd);
   auto parentRend = parentContent.rend();
   parentRbegin = std::find(parentRbegin, parentRend, cmPropertySentinal);
   auto parentIt = parentRbegin.base();
diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h
index da39127100..021fd53c13 100644
--- a/Source/cmStateSnapshot.h
+++ b/Source/cmStateSnapshot.h
@@ -9,7 +9,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include "cmLinkedTree.h"
 #include "cmPolicies.h"
diff --git a/Source/cmString.hxx b/Source/cmString.hxx
index a401ad1059..6223b78400 100644
--- a/Source/cmString.hxx
+++ b/Source/cmString.hxx
@@ -6,7 +6,7 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <algorithm>
 #include <cstddef>
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index cb6b8ba9ff..6631e98251 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -6,7 +6,9 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cmRange.h"
-#include "cm_string_view.hxx"
+
+#include <cm/string_view>
+
 #include <cctype>
 #include <cstring>
 #include <initializer_list>
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 809d05e135..28616c2e64 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -9,12 +9,12 @@
 #include <cctype>
 #include <cstdio>
 #include <cstdlib>
-#include <iterator>
 #include <memory>
 
+#include <cm/iterator>
+
 #include "cm_static_string_view.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmCryptoHash.h"
 #include "cmExecutionStatus.h"
 #include "cmGeneratorExpression.h"
diff --git a/Source/cmSubcommandTable.h b/Source/cmSubcommandTable.h
index 21342bbab6..6e39a1f4e5 100644
--- a/Source/cmSubcommandTable.h
+++ b/Source/cmSubcommandTable.h
@@ -6,7 +6,8 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
+
+#include <cm/string_view>
 
 #include <initializer_list>
 #include <string>
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index e7eef338b6..108215cde7 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -8,9 +8,9 @@
 #include "cmCryptoHash.h"
 #include "cmDuration.h"
 #include "cmProcessOutput.h"
-#include "cm_string_view.hxx"
 #include "cmsys/Process.h"
 #include "cmsys/SystemTools.hxx" // IWYU pragma: export
+#include <cm/string_view>
 #include <cstddef>
 #include <functional>
 #include <string>
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 8900ebf0c1..ca12c873c5 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -12,7 +12,7 @@
 #include <sstream>
 #include <unordered_set>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmAlgorithms.h"
 #include "cmCustomCommand.h"
diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h
index 25af21d10b..f85dc0a9c5 100644
--- a/Source/cmTargetCompileDefinitionsCommand.h
+++ b/Source/cmTargetCompileDefinitionsCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h
index 07948fa252..39597ca22f 100644
--- a/Source/cmTargetCompileFeaturesCommand.h
+++ b/Source/cmTargetCompileFeaturesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h
index a571cfba8c..b328ba2f09 100644
--- a/Source/cmTargetCompileOptionsCommand.h
+++ b/Source/cmTargetCompileOptionsCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h
index 6defab248a..f6481dbf12 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.h
+++ b/Source/cmTargetIncludeDirectoriesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTargetLinkDirectoriesCommand.h b/Source/cmTargetLinkDirectoriesCommand.h
index a2fcfa9d8c..a651d73f4f 100644
--- a/Source/cmTargetLinkDirectoriesCommand.h
+++ b/Source/cmTargetLinkDirectoriesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index 6698ce0056..caf2cf4af3 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetLinkLibraryType.h"
diff --git a/Source/cmTargetLinkOptionsCommand.h b/Source/cmTargetLinkOptionsCommand.h
index 3710739dab..918a8d7a8a 100644
--- a/Source/cmTargetLinkOptionsCommand.h
+++ b/Source/cmTargetLinkOptionsCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTargetPrecompileHeadersCommand.h b/Source/cmTargetPrecompileHeadersCommand.h
index 1ddf2afcfc..7e4558e5e3 100644
--- a/Source/cmTargetPrecompileHeadersCommand.h
+++ b/Source/cmTargetPrecompileHeadersCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 
diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h
index 90fd45f415..1cff8c3361 100644
--- a/Source/cmTargetSourcesCommand.h
+++ b/Source/cmTargetSourcesCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmTargetPropCommandBase.h"
diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h
index ec9f8b8e91..e525e851fb 100644
--- a/Source/cmTryCompileCommand.h
+++ b/Source/cmTryCompileCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmCoreTryCompile.h"
diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h
index bacfcdb80b..c53a69474d 100644
--- a/Source/cmTryRunCommand.h
+++ b/Source/cmTryRunCommand.h
@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 #include "cmCommand.h"
 #include "cmCoreTryCompile.h"
diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx
index 2c37a642cc..3adc47a7a4 100644
--- a/Source/cmUVProcessChain.cxx
+++ b/Source/cmUVProcessChain.cxx
@@ -13,7 +13,7 @@
 #include <iterator>
 #include <utility>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 struct cmUVProcessChain::InternalData
 {
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index ba722940ff..4b835958a3 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -21,7 +21,7 @@
 #include <iterator>
 #include <set>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 static void ConvertToWindowsSlash(std::string& s);
 
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
index 3e423e98ea..1139aa9745 100644
--- a/Source/cmVisualStudioGeneratorOptions.cxx
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -1,5 +1,7 @@
 #include "cmVisualStudioGeneratorOptions.h"
 
+#include <cm/iterator>
+
 #include "cmAlgorithms.h"
 #include "cmLocalVisualStudioGenerator.h"
 #include "cmOutputConverter.h"
@@ -269,8 +271,8 @@ void cmVisualStudioGeneratorOptions::FixManifestUACFlags()
     }
 
     if (keyValue[1].front() == '\'' && keyValue[1].back() == '\'') {
-      keyValue[1] =
-        keyValue[1].substr(1, std::max(0, cm::isize(keyValue[1]) - 2));
+      keyValue[1] = keyValue[1].substr(
+        1, std::max(std::string::size_type(0), keyValue[1].length() - 2));
     }
 
     if (keyValue[0] == "level") {
diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx
index a3968529b0..bd715462aa 100644
--- a/Source/cmWhileCommand.cxx
+++ b/Source/cmWhileCommand.cxx
@@ -2,9 +2,10 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmWhileCommand.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/string_view>
+
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
 
 #include "cmConditionEvaluator.h"
 #include "cmExecutionStatus.h"
diff --git a/Source/cmWorkerPool.cxx b/Source/cmWorkerPool.cxx
index 5ac81df67d..9d279ab62a 100644
--- a/Source/cmWorkerPool.cxx
+++ b/Source/cmWorkerPool.cxx
@@ -17,7 +17,7 @@
 #include <mutex>
 #include <thread>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 /**
  * @brief libuv pipe buffer class
diff --git a/Source/cmWorkerPool.h b/Source/cmWorkerPool.h
index bf072990e4..91799223a0 100644
--- a/Source/cmWorkerPool.h
+++ b/Source/cmWorkerPool.h
@@ -10,7 +10,7 @@
 #include <utility>
 #include <vector>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 // -- Types
 class cmWorkerPoolInternal;
diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx
index fdf07bbba8..264dd3f37c 100644
--- a/Source/cmWriteFileCommand.cxx
+++ b/Source/cmWriteFileCommand.cxx
@@ -2,13 +2,14 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmWriteFileCommand.h"
 
+#include "cm_sys_stat.h"
+
 #include "cmsys/FStream.hxx"
 
 #include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
-#include "cm_sys_stat.h"
 
 // cmLibraryCommand
 bool cmWriteFileCommand(std::vector<std::string> const& args,
diff --git a/Source/cm_static_string_view.hxx b/Source/cm_static_string_view.hxx
index 1bef0c68b1..8351cd75af 100644
--- a/Source/cm_static_string_view.hxx
+++ b/Source/cm_static_string_view.hxx
@@ -5,7 +5,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <cstddef>
 
diff --git a/Source/cm_sys_stat.h b/Source/cm_sys_stat.h
index d3b9ef22a0..eb874c70f2 100644
--- a/Source/cm_sys_stat.h
+++ b/Source/cm_sys_stat.h
@@ -14,6 +14,6 @@ using gid_t = unsigned short;
 
 #include <sys/types.h>
 // include sys/stat.h after sys/types.h
-#include <sys/stat.h>
+#include <sys/stat.h> // IWYU pragma: export
 
 #endif
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 9a66805994..96d903eda5 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -2,7 +2,13 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmake.h"
 
-#include "cm_memory.hxx"
+#include <cm/memory>
+#include <cm/string_view>
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
+#  include <cm/iterator>
+#endif
+
+#include "cm_sys_stat.h"
 
 #include "cmAlgorithms.h"
 #include "cmCommands.h"
@@ -28,8 +34,6 @@
 #include "cmUtils.hxx"
 #include "cmVersionConfig.h"
 #include "cmWorkingDirectory.h"
-#include "cm_string_view.hxx"
-#include "cm_sys_stat.h"
 
 #if !defined(CMAKE_BOOTSTRAP)
 #  include "cm_jsoncpp_writer.h"
diff --git a/Tests/CMakeLib/testArgumentParser.cxx b/Tests/CMakeLib/testArgumentParser.cxx
index 788fecee65..909f71b8f1 100644
--- a/Tests/CMakeLib/testArgumentParser.cxx
+++ b/Tests/CMakeLib/testArgumentParser.cxx
@@ -4,7 +4,7 @@
 #include "cmArgumentParser.h"
 
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <initializer_list>
 #include <iostream>
diff --git a/Tests/CMakeLib/testOptional.cxx b/Tests/CMakeLib/testOptional.cxx
index a5e30fbcf2..cefe9fa380 100644
--- a/Tests/CMakeLib/testOptional.cxx
+++ b/Tests/CMakeLib/testOptional.cxx
@@ -1,9 +1,8 @@
-#include "cm_optional.hxx"
-#include "cm_utility.hxx"
+#include <cm/optional>
+#include <cm/utility>
 
 #include <iostream>
 #include <type_traits>
-#include <utility>
 #include <vector>
 
 class EventLogger;
diff --git a/Tests/CMakeLib/testString.cxx b/Tests/CMakeLib/testString.cxx
index 075892f39f..3b47a9c938 100644
--- a/Tests/CMakeLib/testString.cxx
+++ b/Tests/CMakeLib/testString.cxx
@@ -4,7 +4,7 @@
 #include "cmString.hxx"
 
 #include "cm_static_string_view.hxx"
-#include "cm_string_view.hxx"
+#include <cm/string_view>
 
 #include <cstddef>
 #include <cstring>
diff --git a/Tests/CMakeLib/testStringAlgorithms.cxx b/Tests/CMakeLib/testStringAlgorithms.cxx
index a92a910f97..4e48f6e8aa 100644
--- a/Tests/CMakeLib/testStringAlgorithms.cxx
+++ b/Tests/CMakeLib/testStringAlgorithms.cxx
@@ -3,7 +3,8 @@
 
 #include <cmConfigure.h> // IWYU pragma: keep
 
-#include "cm_string_view.hxx"
+#include <cm/string_view>
+
 #include <iostream>
 #include <sstream>
 #include <string>
diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx
index 63c99435ec..8cee49dcb4 100644
--- a/Tests/CMakeLib/testUVProcessChain.cxx
+++ b/Tests/CMakeLib/testUVProcessChain.cxx
@@ -15,7 +15,7 @@
 
 #include <csignal>
 
-#include "cm_memory.hxx"
+#include <cm/memory>
 
 struct ExpectedStatus
 {
diff --git a/Utilities/IWYU/mapping.imp b/Utilities/IWYU/mapping.imp
index 78026fa844..ef31e8befe 100644
--- a/Utilities/IWYU/mapping.imp
+++ b/Utilities/IWYU/mapping.imp
@@ -95,7 +95,6 @@
   { include: [ "<inttypes.h>", public, "\"cm_kwiml.h\"", public ] },
 
   # Self-sufficient wrapper for <sys/stat.h>
-  { include: [ "<sys/stat.h>", public, "\"cm_sys_stat.h\"", public ] },
   { symbol: [ "mode_t", private, "\"cm_sys_stat.h\"", public ] },
 
   # Wrappers for 3rd-party libraries used from the system.
diff --git a/Utilities/std/.gitattributes b/Utilities/std/.gitattributes
new file mode 100644
index 0000000000..cd205494f3
--- /dev/null
+++ b/Utilities/std/.gitattributes
@@ -0,0 +1 @@
+cm/* our-c-style
diff --git a/Utilities/std/CMakeLists.txt b/Utilities/std/CMakeLists.txt
new file mode 100644
index 0000000000..63c0a60eae
--- /dev/null
+++ b/Utilities/std/CMakeLists.txt
@@ -0,0 +1,10 @@
+
+# source files for CMake std library
+set(SRCS cm/bits/string_view.cxx
+         cm/memory
+         cm/optional
+         cm/shared_mutex
+         cm/string_view
+         cm/utility)
+
+add_library(cmstd STATIC ${SRCS})
diff --git a/Source/cm_string_view.cxx b/Utilities/std/cm/bits/string_view.cxx
similarity index 99%
rename from Source/cm_string_view.cxx
rename to Utilities/std/cm/bits/string_view.cxx
index 61fa80e82a..3b283da4aa 100644
--- a/Source/cm_string_view.cxx
+++ b/Utilities/std/cm/bits/string_view.cxx
@@ -1,7 +1,7 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
 
-#include "cm_string_view.hxx"
+#include <cm/string_view> // IWYU pragma: associated
 
 #ifndef CMake_HAVE_CXX_STRING_VIEW
 
diff --git a/Utilities/std/cm/iterator b/Utilities/std/cm/iterator
new file mode 100644
index 0000000000..083bce33d0
--- /dev/null
+++ b/Utilities/std/cm/iterator
@@ -0,0 +1,78 @@
+// -*-c++-*-
+// vim: set ft=cpp:
+
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#ifndef cm_iterator
+#define cm_iterator
+
+#include <iterator> // IWYU pragma: export
+
+namespace cm {
+
+#if __cplusplus >= 201402L || defined(_MSVC_LANG) && _MSVC_LANG >= 201402L
+using std::make_reverse_iterator;
+
+using std::cbegin;
+using std::cend;
+#else
+template <class Iter>
+std::reverse_iterator<Iter> make_reverse_iterator(Iter it)
+{
+  return std::reverse_iterator<Iter>(it);
+}
+
+// std::c{begin,end} backport from C++14
+template <class C>
+#  if defined(_MSC_VER) && _MSC_VER < 1900
+auto cbegin(C const& c)
+#  else
+constexpr auto cbegin(C const& c) noexcept(noexcept(std::begin(c)))
+#  endif
+  -> decltype(std::begin(c))
+{
+  return std::begin(c);
+}
+
+template <class C>
+#  if defined(_MSC_VER) && _MSC_VER < 1900
+auto cend(C const& c)
+#  else
+constexpr auto cend(C const& c) noexcept(noexcept(std::end(c)))
+#  endif
+  -> decltype(std::end(c))
+{
+  return std::end(c);
+}
+#endif
+
+#if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
+using std::size;
+#else
+
+// std::size backport from C++17.
+template <class C>
+#  if !defined(_MSC_VER) || _MSC_VER >= 1900
+constexpr
+#  endif
+  auto
+  size(C const& c) -> decltype(c.size())
+{
+  return c.size();
+}
+
+template <typename T, size_t N>
+#  if !defined(_MSC_VER) || _MSC_VER >= 1900
+constexpr
+#  endif
+  std::size_t
+  size(const T (&)[N]) throw()
+{
+  return N;
+}
+
+#endif
+
+} // namespace cm
+
+#endif
diff --git a/Source/cm_memory.hxx b/Utilities/std/cm/memory
similarity index 85%
rename from Source/cm_memory.hxx
rename to Utilities/std/cm/memory
index 9f5e67827b..8ebded2779 100644
--- a/Source/cm_memory.hxx
+++ b/Utilities/std/cm/memory
@@ -1,9 +1,10 @@
+// -*-c++-*-
+// vim: set ft=cpp:
+
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cm_memory_hxx
-#define cm_memory_hxx
-
-#include "cmConfigure.h" // IWYU pragma: keep
+#ifndef cm_memory
+#define cm_memory
 
 #include <memory> // IWYU pragma: export
 #if !defined(CMake_HAVE_CXX_MAKE_UNIQUE)
diff --git a/Source/cm_optional.hxx b/Utilities/std/cm/optional
similarity index 97%
rename from Source/cm_optional.hxx
rename to Utilities/std/cm/optional
index 295571dc9c..80b0951604 100644
--- a/Source/cm_optional.hxx
+++ b/Utilities/std/cm/optional
@@ -1,20 +1,21 @@
+// -*-c++-*-
+// vim: set ft=cpp:
+
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cm_optional_hxx
-#define cm_optional_hxx
-
-#include "cmConfigure.h" // IWYU pragma: keep
+#ifndef cm_optional
+#define cm_optional
 
 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
 #  define CMake_HAVE_CXX_OPTIONAL
 #endif
 
 #if defined(CMake_HAVE_CXX_OPTIONAL)
-#  include <optional>
+#  include <optional> // IWYU pragma: export
 #else
-#  include "cm_utility.hxx"
 #  include <memory>
-#  include <utility>
+
+#  include <cm/utility>
 #endif
 
 namespace cm {
diff --git a/Source/cm_thread.hxx b/Utilities/std/cm/shared_mutex
similarity index 52%
rename from Source/cm_thread.hxx
rename to Utilities/std/cm/shared_mutex
index b1f064585d..2ac9447dc7 100644
--- a/Source/cm_thread.hxx
+++ b/Utilities/std/cm/shared_mutex
@@ -1,18 +1,36 @@
+// -*-c++-*-
+// vim: set ft=cpp:
+
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef CM_THREAD_HXX
-#define CM_THREAD_HXX
+#ifndef cm_shared_mutex
+#define cm_shared_mutex
 
-#include "cmConfigure.h" // IWYU pragma: keep
-#include "cm_uv.h"
+#if __cplusplus >= 201402L || defined(_MSVC_LANG) && _MSVC_LANG >= 201402L
+#  define CMake_HAVE_CXX_SHARED_LOCK
+#endif
+#if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
+#  define CMake_HAVE_CXX_SHARED_MUTEX
+#endif
 
-namespace cm {
+#if defined(CMake_HAVE_CXX_SHARED_LOCK)
+#  include <shared_mutex> // IWYU pragma: export
+#endif
+#if !defined(CMake_HAVE_CXX_SHARED_MUTEX)
+#  include "cm_uv.h"
+#endif
 
+namespace cm {
+#if defined(CMake_HAVE_CXX_SHARED_MUTEX)
+using std::shared_mutex;
+#else
 class shared_mutex
 {
   uv_rwlock_t _M_;
 
 public:
+  using native_handle_type = uv_rwlock_t*;
+
   shared_mutex() { uv_rwlock_init(&_M_); }
   ~shared_mutex() { uv_rwlock_destroy(&_M_); }
 
@@ -20,18 +38,27 @@ public:
   shared_mutex& operator=(shared_mutex const&) = delete;
 
   void lock() { uv_rwlock_wrlock(&_M_); }
+  bool try_lock() { return uv_rwlock_trywrlock(&_M_) == 0; }
   void unlock() { uv_rwlock_wrunlock(&_M_); }
 
   void lock_shared() { uv_rwlock_rdlock(&_M_); }
   void unlock_shared() { uv_rwlock_rdunlock(&_M_); }
+
+  native_handle_type native_handle() { return &_M_; }
 };
+#endif
 
+#if defined(CMake_HAVE_CXX_SHARED_LOCK)
+using std::shared_lock;
+#else
 template <typename T>
 class shared_lock
 {
   T& _mutex;
 
 public:
+  using mutex_type = T;
+
   shared_lock(T& m)
     : _mutex(m)
   {
@@ -43,6 +70,7 @@ public:
   shared_lock(shared_lock const&) = delete;
   shared_lock& operator=(shared_lock const&) = delete;
 };
+#endif
 }
 
 #endif
diff --git a/Source/cm_string_view.hxx b/Utilities/std/cm/string_view
similarity index 98%
rename from Source/cm_string_view.hxx
rename to Utilities/std/cm/string_view
index 04de7971d9..4d359cb5c3 100644
--- a/Source/cm_string_view.hxx
+++ b/Utilities/std/cm/string_view
@@ -1,16 +1,17 @@
+// -*-c++-*-
+// vim: set ft=cpp:
+
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cm_string_view_hxx
-#define cm_string_view_hxx
-
-#include "cmConfigure.h" // IWYU pragma: keep
+#ifndef cm_string_view
+#define cm_string_view
 
 #if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
 #  define CMake_HAVE_CXX_STRING_VIEW
 #endif
 
 #ifdef CMake_HAVE_CXX_STRING_VIEW
-#  include <string_view>
+#  include <string_view> // IWYU pragma: export
 namespace cm {
 using std::string_view;
 }
diff --git a/Source/cm_utility.hxx b/Utilities/std/cm/utility
similarity index 75%
rename from Source/cm_utility.hxx
rename to Utilities/std/cm/utility
index 99d7f8bcd6..3acac4f69d 100644
--- a/Source/cm_utility.hxx
+++ b/Utilities/std/cm/utility
@@ -1,17 +1,16 @@
+// -*-c++-*-
+// vim: set ft=cpp:
+
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cm_utility_hxx
-#define cm_utility_hxx
-
-#include "cmConfigure.h" // IWYU pragma: keep
+#ifndef cm_utility
+#define cm_utility
 
 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
 #  define CMake_HAVE_CXX_IN_PLACE
 #endif
 
-#if defined(CMake_HAVE_CXX_IN_PLACE)
-#  include <utility>
-#endif
+#include <utility> // IWYU pragma: export
 
 namespace cm {
 
diff --git a/bootstrap b/bootstrap
index 9504250cb1..123e256e37 100755
--- a/bootstrap
+++ b/bootstrap
@@ -453,7 +453,6 @@ CMAKE_CXX_SOURCES="\
   cmake  \
   cmakemain \
   cmcmd  \
-  cm_string_view \
 "
 
 if ${cmake_system_mingw}; then
@@ -464,6 +463,17 @@ if ${cmake_system_mingw}; then
   "
 fi
 
+CMAKE_STD_CXX_HEADERS="\
+  memory \
+  optional \
+  shared_mutex \
+  string_view \
+  utility \
+"
+CMAKE_STD_CXX_SOURCES="\
+  string_view \
+"
+
 LexerParser_CXX_SOURCES="\
   cmCommandArgumentLexer \
   cmCommandArgumentParser \
@@ -1346,6 +1356,8 @@ cmake_compiler_settings_comment="/*
  *
  * Sources:
  * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
+ * STD Sources:
+ * ${CMAKE_STD_CXX_HEADERS} ${CMAKE_STD_CXX_SOURCES}
  * LexerParser Sources:
  * ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES}
  * kwSys Sources:
@@ -1412,9 +1424,12 @@ done
 cmake_generate_file "${cmake_bootstrap_dir}/cmThirdParty.h" ""
 
 # Generate Makefile
-dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
+dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.hxx `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
+for h in ${CMAKE_STD_CXX_HEADERS}; do
+  dep="${dep} `cmake_escape \"${cmake_source_dir}\"`/Utilities/std/cm/${h}"
+done
 objs=""
-for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
+for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${CMAKE_STD_CXX_SOURCES} ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
   objs="${objs} ${a}.o"
 done
 for a in ${LIBUV_C_SOURCES}; do
@@ -1498,6 +1513,7 @@ cmake_cxx_flags="${cmake_cxx_flags} \
   -I`cmake_escape \"${cmake_bootstrap_dir}\"` \
   -I`cmake_escape \"${cmake_source_dir}/Source\"` \
   -I`cmake_escape \"${cmake_source_dir}/Source/LexerParser\"` \
+  -I`cmake_escape \"${cmake_source_dir}/Utilities/std\"` \
   -I`cmake_escape \"${cmake_source_dir}/Utilities\"`"
 echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
 echo "	${cmake_cxx_compiler} ${cmake_ld_flags} ${cmake_cxx_flags} ${objs} ${libs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
@@ -1512,6 +1528,12 @@ for a in ${CMAKE_C_SOURCES}; do
   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
   echo "	${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
 done
+for a in ${CMAKE_STD_CXX_SOURCES}; do
+  src=`cmake_escape "${cmake_source_dir}/Utilities/std/cm/bits/${a}.cxx"`
+  src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
+  echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
+  echo "	${cmake_cxx_compiler} ${cmake_cxx_flags} ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
+done
 for a in ${LexerParser_CXX_SOURCES}; do
   src=`cmake_escape "${cmake_source_dir}/Source/LexerParser/${a}.cxx"`
   src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
-- 
GitLab