@@ -6,6 +6,7 @@ option(MQTT_C_OpenSSL_SUPPORT "Build MQTT-C with OpenSSL support?" OFF)
6
6
option (MQTT_C_MbedTLS_SUPPORT "Build MQTT-C with mbed TLS support?" OFF )
7
7
option (MQTT_C_BearSSL_SUPPORT "Build MQTT-C with Bear SSL support?" OFF )
8
8
option (MQTT_C_EXAMPLES "Build MQTT-C examples?" ON )
9
+ option (MQTT_C_INSTALL_EXAMPLES "Install MQTT-C examples?" OFF )
9
10
option (MQTT_C_TESTS "Build MQTT-C tests?" OFF )
10
11
11
12
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake)
@@ -74,25 +75,41 @@ if(MQTT_C_EXAMPLES)
74
75
add_executable (bio_publisher examples/bio_publisher.c)
75
76
add_executable (openssl_publisher examples/openssl_publisher.c)
76
77
endif ()
77
-
78
+ if (MQTT_C_INSTALL_EXAMPLES)
79
+ install (TARGETS bio_publisher openssl_publisher)
80
+ endif ()
78
81
target_link_libraries (bio_publisher Threads::Threads mqttc)
79
82
target_link_libraries (openssl_publisher Threads::Threads mqttc)
80
- elseif (MQTT_C_MbedTLS_SUPPORT)
83
+
84
+ elseif (MQTT_C_MbedTLS_SUPPORT)
81
85
add_executable (mbedtls_publisher examples/mbedtls_publisher.c)
82
86
target_link_libraries (mbedtls_publisher Threads::Threads mqttc ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY} )
87
+ if (MQTT_C_INSTALL_EXAMPLES)
88
+ install (TARGETS mbedtls_publisher)
89
+ endif ()
90
+
83
91
elseif (MQTT_C_BearSSL_SUPPORT)
84
92
add_executable (bearssl_publisher examples/bearssl_publisher.c)
85
93
target_link_libraries (bearssl_publisher mqttc bearssl)
94
+ if (MQTT_C_INSTALL_EXAMPLES)
95
+ install (TARGETS bearssl_publisher)
96
+ endif ()
86
97
else ()
87
98
add_executable (simple_publisher examples/simple_publisher.c)
88
99
target_link_libraries (simple_publisher Threads::Threads mqttc)
89
-
90
- add_executable (simple_subscriber examples/simple_subscriber.c)
91
- target_link_libraries (simple_subscriber Threads::Threads mqttc)
92
-
93
- add_executable (reconnect_subscriber examples/reconnect_subscriber.c)
94
- target_link_libraries (reconnect_subscriber Threads::Threads mqttc)
100
+ if (MQTT_C_INSTALL_EXAMPLES)
101
+ install (TARGETS simple_publisher)
102
+ endif ()
95
103
endif ()
104
+
105
+ # Always install subscriber targets
106
+ add_executable (simple_subscriber examples/simple_subscriber.c)
107
+ target_link_libraries (simple_subscriber Threads::Threads mqttc)
108
+ add_executable (reconnect_subscriber examples/reconnect_subscriber.c)
109
+ target_link_libraries (reconnect_subscriber Threads::Threads mqttc)
110
+ if (MQTT_C_INSTALL_EXAMPLES)
111
+ install (TARGETS simple_subscriber reconnect_subscriber)
112
+ endif ()
96
113
endif ()
97
114
98
115
# Build tests
@@ -108,9 +125,21 @@ if(MQTT_C_TESTS)
108
125
target_include_directories (tests PRIVATE ${CMOCKA_INCLUDE_DIR} )
109
126
endif ()
110
127
128
+ # Handle multi-lib linux systems correctly and allow custom installation locations.
129
+ if (UNIX )
130
+ include (GNUInstallDirs)
131
+ mark_as_advanced (CLEAR
132
+ CMAKE_INSTALL_BINDIR
133
+ CMAKE_INSTALL_LIBDIR
134
+ CMAKE_INSTALL_INCLUDEDIR)
135
+ else ()
136
+ set (CMAKE_INSTALL_LIBDIR "lib" )
137
+ set (CMAKE_INSTALL_INCLUDEDIR "include" )
138
+ endif ()
139
+
111
140
# Install includes and library
112
141
install (TARGETS mqttc
113
- DESTINATION lib
142
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}
114
143
)
115
144
install (DIRECTORY include /
116
- DESTINATION include )
145
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
0 commit comments