Skip to content

Commit a038c0e

Browse files
authored
[mosquitto] Overhaul (#46849)
1 parent d76af7c commit a038c0e

13 files changed

+201
-131
lines changed

ports/mosquitto/0003-add-find_package-libwebsockets.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.

ports/mosquitto/0004-support-static-build.patch

Lines changed: 0 additions & 42 deletions
This file was deleted.

ports/mosquitto/0005-websocket-shared-lib-name.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 9e1c58d..6fa9392 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -71,7 +71,7 @@ option(WITH_PIC "Build the static library with PIC (Position Independent Code) e
6+
option(WITH_THREADING "Include client library threading support?" ON)
7+
if (WITH_THREADING)
8+
add_definitions("-DWITH_THREADING")
9+
- if(WIN32)
10+
+ if(WIN32 AND NOT MINGW)
11+
find_package(Pthreads4W REQUIRED)
12+
endif()
13+
endif (WITH_THREADING)
14+
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
15+
index 21b6149..051dffe 100644
16+
--- a/lib/CMakeLists.txt
17+
+++ b/lib/CMakeLists.txt
18+
@@ -60,7 +60,7 @@ set(C_SRC
19+
util_mosq.c util_topic.c util_mosq.h
20+
will_mosq.c will_mosq.h)
21+
22+
-set (LIBRARIES OpenSSL::SSL)
23+
+set (LIBRARIES PRIVATE OpenSSL::SSL)
24+
25+
if (UNIX AND NOT APPLE AND NOT ANDROID)
26+
find_library(LIBRT rt)
27+
@@ -90,7 +90,7 @@ set_target_properties(libmosquitto PROPERTIES
28+
)
29+
30+
if (WITH_THREADING)
31+
- if(WIN32)
32+
+ if(WIN32 AND NOT MINGW)
33+
set (LIBRARIES ${LIBRARIES} PThreads4W::PThreads4W)
34+
else()
35+
set(THREADS_PREFER_PTHREAD_FLAG ON)
36+
@@ -115,11 +115,6 @@ if(UNIX AND NOT APPLE)
37+
)
38+
endif()
39+
40+
-install(TARGETS libmosquitto
41+
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
42+
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
43+
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
44+
-
45+
if (WITH_STATIC_LIBRARIES)
46+
add_library(libmosquitto_static STATIC ${C_SRC})
47+
if (WITH_PIC)
48+
@@ -136,8 +131,28 @@ if (WITH_STATIC_LIBRARIES)
49+
)
50+
51+
target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC")
52+
- install(TARGETS libmosquitto_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
53+
+
54+
+ set(install_target libmosquitto_static)
55+
+ set_target_properties(libmosquitto PROPERTIES EXCLUDE_FROM_ALL 1)
56+
+else ()
57+
+ set(install_target libmosquitto)
58+
endif (WITH_STATIC_LIBRARIES)
59+
60+
+target_include_directories(${install_target} PUBLIC $<INSTALL_INTERFACE:include>)
61+
+set_target_properties(${install_target} PROPERTIES EXPORT_NAME mosquitto)
62+
+install(TARGETS ${install_target}
63+
+ EXPORT mosquitto
64+
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
65+
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
66+
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
67+
+)
68+
+install(EXPORT mosquitto
69+
+ NAMESPACE unofficial::mosquitto::
70+
+ FILE unofficial-mosquitto-targets.cmake
71+
+ DESTINATION "share/unofficial-mosquitto"
72+
+)
73+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/unofficial-mosquitto-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/unofficial-mosquitto-config.cmake" @ONLY)
74+
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unofficial-mosquitto-config.cmake" DESTINATION "share/unofficial-mosquitto")
75+
+
76+
install(FILES ../include/mosquitto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
77+
install(FILES ../include/mqtt_protocol.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
78+
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
79+
index 882b662..5959a96 100644
80+
--- a/lib/cpp/CMakeLists.txt
81+
+++ b/lib/cpp/CMakeLists.txt
82+
@@ -9,15 +9,11 @@ add_library(mosquittopp SHARED ${CPP_SRC})
83+
set_target_properties(mosquittopp PROPERTIES
84+
POSITION_INDEPENDENT_CODE 1
85+
)
86+
-target_link_libraries(mosquittopp libmosquitto)
87+
+target_link_libraries(mosquittopp PUBLIC libmosquitto)
88+
set_target_properties(mosquittopp PROPERTIES
89+
VERSION ${VERSION}
90+
SOVERSION 1
91+
)
92+
-install(TARGETS mosquittopp
93+
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
94+
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
95+
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
96+
97+
if (WITH_STATIC_LIBRARIES)
98+
add_library(mosquittopp_static STATIC
99+
@@ -30,7 +26,7 @@ if (WITH_STATIC_LIBRARIES)
100+
)
101+
endif (WITH_PIC)
102+
103+
- target_link_libraries(mosquittopp_static ${LIBRARIES})
104+
+ target_link_libraries(mosquittopp_static PUBLIC libmosquitto_static)
105+
106+
set_target_properties(mosquittopp_static PROPERTIES
107+
OUTPUT_NAME mosquittopp_static
108+
@@ -38,7 +34,19 @@ if (WITH_STATIC_LIBRARIES)
109+
)
110+
111+
target_compile_definitions(mosquittopp_static PUBLIC "LIBMOSQUITTO_STATIC")
112+
- install(TARGETS mosquittopp_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
113+
+
114+
+ set(install_target mosquittopp_static)
115+
+ set_target_properties(mosquittopp PROPERTIES EXCLUDE_FROM_ALL 1)
116+
+else ()
117+
+ set(install_target mosquittopp)
118+
endif (WITH_STATIC_LIBRARIES)
119+
120+
+set_target_properties(${install_target} PROPERTIES EXPORT_NAME mosquittopp)
121+
+install(TARGETS ${install_target}
122+
+ EXPORT mosquitto
123+
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
124+
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
125+
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
126+
+)
127+
+
128+
install(FILES mosquittopp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
129+
diff --git a/libmosquitto.pc.in b/libmosquitto.pc.in
130+
index 101a125..0747b43 100644
131+
--- a/libmosquitto.pc.in
132+
+++ b/libmosquitto.pc.in
133+
@@ -8,3 +8,5 @@ Description: mosquitto MQTT library (C bindings)
134+
Version: @VERSION@
135+
Cflags: -I${includedir}
136+
Libs: -L${libdir} -lmosquitto
137+
+Libs.private: @CMAKE_THREAD_LIBS_INIT@
138+
+Requires.private: libssl
139+
diff --git a/libmosquittopp.pc.in b/libmosquittopp.pc.in
140+
index 6070f44..4edde61 100644
141+
--- a/libmosquittopp.pc.in
142+
+++ b/libmosquittopp.pc.in
143+
@@ -8,3 +8,4 @@ Description: mosquitto MQTT library (C++ bindings)
144+
Version: @VERSION@
145+
Cflags: -I${includedir}
146+
Libs: -L${libdir} -lmosquittopp
147+
+Requires.private: libmosquitto
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
message(AUTHOR_WARNING "find_package(${PACKAGE_NAME}) is deprecated.\n${usage}")
2+
3+
include(CMakeFindDependencyMacro)
4+
find_dependency(unofficial-mosquitto CONFIG)
5+
6+
# legacy, ported from wrapper
7+
find_path(MOSQUITTO_INCLUDE_DIR mosquitto.h)
8+
set(MOSQUITTO_INCLUDE_DIRS ${MOSQUITTO_INCLUDE_DIR})
9+
10+
# legacy, both vars included the C++ target
11+
set(MOSQUITTO_LIBRARIES unofficial::mosquitto::mosquittopp)
12+
set(MOSQUITTOPP_LIBRARIES unofficial::mosquitto::mosquittopp)

ports/mosquitto/portfile.cmake

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ vcpkg_from_github(
55
REF "v${VERSION}"
66
SHA512 ca8bdcb10fea751e655e2de393479b2f863287b396b13e441de46c32918229c1f80a386fdd6d0daf3b0161f640702b6d8a87f2278c9baf2150e2c533cb59e57a
77
PATCHES
8-
0003-add-find_package-libwebsockets.patch
9-
0004-support-static-build.patch
10-
0005-websocket-shared-lib-name.patch
8+
linkage-and-export.diff
119
)
10+
file(REMOVE_RECURSE "${SOURCE_PATH}/deps")
11+
file(COPY "${CURRENT_PORT_DIR}/unofficial-mosquitto-config.cmake" DESTINATION "${SOURCE_PATH}/lib")
1212

1313
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" STATIC_LINKAGE)
1414

@@ -17,8 +17,6 @@ vcpkg_cmake_configure(
1717
OPTIONS
1818
-DWITH_STATIC_LIBRARIES=${STATIC_LINKAGE}
1919
-DWITH_SRV=OFF
20-
-DWITH_WEBSOCKETS=ON
21-
-DSTATIC_WEBSOCKETS=${STATIC_LINKAGE}
2220
-DWITH_TLS=ON
2321
-DWITH_TLS_PSK=ON
2422
-DWITH_THREADING=ON
@@ -29,47 +27,16 @@ vcpkg_cmake_configure(
2927
-DWITH_APPS=OFF
3028
-DWITH_BROKER=OFF
3129
-DWITH_BUNDLED_DEPS=OFF
32-
MAYBE_UNUSED_VARIABLES
33-
WITH_WEBSOCKETS
34-
STATIC_WEBSOCKETS
3530
)
36-
3731
vcpkg_cmake_install()
3832
vcpkg_copy_pdbs()
39-
4033
vcpkg_fixup_pkgconfig()
34+
vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-mosquitto)
4135

4236
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
4337
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
4438

45-
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
46-
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
47-
48-
file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquitto${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}")
49-
file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquittopp${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}")
50-
file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquitto${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}")
51-
file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquittopp${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}")
52-
53-
file(GLOB VERSIONED_LIBRARIES LIST_DIRECTORIES FALSE
54-
"${CURRENT_PACKAGES_DIR}/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquitto${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}.*"
55-
"${CURRENT_PACKAGES_DIR}/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquittopp${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}.*"
56-
"${CURRENT_PACKAGES_DIR}/debug/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquitto${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}.*"
57-
"${CURRENT_PACKAGES_DIR}/debug/lib/${VCPKG_TARGET_SHARED_LIBRARY_PREFIX}mosquittopp${VCPKG_TARGET_SHARED_LIBRARY_SUFFIX}.*"
58-
)
59-
60-
if(NOT "x${VERSIONED_LIBRARIES}x" STREQUAL "xx")
61-
file(REMOVE ${VERSIONED_LIBRARIES})
62-
endif()
63-
64-
if(NOT "x${VCPKG_TARGET_IMPORT_LIBRARY_PREFIX}${VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX}x" STREQUAL "xx")
65-
file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/${VCPKG_TARGET_IMPORT_LIBRARY_PREFIX}mosquitto${VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX}")
66-
file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/${VCPKG_TARGET_IMPORT_LIBRARY_PREFIX}mosquittopp${VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX}")
67-
file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/${VCPKG_TARGET_IMPORT_LIBRARY_PREFIX}mosquitto${VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX}")
68-
file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/lib/${VCPKG_TARGET_IMPORT_LIBRARY_PREFIX}mosquittopp${VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX}")
69-
endif()
70-
endif()
71-
72-
configure_file(${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake ${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake @ONLY)
73-
39+
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/mosquitto-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
7440
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
41+
7542
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.txt")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if("@WITH_STATIC_LIBRARIES@")
2+
include(CMakeFindDependencyMacro)
3+
find_dependency(OpenSSL)
4+
if(WIN32 AND NOT MINGW)
5+
find_dependency(Pthreads4W)
6+
else()
7+
find_dependency(Threads)
8+
endif()
9+
endif()
10+
include("${CMAKE_CURRENT_LIST_DIR}/unofficial-mosquitto-targets.cmake")

ports/mosquitto/usage

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
The package mosquitto provides CMake targets:
1+
mosquitto provides CMake targets:
22

3-
find_package(mosquitto REQUIRED)
4-
target_include_directories(main PRIVATE ${MOSQUITTO_INCLUDE_DIRS})
5-
target_link_libraries(main PRIVATE ${MOSQUITTO_LIBRARIES})
3+
find_package(unofficial-mosquitto CONFIG REQUIRED)
4+
# C bindings
5+
target_link_libraries(main PRIVATE unofficial::mosquitto::mosquitto)
6+
# C++ bindings
7+
target_link_libraries(main PRIVATE unofficial::mosquitto::mosquittopp)
8+
9+
mosquitto provides pkg-config modules:
10+
11+
# mosquitto MQTT library (C bindings)
12+
libmosquitto
13+
14+
# mosquitto MQTT library (C++ bindings)
15+
libmosquittopp

ports/mosquitto/vcpkg-cmake-wrapper.cmake

Lines changed: 0 additions & 15 deletions
This file was deleted.

ports/mosquitto/vcpkg.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
22
"name": "mosquitto",
33
"version": "2.0.22",
4+
"port-version": 1,
45
"description": "Mosquitto is an open source message broker that implements the MQ Telemetry Transport protocol versions 3.1 and 3.1.1, MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model, This makes it suitable for machine to machine messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino",
56
"homepage": "https://mosquitto.org/",
67
"license": "EPL-2.0",
7-
"supports": "!android",
8+
"supports": "!uwp",
89
"dependencies": [
9-
"c-ares",
10-
"libwebsockets",
1110
"openssl",
1211
"pthreads",
1312
"uthash",
1413
{
1514
"name": "vcpkg-cmake",
1615
"host": true
16+
},
17+
{
18+
"name": "vcpkg-cmake-config",
19+
"host": true
1720
}
1821
]
1922
}

0 commit comments

Comments
 (0)