From b87082c6041d69d3fee7abb54bcb5701a6513704 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Tue, 31 May 2016 12:26:47 +0800 Subject: [PATCH 1/5] Fix fail linking of handle* functions in the shared library The shared library fails to link to `handle*` functions implementd in lib/handle_* because these source file definitions seem to be removed accidentally in commit 3499c09. Signed-off-by: Lance Chen --- lib/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 574a4683..d0fb10e1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -24,7 +24,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 From 7ee997e6cc45e0527b2c56edabe2af448276c1a8 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Tue, 31 May 2016 12:52:04 +0800 Subject: [PATCH 2/5] Add an option to control building static library or not The BUILD_STATIC_LIBRARY option is default to ON. Signed-off-by: Lance Chen --- lib/CMakeLists.txt | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d0fb10e1..809d9996 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,3 +1,4 @@ +option(BUILD_STATIC_LIBRARY "Build the static library?" ON) add_subdirectory(cpp) option(WITH_THREADING "Include client library threading support?" ON) @@ -58,11 +59,6 @@ set(C_SRC 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) @@ -84,9 +80,9 @@ if (${WITH_SRV} STREQUAL ON) endif (ARES_HEADER) endif (${WITH_SRV} STREQUAL ON) -target_link_libraries(libmosquitto ${LIBRARIES}) +add_library(libmosquitto SHARED ${C_SRC} ) -target_link_libraries(libmosquitto_static ${LIBRARIES}) +target_link_libraries(libmosquitto ${LIBRARIES}) set_target_properties(libmosquitto PROPERTIES OUTPUT_NAME mosquitto @@ -94,14 +90,23 @@ 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 (${BUILD_STATIC_LIBRARY} STREQUAL ON) + #target for building static version of library + add_library(libmosquitto_static STATIC ${C_SRC}) + + 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 (${BUILD_STATIC_LIBRARY} 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) From aa360e402958ef4eaf0bdc76334196befa3d8ad7 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Tue, 31 May 2016 14:06:37 +0800 Subject: [PATCH 3/5] Add an option to control building static library with PIC or not The option WITH_PIC is default to OFF. By default, the static library is built from the source code directly. If WITH_PIC is enabled, the static library is built with the same set of object libraries that the shared library uses. To link Mosquitto static library into a shared library, one must enable WITH_PIC to make the piece of code locatable. Signed-off-by: Lance Chen --- lib/CMakeLists.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 809d9996..1290f998 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,5 @@ option(BUILD_STATIC_LIBRARY "Build the static library?" 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) @@ -80,7 +81,12 @@ if (${WITH_SRV} STREQUAL ON) endif (ARES_HEADER) endif (${WITH_SRV} STREQUAL ON) -add_library(libmosquitto SHARED ${C_SRC} ) +add_library(libmosquitto_obj OBJECT ${C_SRC}) +set_target_properties(libmosquitto_obj PROPERTIES + POSITION_INDEPENDENT_CODE 1 +) + +add_library(libmosquitto SHARED $) target_link_libraries(libmosquitto ${LIBRARIES}) @@ -93,8 +99,11 @@ set_target_properties(libmosquitto PROPERTIES install(TARGETS libmosquitto RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR}) if (${BUILD_STATIC_LIBRARY} STREQUAL ON) - #target for building static version of library - add_library(libmosquitto_static STATIC ${C_SRC}) + if (${WITH_PIC} STREQUAL OFF) + add_library(libmosquitto_static STATIC ${C_SRC}) + else (${WITH_PIC} STREQUAL OFF) + add_library(libmosquitto_static STATIC $) + endif (${WITH_PIC} STREQUAL OFF) target_link_libraries(libmosquitto_static ${LIBRARIES}) From f18e8e12a89536fd8eb00d618a66df28ab95e5d4 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Tue, 31 May 2016 14:27:12 +0800 Subject: [PATCH 4/5] 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) From 97847fa95b91d5b5ddfae7508ed2f1f8ece28dce Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Fri, 3 Jun 2016 01:53:58 +0800 Subject: [PATCH 5/5] Rename option BUILD_STATIC_LIBRARY to WITH_STATIC_LIBRARIES to conform to the bare Makefiles Signed-off-by: Lance Chen --- lib/CMakeLists.txt | 6 +++--- lib/cpp/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1290f998..c7c2f53f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,4 @@ -option(BUILD_STATIC_LIBRARY "Build the static library?" ON) +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) @@ -98,7 +98,7 @@ set_target_properties(libmosquitto PROPERTIES install(TARGETS libmosquitto RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR}) -if (${BUILD_STATIC_LIBRARY} STREQUAL ON) +if (${WITH_STATIC_LIBRARIES} STREQUAL ON) if (${WITH_PIC} STREQUAL OFF) add_library(libmosquitto_static STATIC ${C_SRC}) else (${WITH_PIC} STREQUAL OFF) @@ -114,7 +114,7 @@ if (${BUILD_STATIC_LIBRARY} STREQUAL ON) target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC") install(TARGETS libmosquitto_static RUNTIME DESTINATION ${BINDIR} ARCHIVE DESTINATION ${LIBDIR}) -endif (${BUILD_STATIC_LIBRARY} STREQUAL ON) +endif (${WITH_STATIC_LIBRARIES} STREQUAL ON) install(FILES mosquitto.h DESTINATION ${INCLUDEDIR}) diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 2b9f3eb9..91adc3fa 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -18,7 +18,7 @@ set_target_properties(mosquittopp PROPERTIES ) install(TARGETS mosquittopp RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR}) -if (${BUILD_STATIC_LIBRARY} STREQUAL ON) +if (${WITH_STATIC_LIBRARIES} STREQUAL ON) if (${WITH_PIC} STREQUAL OFF) add_library(mosquittopp_static STATIC $ @@ -40,7 +40,7 @@ if (${BUILD_STATIC_LIBRARY} STREQUAL ON) target_compile_definitions(mosquittopp_static PUBLIC "LIBMOSQUITTO_STATIC") install(TARGETS mosquittopp_static RUNTIME DESTINATION ${BINDIR} ARCHIVE DESTINATION ${LIBDIR}) -endif (${BUILD_STATIC_LIBRARY} STREQUAL ON) +endif (${WITH_STATIC_LIBRARIES} STREQUAL ON) install(FILES mosquittopp.h DESTINATION ${INCLUDEDIR})