Commit c27a4d2e authored by Ian Craggs's avatar Ian Craggs

Merge branch 'build-cmake-static-lib' of…

Merge branch 'build-cmake-static-lib' of https://github.com/guilhermeferreira/paho.mqtt.c into fixes

PR #154
parents a98b6653 1b012f4e
...@@ -34,6 +34,7 @@ STRING(STRIP ${BUILD_TIMESTAMP} BUILD_TIMESTAMP) ...@@ -34,6 +34,7 @@ STRING(STRIP ${BUILD_TIMESTAMP} BUILD_TIMESTAMP)
## build options ## build options
SET(PAHO_WITH_SSL FALSE CACHE BOOL "Flag that defines whether to build ssl-enabled binaries too. ") SET(PAHO_WITH_SSL FALSE CACHE BOOL "Flag that defines whether to build ssl-enabled binaries too. ")
SET(PAHO_BUILD_STATIC FALSE CACHE BOOL "Build static library")
SET(PAHO_BUILD_DOCUMENTATION FALSE CACHE BOOL "Create and install the HTML based API documentation (requires Doxygen)") SET(PAHO_BUILD_DOCUMENTATION FALSE CACHE BOOL "Create and install the HTML based API documentation (requires Doxygen)")
SET(PAHO_BUILD_SAMPLES FALSE CACHE BOOL "Build sample programs") SET(PAHO_BUILD_SAMPLES FALSE CACHE BOOL "Build sample programs")
......
...@@ -36,6 +36,7 @@ Before compiling, determine the value of some variables in order to configure fe ...@@ -36,6 +36,7 @@ Before compiling, determine the value of some variables in order to configure fe
Variable | Default Value | Description Variable | Default Value | Description
------------ | ------------- | ------------- ------------ | ------------- | -------------
PAHO_BUILD_STATIC | FALSE | Build a static version of the libraries
PAHO_WITH_SSL | FALSE | Flag that defines whether to build ssl-enabled binaries too. PAHO_WITH_SSL | FALSE | Flag that defines whether to build ssl-enabled binaries too.
OPENSSL_INC_SEARCH_PATH | "" (system default) | Directory containing OpenSSL includes OPENSSL_INC_SEARCH_PATH | "" (system default) | Directory containing OpenSSL includes
OPENSSL_LIB_SEARCH_PATH | "" (system default) | Directory containing OpenSSL libraries OPENSSL_LIB_SEARCH_PATH | "" (system default) | Directory containing OpenSSL libraries
...@@ -125,6 +126,8 @@ The Paho C client comprises four shared libraries: ...@@ -125,6 +126,8 @@ The Paho C client comprises four shared libraries:
* libmqttv3c.so - "classic" / synchronous * libmqttv3c.so - "classic" / synchronous
* libmqttv3cs.so - "classic" / synchronous with SSL * libmqttv3cs.so - "classic" / synchronous with SSL
Optionally, you can build static version of those libraries.
## Usage and API ## Usage and API
Detailed API documentation is available by building the Doxygen docs in the ``doc`` directory. A [snapshot is also available online](http://www.eclipse.org/paho/files/mqttdoc/Cclient/index.html). Detailed API documentation is available by building the Doxygen docs in the ``doc`` directory. A [snapshot is also available online](http://www.eclipse.org/paho/files/mqttdoc/Cclient/index.html).
......
...@@ -58,11 +58,17 @@ ELSEIF (UNIX) ...@@ -58,11 +58,17 @@ ELSEIF (UNIX)
ENDIF() ENDIF()
ENDIF() ENDIF()
## common compilation for libpaho-mqtt3c and libpaho-mqtt3a
ADD_LIBRARY(common_obj OBJECT ${common_src})
SET_PROPERTY(TARGET common_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
ADD_EXECUTABLE(MQTTVersion MQTTVersion.c) ADD_EXECUTABLE(MQTTVersion MQTTVersion.c)
ADD_LIBRARY(paho-mqtt3c SHARED ${common_src} MQTTClient.c)
ADD_LIBRARY(paho-mqtt3a SHARED ${common_src} MQTTAsync.c) ADD_LIBRARY(paho-mqtt3c SHARED $<TARGET_OBJECTS:common_obj> MQTTClient.c)
ADD_LIBRARY(paho-mqtt3a SHARED $<TARGET_OBJECTS:common_obj> MQTTAsync.c)
TARGET_LINK_LIBRARIES(paho-mqtt3c pthread ${LIBS_SYSTEM}) TARGET_LINK_LIBRARIES(paho-mqtt3c pthread ${LIBS_SYSTEM})
TARGET_LINK_LIBRARIES(paho-mqtt3a pthread ${LIBS_SYSTEM}) TARGET_LINK_LIBRARIES(paho-mqtt3a pthread ${LIBS_SYSTEM})
TARGET_LINK_LIBRARIES(MQTTVersion paho-mqtt3a paho-mqtt3c ${LIBS_SYSTEM}) TARGET_LINK_LIBRARIES(MQTTVersion paho-mqtt3a paho-mqtt3c ${LIBS_SYSTEM})
SET_TARGET_PROPERTIES( SET_TARGET_PROPERTIES(
paho-mqtt3c paho-mqtt3a PROPERTIES paho-mqtt3c paho-mqtt3a PROPERTIES
...@@ -73,6 +79,22 @@ INSTALL(TARGETS paho-mqtt3c paho-mqtt3a ...@@ -73,6 +79,22 @@ INSTALL(TARGETS paho-mqtt3c paho-mqtt3a
LIBRARY DESTINATION lib) LIBRARY DESTINATION lib)
INSTALL(TARGETS MQTTVersion INSTALL(TARGETS MQTTVersion
RUNTIME DESTINATION bin) RUNTIME DESTINATION bin)
IF (PAHO_BUILD_STATIC)
ADD_LIBRARY(paho-mqtt3c-static STATIC $<TARGET_OBJECTS:common_obj> MQTTClient.c)
ADD_LIBRARY(paho-mqtt3a-static STATIC $<TARGET_OBJECTS:common_obj> MQTTAsync.c)
TARGET_LINK_LIBRARIES(paho-mqtt3c-static ${LIBS_SYSTEM})
TARGET_LINK_LIBRARIES(paho-mqtt3a-static ${LIBS_SYSTEM})
INSTALL(TARGETS paho-mqtt3c-static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
INSTALL(TARGETS paho-mqtt3a-static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
ENDIF()
INSTALL(FILES MQTTAsync.h MQTTClient.h MQTTClientPersistence.h INSTALL(FILES MQTTAsync.h MQTTClient.h MQTTClientPersistence.h
DESTINATION include) DESTINATION include)
...@@ -99,8 +121,13 @@ SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL librarie ...@@ -99,8 +121,13 @@ SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL librarie
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
) )
ADD_LIBRARY(paho-mqtt3cs SHARED ${common_src} MQTTClient.c SSLSocket.c)
ADD_LIBRARY(paho-mqtt3as SHARED ${common_src} MQTTAsync.c SSLSocket.c) ## common compilation for libpaho-mqtt3cs and libpaho-mqtt3as
## Note: SSL libraries must be recompiled due ifdefs
ADD_LIBRARY(common_ssl_obj OBJECT ${common_src})
SET_PROPERTY(TARGET common_ssl_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
ADD_LIBRARY(paho-mqtt3cs SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTClient.c SSLSocket.c)
ADD_LIBRARY(paho-mqtt3as SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTAsync.c SSLSocket.c)
TARGET_LINK_LIBRARIES(paho-mqtt3cs pthread ${OPENSSL_LIB} ${OPENSSLCRYPTO_LIB} ${LIBS_SYSTEM}) TARGET_LINK_LIBRARIES(paho-mqtt3cs pthread ${OPENSSL_LIB} ${OPENSSLCRYPTO_LIB} ${LIBS_SYSTEM})
TARGET_LINK_LIBRARIES(paho-mqtt3as pthread ${OPENSSL_LIB} ${OPENSSLCRYPTO_LIB} ${LIBS_SYSTEM}) TARGET_LINK_LIBRARIES(paho-mqtt3as pthread ${OPENSSL_LIB} ${OPENSSLCRYPTO_LIB} ${LIBS_SYSTEM})
...@@ -115,4 +142,20 @@ SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL librarie ...@@ -115,4 +142,20 @@ SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL librarie
INSTALL(TARGETS paho-mqtt3as INSTALL(TARGETS paho-mqtt3as
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib) LIBRARY DESTINATION lib)
IF (PAHO_BUILD_STATIC)
ADD_LIBRARY(paho-mqtt3cs-static STATIC $<TARGET_OBJECTS:common_ssl_obj> MQTTClient.c SSLSocket.c)
ADD_LIBRARY(paho-mqtt3as-static STATIC $<TARGET_OBJECTS:common_ssl_obj> MQTTAsync.c SSLSocket.c)
TARGET_LINK_LIBRARIES(paho-mqtt3cs-static ${OPENSSL_LIBRARIES} ${LIBS_SYSTEM})
TARGET_LINK_LIBRARIES(paho-mqtt3as-static ${OPENSSL_LIBRARIES} ${LIBS_SYSTEM})
INSTALL(TARGETS paho-mqtt3cs-static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
INSTALL(TARGETS paho-mqtt3as-static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
ENDIF()
ENDIF() ENDIF()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment