Skip to content

Commit

Permalink
Fix Paho C build
Browse files Browse the repository at this point in the history
  • Loading branch information
laitingsheng committed Dec 31, 2023
1 parent 1980bd3 commit 63fe92f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "src/externals/paho-mqtt-c"]
path = src/externals/paho-mqtt-c
url = https://github.com/eclipse/paho.mqtt.c.git
url = ../paho.mqtt.c.git
45 changes: 17 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# and Eclipse Distribution License v1.0 which accompany this distribution.
#
#
# The Eclipse Public License is available at
# http://www.eclipse.org/legal/epl-v20.html
# and the Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
#
# Contributors:
# Guilherme Maciel Ferreira - initial version
# Frank Pagliughi
Expand Down Expand Up @@ -50,27 +50,28 @@ endif()

## --- Find Paho C or build it, if reqested ---

if(PAHO_WITH_SSL)
find_package(OpenSSL REQUIRED)
set(PAHO_MQTT_C_LIB paho-mqtt3as)
else()
set(PAHO_MQTT_C_LIB paho-mqtt3a)
endif()

if(PAHO_BUILD_STATIC AND NOT PAHO_BUILD_SHARED)
set(PAHO_MQTT_C_LIB ${PAHO_MQTT_C_LIB}-static)
endif()

if(PAHO_WITH_MQTT_C)
message(STATUS "Paho C: Bundled")

## Build the Paho C library from the submodule
set(PAHO_ENABLE_TESTING FALSE CACHE BOOL "No Paho C tests")
set(PAHO_HIGH_PERFORMANCE TRUE CACHE BOOL "Paho C high performance")

add_subdirectory(${PROJECT_SOURCE_DIR}/externals/paho-mqtt-c)

## Alias namespace so that the full names can be used with the subdir.
if(PAHO_BUILD_SHARED)
add_library(eclipse-paho-mqtt-c::paho-mqtt3a ALIAS paho-mqtt3a)
if(PAHO_WITH_SSL)
add_library(eclipse-paho-mqtt-c::paho-mqtt3as ALIAS paho-mqtt3as)
endif()
else()
# Seems that the C lib
add_library(eclipse-paho-mqtt-c::paho-mqtt3a-static ALIAS paho-mqtt3a-static)
if(PAHO_WITH_SSL)
add_library(eclipse-paho-mqtt-c::paho-mqtt3as-static ALIAS paho-mqtt3as-static)
endif()
add_subdirectory(${PROJECT_SOURCE_DIR}/src/externals/paho-mqtt-c EXCLUDE_FROM_ALL)

if(NOT TARGET ${PAHO_MQTT_C_LIB})
message(FATAL_ERROR "${PAHO_MQTT_C_LIB} not found in Paho C build")
endif()

## install paho.mqtt.c library (appending to PahoMqttCpp export)
Expand All @@ -83,17 +84,6 @@ else()
find_package(eclipse-paho-mqtt-c REQUIRED)
endif()

if(PAHO_WITH_SSL)
find_package(OpenSSL REQUIRED)
set(PAHO_MQTT_C_LIB eclipse-paho-mqtt-c::paho-mqtt3as)
else()
set(PAHO_MQTT_C_LIB eclipse-paho-mqtt-c::paho-mqtt3a)
endif()

if(PAHO_BUILD_STATIC AND NOT PAHO_BUILD_SHARED)
set(PAHO_MQTT_C_LIB ${PAHO_MQTT_C_LIB}-static)
endif()

## --- C++11 build flags ---

set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -161,4 +151,3 @@ endif()
include(CPack)

add_subdirectory(cmake)

15 changes: 7 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# and Eclipse Distribution License v1.0 which accompany this distribution.
#
# The Eclipse Public License is available at
# and Eclipse Distribution License v1.0 which accompany this distribution.
#
# The Eclipse Public License is available at
# http://www.eclipse.org/legal/epl-v20.html
# and the Eclipse Distribution License is available at
# and the Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
#
# Contributors:
# Guilherme Maciel Ferreira - initial version
# Frank Pagliughi - made the shared library optional
Expand All @@ -38,7 +38,7 @@ set(COMMON_SRC
async_client.cpp
client.cpp
connect_options.cpp
create_options.cpp
create_options.cpp
disconnect_options.cpp
iclient_persistence.cpp
message.cpp
Expand All @@ -61,7 +61,6 @@ if(PAHO_BUILD_SHARED)

## Add dependencies to the shared library
target_link_libraries(paho-mqttpp3 PUBLIC
eclipse-paho-mqtt-c::paho-mqtt3as
${PAHO_MQTT_C_LIB}
Threads::Threads
)
Expand All @@ -81,7 +80,7 @@ if(PAHO_BUILD_STATIC)
list(APPEND PAHO_CPP_TARGETS paho-mqttpp3-static)

## add dependencies to the shared library
target_link_libraries(paho-mqttpp3-static PUBLIC
target_link_libraries(paho-mqttpp3-static PUBLIC
${PAHO_MQTT_C_LIB}
Threads::Threads
)
Expand Down

0 comments on commit 63fe92f

Please sign in to comment.