PROTON-1621/PROTON-1611: [C++ examples] Enable building C++11 examples in some environments
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/ae15cbdd Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/ae15cbdd Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/ae15cbdd Branch: refs/heads/go1 Commit: ae15cbddfcd33f60de289a3fd87f3489be38db55 Parents: e0feb3f Author: Andrew Stitcher <astitc...@apache.org> Authored: Mon Oct 16 16:11:58 2017 -0400 Committer: Andrew Stitcher <astitc...@apache.org> Committed: Tue Oct 17 10:24:38 2017 -0400 ---------------------------------------------------------------------- CMakeLists.txt | 8 +++++--- examples/cpp/CMakeLists.txt | 16 ++++++++++++++-- proton-c/bindings/cpp/CMakeLists.txt | 7 +++---- 3 files changed, 22 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ae15cbdd/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index b87f232..ab0bc79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,6 @@ cmake_minimum_required (VERSION 2.8.7) project (Proton C) -# Enable C++ now for examples and bindings subdirectories, but make it optional. -enable_language(CXX OPTIONAL) - # Enable testing enable_testing() include (CTest) @@ -30,11 +27,16 @@ include (CTest) # Pull in local cmake modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/Modules/") +# TODO - Should change this test to take account of recent MSVC that does support C99 if (MSVC) # No C99 capability, use C++ set(DEFAULT_BUILD_WITH_CXX ON) endif (MSVC) + option(BUILD_WITH_CXX "Compile Proton using C++" ${DEFAULT_BUILD_WITH_CXX}) +if (BUILD_WITH_CXX) + enable_language(CXX) +endif() if (CMAKE_CONFIGURATION_TYPES) # There is no single "build type"... http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ae15cbdd/examples/cpp/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 4114c94..e83732f 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -16,6 +16,7 @@ # specific language governing permissions and limitations # under the License. # +enable_language(CXX) find_package(ProtonCpp REQUIRED) @@ -23,6 +24,19 @@ include_directories(${ProtonCpp_INCLUDE_DIRS}) link_libraries(${ProtonCpp_LIBRARIES}) add_definitions(${CXX_EXAMPLE_FLAGS}) +set (BUILD_CPP_03 OFF CACHE BOOL "Compile as C++03 even when C++11 is available") +# This effectively checks for cmake version 3.1 or later +if (DEFINED CMAKE_CXX_COMPILE_FEATURES) + if (BUILD_CPP_03 OR MSVC) + set(STD 98) + else () + set(STD 11) + set(HAS_CPP11 ON) + endif () + set(CMAKE_CXX_STANDARD ${STD}) + set(CMAKE_CXX_EXTENSIONS OFF) +endif() + # Add a test with the correct environment to find test executables and valgrind. macro(add_cpp_test name) if(WIN32) @@ -57,7 +71,6 @@ foreach(example ssl_client_cert encode_decode) add_executable(${example} ${example}.cpp) - set_target_properties(${example} PROPERTIES LINK_FLAGS "${CXX_EXAMPLE_FLAGS}") endforeach() if(HAS_CPP11) @@ -69,7 +82,6 @@ if(HAS_CPP11) multithreaded_client_flow_control ) add_executable(${example} ${example}.cpp) - set_target_properties(${example} PROPERTIES LINK_FLAGS "${CXX_EXAMPLE_FLAGS}") endforeach() endif() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ae15cbdd/proton-c/bindings/cpp/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt index bd5437e..9d19385 100644 --- a/proton-c/bindings/cpp/CMakeLists.txt +++ b/proton-c/bindings/cpp/CMakeLists.txt @@ -16,6 +16,7 @@ # specific language governing permissions and limitations # under the License. # +enable_language(CXX) set (BUILD_CPP_03 OFF CACHE BOOL "Compile the C++ binding as C++03 even when C++11 is available") @@ -60,16 +61,14 @@ else () endif () # Make these CACHE INTERNAL so they will be set for the C++ examples -set(CXX_EXAMPLE_FLAGS "${CXX_WARNING_FLAGS} ${CMAKE_CXX_FLAGS} ${CXX_STANDARD}" CACHE INTERNAL "") -set(CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD} CACHE INTERNAL "") -set(CMAKE_CXX_EXTENSIONS ${CMAKE_CXX_EXTENSIONS} CACHE INTERNAL "") +set(CXX_EXAMPLE_FLAGS "${CXX_WARNING_FLAGS} ${CMAKE_CXX_FLAGS} ${CXX_STANDARD}" CACHE INTERNAL "") include_directories( "${CMAKE_SOURCE_DIR}/proton-c/include" "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/src/include") -add_definitions(${CXX_STANDARD} ${CXX_WARNING_FLAGS} -DPN_CPP_USE_DEPRECATED_API=1) +add_definitions(${CXX_STANDARD} ${CXX_WARNING_FLAGS} "-DPN_CPP_USE_DEPRECATED_API=1") set(qpid-proton-cpp-source src/binary.cpp --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org