PROTON-1683: [c,cpp] create static libraries `cmake -DBUILD_STATIC_LIBS=YES` builds static as well as shared C and C++ libraries. Requires static C or C++ runtime libraries to be available, they are optional on some platforms. E.g. on fedora 28: `sudo dnf install libstdc++-static`
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a04a964d Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a04a964d Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a04a964d Branch: refs/heads/go1 Commit: a04a964de3925027ed63454fb8475e7a9a5b1ff5 Parents: 8cc69bd Author: Alan Conway <[email protected]> Authored: Tue May 29 11:51:09 2018 -0400 Committer: Alan Conway <[email protected]> Committed: Tue May 29 13:45:31 2018 -0400 ---------------------------------------------------------------------- CMakeLists.txt | 9 ++++++--- c/CMakeLists.txt | 24 ++++++++++++++---------- cpp/CMakeLists.txt | 3 +++ cpp/include/proton/container.hpp | 11 ++++------- cpp/include/proton/work_queue.hpp | 19 +++++-------------- 5 files changed, 32 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04a964d/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index a0fca0d..a6d463f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,9 @@ if (CMAKE_CXX_COMPILER) option(BUILD_WITH_CXX "Compile Proton using C++" ${DEFAULT_BUILD_WITH_CXX}) endif() +# Bulid static C and C++ libraries in addition to shared libraries. +option(BUILD_STATIC_LIBS "Build static libraries as well as shared libraries" OFF) + if (CMAKE_CONFIGURATION_TYPES) # There is no single "build type"... message(STATUS "Build types are ${CMAKE_CONFIGURATION_TYPES}") @@ -331,13 +334,13 @@ endif() # To kick-start a build with just a few bindings enabled by default, e.g. ruby and go: # -# cmake -DBUILD_BINDINGS=ruby;go +# cmake -DBUILD_BINDINGS="ruby;go" # # This is only used when CMakeCache.txt is first created, after that set the normal # BUILD_XXX variables to enable/disable bindings. # if (NOT DEFINED BUILD_BINDINGS) - set(BUILD_BINDINGS "${BINDINGS}") + set(BUILD_BINDINGS "${BINDINGS}") endif() foreach(BINDING ${BINDINGS}) @@ -348,7 +351,7 @@ foreach(BINDING ${BINDINGS}) endif() option(BUILD_${UBINDING} "Build ${BINDING} language binding" ${DEFAULT_${UBINDING}}) if (BUILD_${UBINDING}) - add_subdirectory(${BINDING}) + add_subdirectory(${BINDING}) endif () endforeach(BINDING) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04a964d/c/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index 40b5037..5fd98ee 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -538,17 +538,18 @@ if (BUILD_WITH_CXX) ) endif (BUILD_WITH_CXX) -add_library ( - qpid-proton-core SHARED +set(qpid-proton-core-src ${qpid-proton-core} ${qpid-proton-layers} ${qpid-proton-platform} ${qpid-proton-include} ${qpid-proton-include-generated} ) -add_dependencies(qpid-proton-core generated_c_files) - +add_library (qpid-proton-core SHARED ${qpid-proton-core-src}) target_link_libraries (qpid-proton-core ${UUID_LIB} ${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) set_target_properties ( qpid-proton-core @@ -558,8 +559,7 @@ set_target_properties ( LINK_FLAGS "${CATCH_UNDEFINED} ${LTO}" ) -add_library( - qpid-proton SHARED +set(qpid-proton-src # Proton Core ${qpid-proton-core} ${qpid-proton-layers} @@ -573,7 +573,10 @@ add_library( ${qpid-proton-platform-io} ${qpid-proton-include-extra} ) -add_dependencies(qpid-proton generated_c_files) +add_library(qpid-proton SHARED ${qpid-proton-src}) +if (BUILD_STATIC_LIBS) + add_library(qpid-proton-static STATIC ${qpid-proton-src}) +endif(BUILD_STATIC_LIBS) if (MSVC) # Add a phony dependency for Windows builds to serialize creation @@ -599,10 +602,8 @@ if (MSVC) endif(MSVC) if (qpid-proton-proactor) - # Bizarre CMake variable setting set(HAS_PROACTOR True) - add_library ( - qpid-proton-proactor SHARED ${qpid-proton-proactor}) + add_library (qpid-proton-proactor SHARED ${qpid-proton-proactor}) target_link_libraries (qpid-proton-proactor LINK_PUBLIC qpid-proton-core) target_link_libraries (qpid-proton-proactor LINK_PRIVATE ${PLATFORM_LIBS} ${PROACTOR_LIBS}) list(APPEND LIB_TARGETS qpid-proton-proactor) @@ -613,6 +614,9 @@ if (qpid-proton-proactor) SOVERSION "${PN_LIB_PROACTOR_MAJOR_VERSION}" LINK_FLAGS "${CATCH_UNDEFINED} ${LTO}" ) + if (BUILD_STATIC_LIBS) + add_library (qpid-proton-proactor-static STATIC ${qpid-proton-proactor}) + endif(BUILD_STATIC_LIBS) endif() # Install executables and libraries http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04a964d/cpp/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 0311506..a9ff90c 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -159,6 +159,9 @@ set_source_files_properties ( ) 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}) +endif(BUILD_STATIC_LIBS) target_link_libraries (qpid-proton-cpp LINK_PRIVATE ${PLATFORM_LIBS} qpid-proton-core qpid-proton-proactor) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04a964d/cpp/include/proton/container.hpp ---------------------------------------------------------------------- diff --git a/cpp/include/proton/container.hpp b/cpp/include/proton/container.hpp index c6a876c..27ac498 100644 --- a/cpp/include/proton/container.hpp +++ b/cpp/include/proton/container.hpp @@ -306,15 +306,12 @@ class PN_CPP_CLASS_EXTERN container { /// **Deprecated** - Use `container::schedule(duration, work)`. PN_CPP_EXTERN PN_CPP_DEPRECATED("Use 'container::schedule(duration, work)'") void schedule(duration dur, void_function0& fn); - /// @cond INTERNAL - // This is a hack to ensure that the C++03 version is declared - // only during the compilation of the library -#if PN_CPP_HAS_LAMBDAS && PN_CPP_HAS_VARIADIC_TEMPLATES && defined(qpid_proton_cpp_EXPORTS) + private: + /// Declare both v03 and v11 if compiling with c++11 as the library contains both. + /// A C++11 user should never call the v03 overload so it is private in this case +#if PN_CPP_HAS_LAMBDAS && PN_CPP_HAS_VARIADIC_TEMPLATES PN_CPP_EXTERN void schedule(duration dur, internal::v03::work fn); #endif - /// @endcond - - private: class impl; internal::pn_unique_ptr<impl> impl_; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04a964d/cpp/include/proton/work_queue.hpp ---------------------------------------------------------------------- diff --git a/cpp/include/proton/work_queue.hpp b/cpp/include/proton/work_queue.hpp index c1c105e..580b201 100644 --- a/cpp/include/proton/work_queue.hpp +++ b/cpp/include/proton/work_queue.hpp @@ -364,14 +364,6 @@ class PN_CPP_CLASS_EXTERN work_queue { /// **Deprecated** - Use `add(work)`. PN_CPP_EXTERN PN_CPP_DEPRECATED("Use 'work_queue::add(work)'") bool add(void_function0& fn); - /// @cond INTERNAL - // This is a hack to ensure that the C++03 version is declared - // only during the compilation of the library -#if PN_CPP_HAS_LAMBDAS && PN_CPP_HAS_VARIADIC_TEMPLATES && defined(qpid_proton_cpp_EXPORTS) - PN_CPP_EXTERN bool add(internal::v03::work fn); -#endif - /// @endcond - /// **Unsettled API** - Add work `fn` to the work queue after a /// duration. /// @@ -385,15 +377,14 @@ class PN_CPP_CLASS_EXTERN work_queue { /// **Deprecated** - Use `schedule(duration, work)`. PN_CPP_EXTERN PN_CPP_DEPRECATED("Use 'work_queue::schedule(duration, work)'") void schedule(duration, void_function0& fn); - /// @cond INTERNAL - // This is a hack to ensure that the C++03 version is declared - // only during the compilation of the library -#if PN_CPP_HAS_LAMBDAS && PN_CPP_HAS_VARIADIC_TEMPLATES && defined(qpid_proton_cpp_EXPORTS) + private: + /// Declare both v03 and v11 if compiling with c++11 as the library contains both. + /// A C++11 user should never call the v03 overload so it is private in this case +#if PN_CPP_HAS_LAMBDAS && PN_CPP_HAS_VARIADIC_TEMPLATES + PN_CPP_EXTERN bool add(internal::v03::work fn); PN_CPP_EXTERN void schedule(duration, internal::v03::work fn); #endif - /// @endcond - private: PN_CPP_EXTERN static work_queue& get(pn_connection_t*); PN_CPP_EXTERN static work_queue& get(pn_session_t*); PN_CPP_EXTERN static work_queue& get(pn_link_t*); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
