You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2017/09/25 20:50:38 UTC
qpid-proton git commit: PROTON-1527: Compile with C++ 11 if available.
Repository: qpid-proton
Updated Branches:
refs/heads/master 3dae6623e -> a181656d2
PROTON-1527: Compile with C++ 11 if available.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a181656d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a181656d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a181656d
Branch: refs/heads/master
Commit: a181656d25dfef550be4c3be78717709bb3fd11e
Parents: 3dae662
Author: Andrew Stitcher <as...@apache.org>
Authored: Tue Aug 1 14:50:08 2017 -0400
Committer: Andrew Stitcher <as...@apache.org>
Committed: Mon Sep 25 16:40:54 2017 -0400
----------------------------------------------------------------------
proton-c/bindings/cpp/CMakeLists.txt | 34 +++++++++++++++++++++++++++--
proton-c/bindings/cpp/cpp.cmake | 36 ++++++++++++++++++++++---------
2 files changed, 58 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a181656d/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index e0bcac9..9409d30 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -17,14 +17,44 @@
# under the License.
#
-include(cpp.cmake) # Compiler checks
+# This effectively checks for cmake version 3.1 or later
+if (DEFINED CMAKE_CXX_COMPILE_FEATURES)
+ set(CMAKE_CXX_STANDARD 11)
+ set(CMAKE_CXX_EXTENSIONS OFF)
+# AStitcher 20170804: Disabled for present - work on this when Windows C++ works
+# cmake_minimum_required(VERSION 3.1)
+# include(WriteCompilerDetectionHeader)
+# write_compiler_detection_header(
+# FILE cpp_features.h
+# PREFIX PN
+# COMPILERS GNU Clang MSVC SunPro
+# FEATURES ${CMAKE_CXX_COMPILE_FEATURES}
+# ALLOW_UNKNOWN_COMPILERS)
+ if (MSVC) # Compiler feature checks only needed for Visual Studio in this case
+ include(cpp.cmake)
+ endif()
+else ()
+ include(CheckCXXCompilerFlag)
+ # These flags work with GCC/Clang/SunPro compilers
+ check_cxx_compiler_flag("-std=c++11" ACCEPTS_CXX11)
+ check_cxx_compiler_flag("-std=c++0x" ACCEPTS_CXX0X)
+ if (ACCEPTS_CXX11)
+ set(CXX_STANDARD "-std=c++11")
+ elseif(ACCEPTS_CXX0X)
+ set(CXX_STANDARD "-std=c++0x")
+ include(cpp.cmake) # Compiler checks needed for C++0x as not all C++11 may be supported
+ else()
+ include(cpp.cmake) # Compiler checks needed as we have no idea whats going on here!
+ endif()
+endif ()
+
include_directories(
"${CMAKE_SOURCE_DIR}/proton-c/include"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/src/include")
-add_definitions(${CXX_WARNING_FLAGS})
+add_definitions(${CXX_STANDARD} ${CXX_WARNING_FLAGS})
set(qpid-proton-cpp-source
src/binary.cpp
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a181656d/proton-c/bindings/cpp/cpp.cmake
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/cpp.cmake b/proton-c/bindings/cpp/cpp.cmake
index 51980d7..99136fa 100644
--- a/proton-c/bindings/cpp/cpp.cmake
+++ b/proton-c/bindings/cpp/cpp.cmake
@@ -21,15 +21,31 @@
include(CheckCXXSourceCompiles)
-if (CMAKE_CXX_COMPILER)
- set(CMAKE_REQUIRED_FLAGS "${CXX_WARNING_FLAGS}")
- check_cxx_source_compiles("long long ll; int main(int, char**) { return 0; }" HAS_LONG_LONG)
- if (HAS_LONG_LONG)
- add_definitions(-DPN_CPP_HAS_LONG_LONG=1)
+macro (cxx_test prog name)
+ check_cxx_source_compiles("${prog}" HAS_${name})
+ if (HAS_${name})
+ add_definitions(-DPN_CPP_HAS_${name}=1)
endif()
- check_cxx_source_compiles("#include <memory>\nstd::shared_ptr<int> i; std::unique_ptr<int> u; int main(int, char**) { return 0; }" HAS_STD_PTR)
- if (HAS_STD_PTR)
- add_definitions(-DPN_CPP_HAS_STD_PTR=1)
- endif()
- check_cxx_source_compiles("#if defined(__cplusplus) && __cplusplus >= 201100\nint main(int, char**) { return 0; }\n#endif" HAS_CPP11)
+endmacro()
+
+check_cxx_source_compiles("#if defined(__cplusplus) && __cplusplus >= 201103\nint main(int, char**) { return 0; }\n#endif" CPP11)
+# Don't need to check individual flags if compiler claims to be C++11 or later as they will be set automatically
+if (NOT CPP11)
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} ${CXX_WARNING_FLAGS}")
+ cxx_test("long long ll; int main(int, char**) { return 0; }" LONG_LONG)
+ cxx_test("#include <memory>\nstd::shared_ptr<int> i; int main(int, char**) { return 0; }" SHARED_PTR)
+ cxx_test("#include <memory>\nstd::unique_ptr<int> u; int main(int, char**) { return 0; }" UNIQUE_PTR)
+ cxx_test("int* x = nullptr; int main(int, char**) { return 0; }" NULLPTR)
+ cxx_test("#include <string>\nvoid blah(std::string&&) {} int main(int, char**) { blah(\"hello\"); return 0; }" RVALUE_REFERENCES)
+ cxx_test("class x {explicit operator int(); }; int main(int, char**) { return 0; }" EXPLICIT_CONVERSIONS)
+ cxx_test("class x {x(x&&)=default; }; int main(int, char**) { return 0; }" DEFAULTED_FUNCTIONS)
+ cxx_test("class x {x()=delete; }; int main(int, char**) { return 0; }" DELETED_FUNCTIONS)
+ cxx_test("struct x {x() {}}; int main(int, char**) { static thread_local x foo; return 0; }" THREAD_LOCAL)
+ cxx_test("#include <functional>\nstd::function<int(void)> f = [](){return 42;}; int main(int, char**) { return 0; }" STD_FUNCTION)
+ cxx_test("#include <functional>\nvoid f(int) {} int main(int, char**) { std::bind(f, 42); return 0; }" STD_BIND)
+ cxx_test("#include <chrono>\nint main(int, char**) { return 0; }" CHRONO)
+ cxx_test("#include <random>\nint main(int, char**) { return 0; }" RANDOM)
+ cxx_test("#include <thread>\nstd::thread t; int main(int, char**) { return 0; }" STD_THREAD)
+ cxx_test("#include <mutex>\nstd::mutex m; int main(int, char**) { return 0; }" STD_MUTEX)
+ cxx_test("#include <atomic>\nstd::atomic<int> a; int main(int, char**) { return 0; }" STD_ATOMIC)
endif()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org