qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject [3/5] qpid-proton git commit: PROTON-1654: [C++ binding] Improve turning C++ features on/off - Specifically for gcc 4.4 and Visual Studio compilers where this is a problem
Date Mon, 04 Dec 2017 19:00:23 GMT
PROTON-1654: [C++ binding] Improve turning C++ features on/off
- Specifically for gcc 4.4 and Visual Studio compilers where this is a problem


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f88c826c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f88c826c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f88c826c

Branch: refs/heads/master
Commit: f88c826c62f7aa624e1388131f4042e88f6a32ff
Parents: 5199e8c
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Thu Nov 30 15:42:20 2017 -0500
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Mon Dec 4 13:49:36 2017 -0500

----------------------------------------------------------------------
 examples/ProtonCppConfig.cmake                  |  3 +-
 examples/cpp/CMakeLists.txt                     |  4 +--
 examples/cpp/example_test.py                    |  8 ++---
 proton-c/bindings/cpp/CMakeLists.txt            | 36 ++++++++++++++------
 proton-c/bindings/cpp/config_presets.hpp.in     | 26 ++++++++++++++
 proton-c/bindings/cpp/cpp.cmake                 | 20 ++++++++---
 .../bindings/cpp/include/proton/container.hpp   |  5 ---
 .../cpp/include/proton/internal/config.hpp      |  9 +++++
 tools/py/proctest.py                            | 20 -----------
 9 files changed, 84 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/examples/ProtonCppConfig.cmake
----------------------------------------------------------------------
diff --git a/examples/ProtonCppConfig.cmake b/examples/ProtonCppConfig.cmake
index 9709163..6ebdc69 100644
--- a/examples/ProtonCppConfig.cmake
+++ b/examples/ProtonCppConfig.cmake
@@ -28,7 +28,8 @@
 # tree build and installed in the appropriate place for cmake on that system.
 
 set (ProtonCpp_VERSION       ${PN_VERSION})
-set (ProtonCpp_INCLUDE_DIRS  ${CMAKE_SOURCE_DIR}/proton-c/include ${CMAKE_SOURCE_DIR}/proton-c/bindings/cpp/include)
+set (ProtonCpp_INCLUDE_DIRS  ${CMAKE_SOURCE_DIR}/proton-c/include ${CMAKE_SOURCE_DIR}/proton-c/bindings/cpp/include
+    ${CMAKE_BINARY_DIR}/proton-c/bindings/cpp)
 set (ProtonCpp_LIBRARIES     ${C_EXAMPLE_LINK_FLAGS} qpid-proton-cpp)
 set (ProtonCpp_DEFINITIONS   ${CXX_EXAMPLE_FLAGS})
 set (ProtonCpp_FOUND True)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/examples/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
index 0531aec..8768f71 100644
--- a/examples/cpp/CMakeLists.txt
+++ b/examples/cpp/CMakeLists.txt
@@ -31,7 +31,7 @@ add_definitions(${ProtonCpp_DEFINITIONS})
 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)
+  if (BUILD_CPP_03)
     set(STD 98)
   else ()
     set(STD 11)
@@ -93,7 +93,7 @@ macro(add_cpp_test name)
     set(test_path "$<TARGET_FILE_DIR:broker>:$ENV{PATH}")
   endif(WIN32)
   set(run_env ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/proton-c/env.py ${EXAMPLE_ENV})
-  add_test(NAME ${name} COMMAND ${run_env} "PATH=${test_path}" ${VALGRIND_ENV} -- ${ARGN})
+  add_test(NAME ${name} COMMAND ${run_env} "PATH=${test_path}" ${VALGRIND_ENV} "HAS_CPP11=${HAS_CPP11}"
-- ${ARGN})
 endmacro()
 
 add_cpp_test(cpp-example-container ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example_test.py
-v ContainerExampleTest)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/examples/cpp/example_test.py
----------------------------------------------------------------------
diff --git a/examples/cpp/example_test.py b/examples/cpp/example_test.py
index bc4c6e6..5d8d45f 100644
--- a/examples/cpp/example_test.py
+++ b/examples/cpp/example_test.py
@@ -35,7 +35,7 @@ createdSASLDb = False
 def _cyrusSetup(conf_dir):
   """Write out simple SASL config.tests
   """
