PROTON-1879: Make CMake files more idiomatic by modern standards
- Use imported targets
- Create wrappers for FindOpenSSL/FindThreads so that we can use imported
  targets on cmake 2.8.12 on RHEL6/RHEL7 where the cmake supplied modules
  don't provide imported targets.


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

Branch: refs/heads/master
Commit: 69647801d4615403be64cf3162f1de5ec947306a
Parents: 5564638
Author: Andrew Stitcher <astitc...@apache.org>
Authored: Wed Jun 27 19:41:23 2018 -0400
Committer: Andrew Stitcher <astitc...@apache.org>
Committed: Thu Jun 28 21:51:46 2018 -0400

----------------------------------------------------------------------
 c/CMakeLists.txt                      | 15 +++++------
 cpp/CMakeLists.txt                    |  6 ++---
 tools/cmake/Modules/FindOpenSSL.cmake | 35 +++++++++++++++++++++++++
 tools/cmake/Modules/FindThreads.cmake | 42 ++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69647801/c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt
index ffd45b9..dc869a3 100644
--- a/c/CMakeLists.txt
+++ b/c/CMakeLists.txt
@@ -99,8 +99,7 @@ endif(PN_WINAPI)
 # Link in SASL if present
 if (SASL_IMPL STREQUAL cyrus)
   set(pn_sasl_impl src/sasl/sasl.c src/sasl/default_sasl.c 
src/sasl/cyrus_sasl.c)
-  include_directories (${CyrusSASL_INCLUDE_DIRS})
-  set(SASL_LIB ${CyrusSASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+  set(SASL_LIB CyrusSASL::CyrusSASL Threads::Threads)
 elseif (SASL_IMPL STREQUAL none)
   set(pn_sasl_impl src/sasl/sasl.c src/sasl/default_sasl.c 
src/sasl/cyrus_stub.c)
 endif ()
@@ -117,8 +116,7 @@ endif()
 # Link in openssl if present
 if (SSL_IMPL STREQUAL openssl)
   set (pn_ssl_impl src/ssl/openssl.c)
-  include_directories (${OPENSSL_INCLUDE_DIR})
-  set (SSL_LIB ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+  set (SSL_LIB OpenSSL::SSL Threads::Threads)
 elseif (SSL_IMPL STREQUAL schannel)
   set (pn_ssl_impl src/ssl/schannel.c)
   set (SSL_LIB Crypt32.lib Secur32.lib)
@@ -472,7 +470,7 @@ if (PROACTOR STREQUAL "epoll" OR (NOT PROACTOR AND NOT 
BUILD_PROACTOR))
   if (HAVE_EPOLL)
     set (PROACTOR_OK epoll)
     set (qpid-proton-proactor src/proactor/epoll.c 
src/proactor/proactor-internal.c)
-    set (PROACTOR_LIBS -lpthread)
+    set (PROACTOR_LIBS Threads::Threads)
     set_source_files_properties (${qpid-proton-proactor} PROPERTIES
       COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_LANGUAGE_FLAGS} ${LTO}"
       )
@@ -495,11 +493,10 @@ if (PROACTOR STREQUAL "libuv" OR (NOT PROACTOR AND NOT 
PROACTOR_OK))
   if (Libuv_FOUND)
     set (PROACTOR_OK libuv)
     set (qpid-proton-proactor src/proactor/libuv.c 
src/proactor/proactor-internal.c)
-    set (PROACTOR_LIBS ${Libuv_LIBRARIES})
+    set (PROACTOR_LIBS Libuv::Libuv)
     set_source_files_properties (${qpid-proton-proactor} PROPERTIES
       COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_LANGUAGE_FLAGS} ${LTO}"
       )
-    include_directories(${Libuv_INCLUDE_DIRS})
   endif()
 endif()
 
@@ -548,7 +545,7 @@ set(qpid-proton-core-src
   )
 add_library (qpid-proton-core SHARED ${qpid-proton-core-src})
 add_dependencies(qpid-proton-core generated_c_files)
-target_link_libraries (qpid-proton-core ${UUID_LIB} ${SSL_LIB} ${SASL_LIB} 
${TIME_LIB} ${PLATFORM_LIBS})
+target_link_libraries (qpid-proton-core ${SSL_LIB} ${SASL_LIB} ${TIME_LIB} 
${PLATFORM_LIBS})
 if (BUILD_STATIC_LIBS)
   add_library (qpid-proton-core-static STATIC ${qpid-proton-core-src})
 endif(BUILD_STATIC_LIBS)
@@ -588,7 +585,7 @@ if (MSVC)
   add_dependencies(qpid-proton qpid-proton-core)
 endif (MSVC)
 
-target_link_libraries (qpid-proton LINK_PRIVATE ${UUID_LIB} ${SSL_LIB} 
${SASL_LIB} ${TIME_LIB} ${PLATFORM_LIBS} ${PROACTOR_LIBS})
+target_link_libraries (qpid-proton LINK_PRIVATE ${SSL_LIB} ${SASL_LIB} 
${TIME_LIB} ${PLATFORM_LIBS} ${PROACTOR_LIBS})
 
 set_target_properties (
   qpid-proton

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69647801/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 07faf95..f341241 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -33,7 +33,7 @@ if (DEFINED CMAKE_CXX_COMPILE_FEATURES)
     set(STD 98)
   else ()
     set(STD 11)
-    list(APPEND PLATFORM_LIBS "${CMAKE_THREAD_LIBS_INIT}")
+    list(APPEND PLATFORM_LIBS Threads::Threads)
   endif ()
   set(CMAKE_CXX_STANDARD ${STD})
   set(CMAKE_CXX_EXTENSIONS OFF)
@@ -53,10 +53,10 @@ else ()
     if (ACCEPTS_CXX11)
       set(CXX_STANDARD "-std=c++11")
       set(CPP_DEFINITIONS "HAS_CPP11")
-      list(APPEND PLATFORM_LIBS "${CMAKE_THREAD_LIBS_INIT}")
+      list(APPEND PLATFORM_LIBS Threads::Threads)
     elseif(ACCEPTS_CXX0X)
       set(CXX_STANDARD "-std=c++0x")
-      list(APPEND PLATFORM_LIBS "${CMAKE_THREAD_LIBS_INIT}")
+      list(APPEND PLATFORM_LIBS Threads::Threads)
       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!

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69647801/tools/cmake/Modules/FindOpenSSL.cmake
----------------------------------------------------------------------
diff --git a/tools/cmake/Modules/FindOpenSSL.cmake 
b/tools/cmake/Modules/FindOpenSSL.cmake
new file mode 100644
index 0000000..06d5ce4
--- /dev/null
+++ b/tools/cmake/Modules/FindOpenSSL.cmake
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+# This is a wrapper hack purely so that we can use imported targets
+# with cmake 2.8.12 and its supplied older modules
+
+include(${CMAKE_ROOT}/Modules/FindOpenSSL.cmake)
+
+if (OPENSSL_FOUND AND NOT TARGET OpenSSL::SSL)
+  add_library(OpenSSL::SSL UNKNOWN IMPORTED)
+  set_target_properties(OpenSSL::SSL
+    PROPERTIES
+      IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}"
+      INTERFACE_LINK_LIBRARIES "${OPENSSL_CRYPTO_LIBRARY}"
+      INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}"
+  )
+endif ()
+
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69647801/tools/cmake/Modules/FindThreads.cmake
----------------------------------------------------------------------
diff --git a/tools/cmake/Modules/FindThreads.cmake 
b/tools/cmake/Modules/FindThreads.cmake
new file mode 100644
index 0000000..d399fa0
--- /dev/null
+++ b/tools/cmake/Modules/FindThreads.cmake
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+
+# This is a wrapper hack purely so that we can use imported targets
+# with cmake 2.8.12 and its supplied older modules
+
+include(${CMAKE_ROOT}/Modules/FindThreads.cmake)
+
+if(Threads_FOUND AND NOT TARGET Threads::Threads)
+  add_library(Threads::Threads UNKNOWN IMPORTED)
+
+  if(THREADS_HAVE_PTHREAD_ARG)
+    set_target_properties(Threads::Threads
+      PROPERTIES
+        INTERFACE_COMPILE_OPTIONS "-pthread"
+    )
+  endif()
+
+  if(CMAKE_THREAD_LIBS_INIT)
+    set_target_properties(Threads::Threads
+      PROPERTIES
+        IMPORTED_LOCATION "${CMAKE_THREAD_LIBS_INIT}"
+    )
+  endif()
+endif()
+


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

Reply via email to