From f18e8e12a89536fd8eb00d618a66df28ab95e5d4 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Tue, 31 May 2016 14:27:12 +0800 Subject: [PATCH] Add build configuration for CPP static library The CPP static library respects options BUILD_STATIC_LIBRARY and WITH_PIC as well. Signed-off-by: Lance Chen --- lib/cpp/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 2a81c2bf..2b9f3eb9 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -2,8 +2,14 @@ include_directories(${mosquitto_SOURCE_DIR}/lib ${mosquitto_SOURCE_DIR}/lib/cpp ${STDBOOL_H_PATH} ${STDINT_H_PATH}) link_directories(${mosquitto_BINARY_DIR}/lib) -add_library(mosquittopp SHARED - mosquittopp.cpp mosquittopp.h) +set(C_SRC mosquittopp.cpp mosquittopp.h) + +add_library(mosquittopp_obj OBJECT ${C_SRC}) +set_target_properties(mosquittopp_obj PROPERTIES + POSITION_INDEPENDENT_CODE 1 +) + +add_library(mosquittopp SHARED $) target_link_libraries(mosquittopp libmosquitto) set_target_properties(mosquittopp PROPERTIES @@ -11,6 +17,31 @@ set_target_properties(mosquittopp PROPERTIES SOVERSION 1 ) install(TARGETS mosquittopp RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR}) + +if (${BUILD_STATIC_LIBRARY} STREQUAL ON) + if (${WITH_PIC} STREQUAL OFF) + add_library(mosquittopp_static STATIC + $ + ${C_SRC} + ) + else (${WITH_PIC} STREQUAL OFF) + add_library(mosquittopp_static STATIC + $ + $ + ) + endif (${WITH_PIC} STREQUAL OFF) + + target_link_libraries(mosquittopp_static ${LIBRARIES}) + + set_target_properties(mosquittopp_static PROPERTIES + OUTPUT_NAME mosquittopp + VERSION ${VERSION} + ) + + target_compile_definitions(mosquittopp_static PUBLIC "LIBMOSQUITTO_STATIC") + install(TARGETS mosquittopp_static RUNTIME DESTINATION ${BINDIR} ARCHIVE DESTINATION ${LIBDIR}) +endif (${BUILD_STATIC_LIBRARY} STREQUAL ON) + install(FILES mosquittopp.h DESTINATION ${INCLUDEDIR}) if (UNIX AND NOT APPLE)