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 2020/07/22 00:07:31 UTC

[qpid-proton] branch master updated: PROTON-2208: Fix static library build - Also fix long standing fuzz test failure with static build - Also allow link time optimization for Clang and MSVC

This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/master by this push:
     new 911d579  PROTON-2208: Fix static library build - Also fix long standing fuzz test failure with static build - Also allow link time optimization for Clang and MSVC
911d579 is described below

commit 911d5794f5af515b954cb3c08d025e4011507277
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Tue Jul 21 14:37:33 2020 -0400

    PROTON-2208: Fix static library build
    - Also fix long standing fuzz test failure with static build
    - Also allow link time optimization for Clang and MSVC
---
 .travis.yml                         | 14 +++++++++++--
 CMakeLists.txt                      | 16 +++++++++++----
 azure-pipelines/azure-pipelines.yml |  1 +
 azure-pipelines/steps.yml           |  2 +-
 c/CMakeLists.txt                    | 40 ++++++++++++++++++++++++++-----------
 cpp/CMakeLists.txt                  | 12 +++++------
 6 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index fc3f74e..f75c493 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,7 +32,16 @@ jobs:
     env:
     - OPENSSL_ia32cap='0x00000000'
     # c-threaderciser test hangs on older clang
+    - QPID_PROTON_CMAKE_ARGS='-DENABLE_LINKTIME_OPTIMIZATION=OFF'
     - QPID_PROTON_CTEST_ARGS="--exclude-regex 'c-threaderciser'"
+  - name: static libs
+    os: linux
+    dist: focal
+    language: cpp
+    compiler: gcc
+    env:
+    - PYTHON=python3
+    - QPID_PROTON_CMAKE_ARGS='-DBUILD_STATIC_LIBS=ON'
   - name: benchmarks
     os: linux
     dist: focal
@@ -64,7 +73,7 @@ jobs:
     - CC=clang-10
     - CXX=clang++-10
     - PYTHON=python3
-    - QPID_PROTON_CMAKE_ARGS='-DRUNTIME_CHECK=asan -DENABLE_TOX_TEST=OFF'
+    - QPID_PROTON_CMAKE_ARGS='-DRUNTIME_CHECK=asan -DENABLE_LINKTIME_OPTIMIZATION=OFF -DENABLE_TOX_TEST=OFF'
     # otherwise, on Travis ldd gives `libclang_rt.asan-x86_64.so => not found` and binaries don't work
     - LD_LIBRARY_PATH=/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux/
   - name: gcc tsan
@@ -79,7 +88,8 @@ jobs:
     # python-test, python-integration-test, and python-tox-test segfault
     - QPID_PROTON_CMAKE_ARGS='-DRUNTIME_CHECK=tsan -DENABLE_TOX_TEST=OFF'
     - QPID_PROTON_CTEST_ARGS="-E 'python-test|python-integration-test'"
-  - os: linux
+  - name: coverage
+    os: linux
     dist: bionic
     language: cpp
     compiler: gcc
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a78b29..d75dfdb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -159,6 +159,18 @@ option(ENABLE_FUZZ_TESTING "Enable building fuzzers and regression testing with
 option(ENABLE_BENCHMARKS "Enable building and running benchmarks with Google Benchmark" ${DEFAULT_BENCHMARKS})
 
 # Set any additional compiler specific flags
+set (LTO_GNU "-flto -fno-fat-lto-objects")
+set (LTO_Clang "-flto=thin")
+set (LTO_MSVC "/GL")
+set (LINK_LTO_GNU "-flto -fno-fat-lto-objects")
+set (LINK_LTO_Clang "-flto=thin")
+set (LINK_LTO_MSVC "/LTCG")
+
+if (ENABLE_LINKTIME_OPTIMIZATION)
+  set (LTO ${LTO_${CMAKE_C_COMPILER_ID}})
+  set (LINK_LTO ${LINK_LTO_${CMAKE_C_COMPILER_ID}})
+endif (ENABLE_LINKTIME_OPTIMIZATION)
+
 if (CMAKE_COMPILER_IS_GNUCC)
   if (ENABLE_WARNING_ERROR)
     set (WERROR "-Werror")
@@ -172,10 +184,6 @@ if (CMAKE_COMPILER_IS_GNUCC)
     set (ALLOW_UNDEFINED "-Wl,--allow-shlib-undefined")
   endif (ENABLE_UNDEFINED_ERROR)
 
-  if (ENABLE_LINKTIME_OPTIMIZATION)
-    set (LTO "-flto")
-  endif (ENABLE_LINKTIME_OPTIMIZATION)
-
   if (ENABLE_HIDE_UNEXPORTED_SYMBOLS)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml
index 44e4a59..7db802c 100644
--- a/azure-pipelines/azure-pipelines.yml
+++ b/azure-pipelines/azure-pipelines.yml
@@ -11,6 +11,7 @@ variables:
   PythonVersion: '3.6'
   PythonArch: 'x64'
   CmakeConfigExtraArgs: ''
+  StaticLibs: yes
 
 jobs:
 - job: Windows_VS2019
diff --git a/azure-pipelines/steps.yml b/azure-pipelines/steps.yml
index ec481d6..7e4c201 100644
--- a/azure-pipelines/steps.yml
+++ b/azure-pipelines/steps.yml
@@ -13,7 +13,7 @@ steps:
   name: CMakeConfigure
   inputs:
     workingDirectory: 'BLD'
-    cmakeArgs: $(Build.SourcesDirectory) $(CmakeConfigExtraArgs)
+    cmakeArgs: $(Build.SourcesDirectory) -DBUILD_STATIC_LIBS=$(StaticLibs) $(CmakeConfigExtraArgs)
 - task: CMake@1
   name: CMakeBuild
   inputs:
diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt
index 7b7e242..17495a5 100644
--- a/c/CMakeLists.txt
+++ b/c/CMakeLists.txt
@@ -339,7 +339,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 ${qpid-proton-proactor-common})
-    set (PROACTOR_LIBS Threads::Threads)
+    set (PROACTOR_LIBS Threads::Threads ${TIME_LIB})
   endif()
 endif()
 
