Merge pull request #179 from Lance0312/enhance-static-library-build

Enhance static library build
pull/190/head
Roger Light 9 years ago
commit 6c87f7a514

@ -1,3 +1,5 @@
option(WITH_STATIC_LIBRARIES "Build the static libraries?" ON)
option(WITH_PIC "Build the static library with PIC(Position Independent Code) enabled archives?" OFF)
add_subdirectory(cpp)
option(WITH_THREADING "Include client library threading support?" ON)
@ -24,7 +26,17 @@ include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/lib
${OPENSSL_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIR})
link_directories(${mosquitto_SOURCE_DIR}/lib)
set(C_SRC logging_mosq.c logging_mosq.h
set(C_SRC
handle_connack.c
handle_ping.c
handle_pubackcomp.c
handle_publish.c
handle_pubrec.c
handle_pubrel.c
handle_suback.c
handle_unsuback.c
helpers.c
logging_mosq.c logging_mosq.h
memory_mosq.c memory_mosq.h
messages_mosq.c messages_mosq.h
mosquitto.c mosquitto.h
@ -48,11 +60,6 @@ set(C_SRC logging_mosq.c logging_mosq.h
util_mosq.c util_mosq.h
will_mosq.c will_mosq.h)
add_library(libmosquitto SHARED ${C_SRC} )
#target for building static version of library
add_library(libmosquitto_static STATIC ${C_SRC})
set (LIBRARIES ${OPENSSL_LIBRARIES} ${PTHREAD_LIBRARIES})
if (UNIX AND NOT APPLE)
@ -74,9 +81,14 @@ if (${WITH_SRV} STREQUAL ON)
endif (ARES_HEADER)
endif (${WITH_SRV} STREQUAL ON)
target_link_libraries(libmosquitto ${LIBRARIES})
add_library(libmosquitto_obj OBJECT ${C_SRC})
set_target_properties(libmosquitto_obj PROPERTIES
POSITION_INDEPENDENT_CODE 1
)
add_library(libmosquitto SHARED $<TARGET_OBJECTS:libmosquitto_obj>)
target_link_libraries(libmosquitto_static ${LIBRARIES})
target_link_libraries(libmosquitto ${LIBRARIES})
set_target_properties(libmosquitto PROPERTIES
OUTPUT_NAME mosquitto
@ -84,14 +96,26 @@ set_target_properties(libmosquitto PROPERTIES
SOVERSION 1
)
set_target_properties(libmosquitto_static PROPERTIES
OUTPUT_NAME mosquitto
VERSION ${VERSION}
)
install(TARGETS libmosquitto RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR})
if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
if (${WITH_PIC} STREQUAL OFF)
add_library(libmosquitto_static STATIC ${C_SRC})
else (${WITH_PIC} STREQUAL OFF)
add_library(libmosquitto_static STATIC $<TARGET_OBJECTS:libmosquitto_obj>)
endif (${WITH_PIC} STREQUAL OFF)
target_link_libraries(libmosquitto_static ${LIBRARIES})
set_target_properties(libmosquitto_static PROPERTIES
OUTPUT_NAME mosquitto
VERSION ${VERSION}
)
target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC")
target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC")
install(TARGETS libmosquitto_static RUNTIME DESTINATION ${BINDIR} ARCHIVE DESTINATION ${LIBDIR})
endif (${WITH_STATIC_LIBRARIES} STREQUAL ON)
install(TARGETS libmosquitto libmosquitto_static RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR} ARCHIVE DESTINATION ${LIBDIR})
install(FILES mosquitto.h DESTINATION ${INCLUDEDIR})
if (UNIX AND NOT APPLE)

@ -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_OBJECTS:mosquittopp_obj>)
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 (${WITH_STATIC_LIBRARIES} STREQUAL ON)
if (${WITH_PIC} STREQUAL OFF)
add_library(mosquittopp_static STATIC
$<TARGET_OBJECTS:libmosquitto_obj>
${C_SRC}
)
else (${WITH_PIC} STREQUAL OFF)
add_library(mosquittopp_static STATIC
$<TARGET_OBJECTS:libmosquitto_obj>
$<TARGET_OBJECTS:mosquittopp_obj>
)
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 (${WITH_STATIC_LIBRARIES} STREQUAL ON)
install(FILES mosquittopp.h DESTINATION ${INCLUDEDIR})
if (UNIX AND NOT APPLE)

Loading…
Cancel
Save