From 4614a3b287456fad12bcb91ad2936214da3237bf Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Thu, 17 Aug 2017 00:41:18 +0200 Subject: [PATCH] server: backport to C++11 --- CMakeLists.txt | 5 +---- Source/cmAlgorithms.h | 19 +++++++++++++++++++ Source/cmServer.cxx | 3 ++- Source/cmServerProtocol.cxx | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67c4cdc2f8..7b0a1d10ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -723,10 +723,7 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) if(NOT DEFINED CMake_ENABLE_SERVER_MODE) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_auto_type CMake_HAVE_CXX_AUTO_TYPE) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_range_for CMake_HAVE_CXX_RANGE_FOR) - if(CMake_HAVE_CXX_AUTO_TYPE - AND CMake_HAVE_CXX_MAKE_UNIQUE - AND CMake_HAVE_CXX_RANGE_FOR - ) + if(CMake_HAVE_CXX_AUTO_TYPE AND CMake_HAVE_CXX_RANGE_FOR) set(CMake_ENABLE_SERVER_MODE 1) else() set(CMake_ENABLE_SERVER_MODE 0) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 4adfe23284..a4f66a975e 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -402,4 +403,22 @@ inline void cmStripSuffixIfExists(std::string& str, const std::string& suffix) } } +namespace cm { + +#if defined(CMake_HAVE_CXX_MAKE_UNIQUE) + +using std::make_unique; + +#else + +template +std::unique_ptr make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + +#endif + +} // namespace cm + #endif diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 04810c64ec..d3aeb0bd14 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServer.h" +#include "cmAlgorithms.h" #include "cmConnection.h" #include "cmFileMonitor.h" #include "cmServerDictionary.h" @@ -78,7 +79,7 @@ void cmServer::ProcessRequest(cmConnection* connection, std::unique_ptr debug; Json::Value debugValue = value["debug"]; if (!debugValue.isNull()) { - debug = std::make_unique(); + debug = cm::make_unique(); debug->OutputFile = debugValue["dumpToFile"].asString(); debug->PrintStatistics = debugValue["showStats"].asBool(); } diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index cb5e6ae8e5..0b50debea7 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -220,7 +220,7 @@ bool cmServerProtocol::Activate(cmServer* server, { assert(server); this->m_Server = server; - this->m_CMakeInstance = std::make_unique(cmake::RoleProject); + this->m_CMakeInstance = cm::make_unique(cmake::RoleProject); const bool result = this->DoActivate(request, errorMessage); if (!result) { this->m_CMakeInstance = nullptr;