@@ -373,13 +373,13 @@ set_source_files_properties (
   ${qpid-proton-extra}
   ${qpid-proton-platform}
   PROPERTIES
-  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${C_STANDARD_FLAGS} ${LTO}"
+  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${C_STANDARD_FLAGS}"
   )
 
 set_source_files_properties (
   ${qpid-proton-platform-io}
   PROPERTIES
-  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${C_EXTENDED_FLAGS} ${LTO}"
+  COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${C_EXTENDED_FLAGS}"
   COMPILE_DEFINITIONS "${PLATFORM_DEFINITIONS}"
   )
 
@@ -393,12 +393,15 @@ set(qpid-proton-core-src
 
 add_library (qpid-proton-core-objects OBJECT ${qpid-proton-core-src})
 add_dependencies (qpid-proton-core-objects generated_c_files)
-set_target_properties(qpid-proton-core-objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
+set_target_properties(qpid-proton-core-objects PROPERTIES
+  POSITION_INDEPENDENT_CODE ON
+  COMPILE_FLAGS "${LTO}"
+  LINK_FLAGS "${LINK_LTO}")
 target_compile_definitions(qpid-proton-core-objects PRIVATE qpid_proton_core_EXPORTS)
 
 # Can't use target_link_libraries() because cmake 2.8.12 doesn't allow object libraries as the first param
 # otherwise for cmake 3.9 and on this would be:
-#   target_link_libraries (qpid-proton-core-objects ${SSL_LIB} ${SASL_LIB} ${TIME_LIB} ${PLATFORM_LIBS})
+#   target_link_libraries (qpid-proton-core-objects ${SSL_LIB} ${SASL_LIB} ${PLATFORM_LIBS})
 target_compile_definitions(qpid-proton-core-objects PRIVATE $<TARGET_PROPERTY:qpid-proton-core,COMPILE_DEFINITIONS>)
 target_compile_options    (qpid-proton-core-objects PRIVATE $<TARGET_PROPERTY:qpid-proton-core,COMPILE_OPTIONS>)
 target_include_directories(qpid-proton-core-objects PRIVATE $<TARGET_PROPERTY:qpid-proton-core,INCLUDE_DIRECTORIES>)
@@ -406,7 +409,9 @@ target_include_directories(qpid-proton-core-objects PRIVATE $<TARGET_PROPERTY:qp
 add_library (qpid-proton-platform-io-objects OBJECT ${qpid-proton-platform-io})
 set_target_properties(qpid-proton-platform-io-objects PROPERTIES
   POSITION_INDEPENDENT_CODE ON
-  C_EXTENSIONS ON)
+  C_EXTENSIONS ON
+  COMPILE_FLAGS "${LTO}"
+  LINK_FLAGS "${LINK_LTO}")
 target_compile_definitions(qpid-proton-platform-io-objects PRIVATE qpid_proton_EXPORTS)
 
 target_compile_definitions(qpid-proton-platform-io-objects PRIVATE $<TARGET_PROPERTY:qpid-proton,COMPILE_DEFINITIONS>)
@@ -414,16 +419,18 @@ target_compile_options    (qpid-proton-platform-io-objects PRIVATE $<TARGET_PROP
 target_include_directories(qpid-proton-platform-io-objects PRIVATE $<TARGET_PROPERTY:qpid-proton,INCLUDE_DIRECTORIES>)
 
 add_library (qpid-proton-core SHARED $<TARGET_OBJECTS:qpid-proton-core-objects>)
-target_link_libraries (qpid-proton-core ${SSL_LIB} ${SASL_LIB} ${TIME_LIB} ${PLATFORM_LIBS})
+target_link_libraries (qpid-proton-core LINK_PRIVATE ${SSL_LIB} ${SASL_LIB} ${PLATFORM_LIBS})
 set_target_properties (qpid-proton-core
   PROPERTIES
   VERSION   "${PN_LIB_CORE_VERSION}"
   SOVERSION "${PN_LIB_CORE_MAJOR_VERSION}"
-  LINK_FLAGS "${CATCH_UNDEFINED} ${LTO}"
+  LINK_FLAGS "${CATCH_UNDEFINED} ${LINK_LTO}"
 )
 
 if (BUILD_STATIC_LIBS)
   add_library (qpid-proton-core-static STATIC ${qpid-proton-core-src})
+  target_compile_definitions(qpid-proton-core-static PUBLIC PROTON_DECLARE_STATIC)
+  target_link_libraries (qpid-proton-core-static ${SSL_LIB} ${SASL_LIB} ${PLATFORM_LIBS})
 endif(BUILD_STATIC_LIBS)
 
 set(qpid-proton-noncore-src
@@ -440,17 +447,23 @@ set_target_properties (qpid-proton
   PROPERTIES
   VERSION   "${PN_LIB_LEGACY_VERSION}"
   SOVERSION "${PN_LIB_LEGACY_MAJOR_VERSION}"
-  LINK_FLAGS "${CATCH_UNDEFINED} ${LTO}"
+  LINK_FLAGS "${CATCH_UNDEFINED} ${LINK_LTO}"
+  COMPILE_FLAGS "${LTO}"
 )
 
 if (BUILD_STATIC_LIBS)
-  add_library(qpid-proton-static STATIC ${qpid-proton-core-src} ${qpid-proton-platform-io} ${qpid-proton-noncore-src})
+  add_library (qpid-proton-platform-io-static OBJECT ${qpid-proton-platform-io})
+  set_target_properties(qpid-proton-platform-io-static PROPERTIES
+    C_EXTENSIONS ON)
+  add_library(qpid-proton-static STATIC ${qpid-proton-core-src} $<TARGET_OBJECTS:qpid-proton-platform-io-static> ${qpid-proton-noncore-src})
+  target_compile_definitions(qpid-proton-static PUBLIC PROTON_DECLARE_STATIC)
+  target_link_libraries (qpid-proton-static ${SSL_LIB} ${SASL_LIB} ${TIME_LIB} ${PLATFORM_LIBS} ${PROACTOR_LIBS})
 endif(BUILD_STATIC_LIBS)
 
 if (qpid-proton-proactor)
   set(HAS_PROACTOR True)
   set_source_files_properties (${qpid-proton-proactor} PROPERTIES
-    COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${C_STANDARD_FLAGS} ${LTO}"
+    COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${C_STANDARD_FLAGS}"
     )
   add_library (qpid-proton-proactor SHARED ${qpid-proton-proactor})
   target_link_libraries (qpid-proton-proactor  LINK_PUBLIC qpid-proton-core)
@@ -459,10 +472,13 @@ if (qpid-proton-proactor)
     PROPERTIES
     VERSION   "${PN_LIB_PROACTOR_VERSION}"
     SOVERSION "${PN_LIB_PROACTOR_MAJOR_VERSION}"
-    LINK_FLAGS "${CATCH_UNDEFINED} ${LTO}"
+    LINK_FLAGS "${CATCH_UNDEFINED} ${LINK_LTO}"
+    COMPILE_FLAGS "${LTO}"
     )
   if (BUILD_STATIC_LIBS)
     add_library (qpid-proton-proactor-static STATIC ${qpid-proton-proactor})
+    target_compile_definitions(qpid-proton-proactor-static PUBLIC PROTON_DECLARE_STATIC)
+    target_link_libraries (qpid-proton-proactor-static ${PLATFORM_LIBS} ${PROACTOR_LIBS})
   endif(BUILD_STATIC_LIBS)
 endif()
 
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index cdfb415..bd926df 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -150,12 +150,6 @@ set(qpid-proton-cpp-source
   ${CONNECT_CONFIG_SRC}
   )
 
-set_source_files_properties (
-  ${qpid-proton-cpp-source}
-  PROPERTIES
-  COMPILE_OPTIONS "${LTO}"
-  )
-
 if (MSVC)
   set (CMAKE_DEBUG_POSTFIX "d")
 endif ()
@@ -163,6 +157,9 @@ endif ()
 add_library(qpid-proton-cpp SHARED ${qpid-proton-cpp-source})
 if(BUILD_STATIC_LIBS)
   add_library(qpid-proton-cpp-static STATIC ${qpid-proton-cpp-source})
+  target_compile_definitions(qpid-proton-cpp-static
+    PRIVATE PROTON_DECLARE_STATIC
+    PUBLIC PN_CPP_DECLARE_STATIC)
   set(STATIC_LIBS qpid-proton-cpp-static)
 endif(BUILD_STATIC_LIBS)
 
@@ -174,7 +171,8 @@ set_target_properties (
   LINKER_LANGUAGE CXX
   VERSION   "${PN_LIB_CPP_VERSION}"
   SOVERSION "${PN_LIB_CPP_MAJOR_VERSION}"
-  LINK_FLAGS "${CATCH_UNDEFINED} ${LTO}"
+  LINK_FLAGS "${CATCH_UNDEFINED} ${LINK_LTO}"
+  COMPILE_FLAGS "${LTO}"
   )
 
 ## Install


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