-  saslpasswd = os.getenv('SASLPASSWD') or find_file('saslpasswd2', os.getenv('PATH'))
+  saslpasswd = os.getenv('SASLPASSWD')
   if saslpasswd:
     t = Template("""sasldb_path: ${db}
 mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
@@ -197,7 +197,7 @@ map{string(k1):int(42), symbol(k2):boolean(0)}
         self.assertTrue(len(out) > 0);
         self.assertEqual(["send"]*len(out), out)
 
-    @unittest.skipUnless(find_exes('scheduled_send'), "not a  C++11 build")
+    @unittest.skipUnless(os.getenv('HAS_CPP11'), "not a  C++11 build")
     def test_scheduled_send(self):
         out = self.proc(["scheduled_send", "-a", self.addr+"scheduled_send", "-t", "0.1",
"-i", "0.001"]).wait_exit().split()
         self.assertTrue(len(out) > 0);
@@ -215,13 +215,13 @@ expected conversion_error: "unexpected type, want: uint got: string"
 """
         self.assertMultiLineEqual(expect, self.proc(["message_properties"]).wait_exit())
 
-    @unittest.skipUnless(find_exes('multithreaded_client'), "not a  C++11 build")
+    @unittest.skipUnless(os.getenv('HAS_CPP11'), "not a  C++11 build")
     def test_multithreaded_client(self):
         got = self.proc(["multithreaded_client", self.addr, "examples", "10"], helgrind=True).wait_exit()
         self.maxDiff = None
         self.assertRegexpMatches(got, "10 messages sent and received");
 
-    @unittest.skipUnless(find_exes('multithreaded_client_flow_control'), "not a  C++11 build")
+    @unittest.skipUnless(os.getenv('HAS_CPP11'), "not a  C++11 build")
     def test_multithreaded_client_flow_control(self):
         got = self.proc(["multithreaded_client_flow_control", self.addr, "examples", "10",
"2"], helgrind=True).wait_exit()
         self.maxDiff = None

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index 109b543..5858099 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -31,17 +31,10 @@ if (DEFINED CMAKE_CXX_COMPILE_FEATURES)
   endif ()
   set(CMAKE_CXX_STANDARD ${STD})
   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)
+  else()
+    set (CPP_DEFINITIONS "HAS_CPP11")
   endif()
 else ()
   if (BUILD_CPP_03)
@@ -53,6 +46,7 @@ else ()
     check_cxx_compiler_flag("-std=c++0x" ACCEPTS_CXX0X)
     if (ACCEPTS_CXX11)
       set(CXX_STANDARD "-std=c++11")
+      set (CPP_DEFINITIONS "HAS_CPP11")
     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
@@ -62,13 +56,34 @@ else ()
   endif()
 endif ()
 
+# Construct #define lines to insert in config_presets.hpp
+foreach(d ${CPP_DEFINITIONS})
+  set(presets "${presets}#define PN_CPP_LIB_${d} 1\n")
+endforeach()
+# For Visual Studio define the app compile time macros now, for everything else don't
+if(MSVC)
+  set(presets "${presets}\n// Compiled for MSVC version ${CMAKE_CXX_COMPILER_VERSION} (${MSVC_VERSION})\n")
+  foreach(d ${CPP_DEFINITIONS})
+    set(presets "${presets}# define PN_CPP_${d} 1\n")
+  endforeach()
+else()
+  set(presets "${presets}\n#if qpid_proton_cpp_EXPORTS\n")
+  foreach(d ${CPP_DEFINITIONS})
+    set(presets "${presets}# define PN_CPP_${d} 1\n")
+  endforeach()
+  set(presets "${presets}#endif // qpid_proton_cpp_EXPORTS\n")
+endif()
+
+configure_file(config_presets.hpp.in config_presets.hpp @ONLY)
+
 # 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(CXX_EXAMPLE_LINK_FLAGS "${SANITIZE_FLAGS}" CACHE INTERNAL "")
 
 include_directories(
   "${CMAKE_SOURCE_DIR}/proton-c/include"
-  "${CMAKE_CURRENT_SOURCE_DIR}/include")
+  "${CMAKE_CURRENT_SOURCE_DIR}/include"
+  "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_definitions(${CXX_STANDARD} ${CXX_WARNING_FLAGS} "-DPN_CPP_USE_DEPRECATED_API=1")
 
@@ -162,6 +177,7 @@ if (MSVC)
 endif (MSVC)
 
 install (DIRECTORY "include/proton" DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN
"*.hpp")
+install (FILES "${CMAKE_CURRENT_BINARY_DIR}/config_presets.hpp" DESTINATION "${INCLUDE_INSTALL_DIR}/proton/internal")
 
 add_subdirectory(docs)
 add_subdirectory(${CMAKE_SOURCE_DIR}/tests/tools/apps/cpp ${CMAKE_BINARY_DIR}/tests/tools/apps/cpp)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/proton-c/bindings/cpp/config_presets.hpp.in
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/config_presets.hpp.in b/proton-c/bindings/cpp/config_presets.hpp.in
new file mode 100644
index 0000000..676681b
--- /dev/null
+++ b/proton-c/bindings/cpp/config_presets.hpp.in
@@ -0,0 +1,26 @@
+#ifndef PROTON_INTERNAL_CONFIG_PRESETS_HPP
+#define PROTON_INTERNAL_CONFIG_PRESETS_HPP
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+@presets@
+ #endif // PROTON_INTERNAL_CONFIG_PRESETS_HPP
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/proton-c/bindings/cpp/cpp.cmake
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/cpp.cmake b/proton-c/bindings/cpp/cpp.cmake
index 051781c..0791044 100644
--- a/proton-c/bindings/cpp/cpp.cmake
+++ b/proton-c/bindings/cpp/cpp.cmake
@@ -24,14 +24,18 @@ include(CheckCXXSourceCompiles)
 macro (cxx_test prog name)
   check_cxx_source_compiles("${prog}" HAS_${name})
   if (HAS_${name})
-    add_definitions(-DPN_CPP_HAS_${name}=1)
+    list(APPEND CPP_DEFINITIONS "HAS_${name}")
+  else()
+    set(CPP_TEST_FAILED True)
   endif()
 endmacro()
 
-check_cxx_source_compiles("#if defined(__cplusplus) && __cplusplus >= 201103\nint
main(int, char**) { return 0; }\n#endif" CPP11)
+set(CPP_DEFINITIONS "")
+set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} ${CXX_WARNING_FLAGS}")
+cxx_test("#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}")
+if (NOT HAS_CPP11)
+  set(CPP_TEST_FAILED False)
   cxx_test("long long ll; int main(int, char**) { return 0; }" LONG_LONG_TYPE)
   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)
@@ -48,5 +52,11 @@ if (NOT CPP11)
   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)
-  unset(CMAKE_REQUIRED_FLAGS) # Don't contaminate later C tests with C++ flags
+
+  # If all the tests passed this is the same as if we have C++11 for the purposes of compilation
+  # (this shortens the compile command line for VS 2017 significantly)
+  if (NOT CPP_TEST_FAILED)
+    set(CPP_DEFINITIONS "HAS_CPP11")
+  endif()
 endif()
+unset(CMAKE_REQUIRED_FLAGS) # Don't contaminate later C tests with C++ flags

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/proton-c/bindings/cpp/include/proton/container.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp
index 7f4ed21..e80acbe 100644
--- a/proton-c/bindings/cpp/include/proton/container.hpp
+++ b/proton-c/bindings/cpp/include/proton/container.hpp
@@ -35,11 +35,6 @@
 /// @file
 /// @copybrief proton::container
 
-/// @cond INTERNAL
-/// True if the library can support multithreaded containers.
-#define PN_CPP_SUPPORTS_THREADS PN_CPP_HAS_STD_THREAD && PN_CPP_HAS_STD_MUTEX
-/// @endcond
-
 namespace proton {
 
 /// A top-level container of connections, sessions, and links.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/proton-c/bindings/cpp/include/proton/internal/config.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/internal/config.hpp b/proton-c/bindings/cpp/include/proton/internal/config.hpp
index 42de663..321aebf 100644
--- a/proton-c/bindings/cpp/include/proton/internal/config.hpp
+++ b/proton-c/bindings/cpp/include/proton/internal/config.hpp
@@ -33,6 +33,15 @@
 /// default.  Otherwise they can be enabled or disabled separately
 /// with -D on the compile line.
 
+// Read library compilation presets -
+// This sets the options the library itself was compiled with
+// and sets up the compilation options is we are compiling the library itself
+#include "config_presets.hpp"
+
+/// Whether the library supports threads depends on the configuration of the library compilation
only
+#define PN_CPP_SUPPORTS_THREADS PN_CPP_LIB_HAS_CPP11 || (PN_CPP_LIB_HAS_STD_THREAD &&
PN_CPP_LIB_HAS_STD_MUTEX)
+/// @endcond
+
 /// The Apple clang compiler doesn't really support PN_CPP_HAS_THREAD_LOCAL
 /// before Xcode 8 even though it claims to be C++11 compatible
 #if defined(__clang__) && defined(__apple_build_version__) && ((__clang_major__
* 100) + __clang_minor__) >= 301

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f88c826c/tools/py/proctest.py
----------------------------------------------------------------------
diff --git a/tools/py/proctest.py b/tools/py/proctest.py
index 802376e..35eb216 100644
--- a/tools/py/proctest.py
+++ b/tools/py/proctest.py
@@ -213,26 +213,6 @@ class ProcTestCase(unittest.TestCase):
 
 from functools import reduce
 
-def find_file(filename, path):
-    """
-    Find filename in path. Path is a list of directory names or OS path strings
-    separated with os.pathsep. return absolute path to the file or None
-
-    """
-    dirs = reduce((lambda x,y: x+y), (p.split(os.pathsep) for p in path))
-    for d in dirs:
-        if os.path.exists(os.path.join(d, filename)):
-            return os.path.abspath(os.path.join(d, filename))
-    return None
-
-def find_exes(*filenames):
-    """
-    True if all filenames in the list are found on the system PATH.
-    """
-    for f in filenames:
-        if not find_file(f, os.getenv('PATH')): return False
-    return True
-
 #### Skip decorators missing in python 2.6
 
 def _id(obj):


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message