-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
408 lines (342 loc) · 18.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
cmake_minimum_required (VERSION 3.10)
project ("cc.mqtt311.commsdsl")
option (MQTT311_WARN_AS_ERR "Treat compilation warnings as errors." ON)
option (MQTT311_USE_CCACHE "Use ccache." OFF)
option (MQTT311_GEN_PROTOCOL "Use commsdsl2comms to generate protocol definition" ON)
option (MQTT311_BUILD_PROTOCOL "Build and install protocol definition generated by the commsdsl2comms" ${MQTT311_GEN_PROTOCOL})
option (MQTT311_BUILD_PROT_DOC "Build documentation for generated protocol" OFF)
option (MQTT311_GEN_TEST "Use commsdsl2test to generate test project." OFF)
option (MQTT311_BUILD_TEST "Build and install project generated by the commsdsl2test." ${MQTT311_GEN_TEST})
option (MQTT311_GEN_TOOLS "Use commsdsl2tools_qt to generate cc_tools_qt plugin project." OFF)
option (MQTT311_BUILD_TOOLS "Build and install project generated by the commsdsl2tools_qt." ${MQTT311_GEN_TOOLS})
option (MQTT311_GEN_SWIG "Use commsdsl2swig to generate swig bindings project." OFF)
option (MQTT311_BUILD_SWIG "Build and install project generated by the commsdsl2swig." ${MQTT311_GEN_SWIG})
option (MQTT311_GEN_EMSCRIPTEN "Use commsdsl2emscripten to generate emscripten bindings project." OFF)
option (MQTT311_BUILD_EMSCRIPTEN "Build and install project generated by the commsdsl2emscripten." ${MQTT311_GEN_EMSCRIPTEN})
# Additional variables to be used if needed
# ---------------------------
# MQTT311_PROT_OUTPUT_DIR - Path to protocol output directory. If not provided <build_dir>/output one is used.
# MQTT311_TEST_OUTPUT_DIR - Path to test output directory. If not provided <build_dir>/output_tools one is used.
# MQTT311_TOOLS_OUTPUT_DIR - Path to tools output directory. If not provided <build_dir>/output_tools one is used.
# MQTT311_TOOLS_QT_VER - Major Qt version to be used when building tools output. Defaults to 5
# MQTT311_SWIG_OUTPUT_DIR - Path to swig output directory. If not provided <build_dir>/output_swig one is used.
# MQTT311_SWIG_SRC_DIR - Path to the commsdsl2swig sources. If not provided local "src/swig" dir is used.
# MQTT311_SWIG_LANGUAGES - Languages list to support by swig. If not provided "python java csharp" are chosen
# MQTT311_EMSCRIPTEN_OUTPUT_DIR - Path to emscripten output directory. If not provided <build_dir>/output_emscripten one is used.
# MQTT311_CCACHE_EXECUTABLE - Custom ccache executable
# COMMSDSL2COMMS_EXTRA_ARGS - Extra arguments to pass to "commsdsl2comms"
# COMMSDSL2TEST_EXTRA_ARGS - Extra arguments to pass to "commsdsl2test"
# COMMSDSL2TOOLS_QT_EXTRA_ARGS - Extra arguments to pass to "commsdsl2tools_qt"
# COMMSDSL2SWIG_EXTRA_ARGS - Extra arguments to pass to "commsdsl2swig"
# COMMSDSL2EMSCRIPTEN_EXTRA_ARGS - Extra arguments to pass to "commsdsl2emscripten"
set (MQTT311_VERSION "2.9")
set (MQTT311_MIN_COMMSDSL_VERSION "6.3.4")
if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
set(CMAKE_CXX_STANDARD 17)
endif ()
set (EXTERNALS_DIR "${PROJECT_SOURCE_DIR}/externals")
set (PROT_OUTPUT_TGT "prot_output_tgt")
set (schema_file "${CMAKE_SOURCE_DIR}/dsl/schema.xml")
if ("${MQTT311_PROT_OUTPUT_DIR}" STREQUAL "")
set (MQTT311_PROT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/output")
endif ()
if ("${MQTT311_TEST_OUTPUT_DIR}" STREQUAL "")
set (MQTT311_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/output_test")
endif ()
if ("${MQTT311_TOOLS_OUTPUT_DIR}" STREQUAL "")
set (MQTT311_TOOLS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/output_tools")
endif ()
if ("${MQTT311_SWIG_OUTPUT_DIR}" STREQUAL "")
set (MQTT311_SWIG_OUTPUT_DIR "${CMAKE_BINARY_DIR}/output_swig")
endif ()
if ("${MQTT311_SWIG_SRC_DIR}" STREQUAL "")
set (MQTT311_SWIG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/swig)
endif ()
if ("${MQTT311_SWIG_LANGUAGES}" STREQUAL "")
set (MQTT311_SWIG_LANGUAGES python java csharp)
endif ()
if ("${MQTT311_EMSCRIPTEN_OUTPUT_DIR}" STREQUAL "")
set (MQTT311_EMSCRIPTEN_OUTPUT_DIR "${CMAKE_BINARY_DIR}/output_emscripten")
endif ()
if ("${MQTT311_TOOLS_QT_VER}" STREQUAL "")
set (MQTT311_TOOLS_QT_VER 5)
endif ()
set (warn_as_error "--warn-as-err")
if (NOT MQTT311_WARN_AS_ERR)
set (warn_as_error)
endif ()
include (ExternalProject)
if (MQTT311_GEN_PROTOCOL)
find_program(COMMSDSL2COMMS commsdsl2comms PATH_SUFFIXES bin REQUIRED)
execute_process(COMMAND "${COMMSDSL2COMMS}" --version OUTPUT_VARIABLE commsdsl2comms_version)
if ("${commsdsl2comms_version}" VERSION_LESS "${MQTT311_MIN_COMMSDSL_VERSION}")
message (FATAL_ERROR "Version of commsdsl2comms is too old, required minimum is v${MQTT311_MIN_COMMSDSL_VERSION}.")
endif ()
set (prot_tmp_dir "${CMAKE_BINARY_DIR}/output.tmp")
add_custom_target(rm_prot_tmp_tgt
COMMAND ${CMAKE_COMMAND} -E remove_directory ${prot_tmp_dir}
)
add_custom_command(
OUTPUT ${prot_tmp_dir}
DEPENDS ${schema_file} ${src_files} rm_prot_tmp_tgt
COMMAND ${COMMSDSL2COMMS} ${warn_as_error} -V ${MQTT311_VERSION}
-o ${prot_tmp_dir} -c ${PROJECT_SOURCE_DIR}/src/protocol
${COMMSDSL2COMMS_EXTRA_ARGS} ${schema_file}
)
add_custom_target(${PROT_OUTPUT_TGT} ALL
COMMAND ${CMAKE_COMMAND}
-DGENERATED="${prot_tmp_dir}" -DOUTPUT="${MQTT311_PROT_OUTPUT_DIR}"
-P "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake"
DEPENDS ${prot_tmp_dir} "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake" ${schema_file})
if (MQTT311_BUILD_PROTOCOL)
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${MQTT311_PROT_OUTPUT_DIR}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${MQTT311_PROT_OUTPUT_DIR}/dummy.txt
)
set (prot_build_dir ${CMAKE_CURRENT_BINARY_DIR}/prot_tgt_build)
ExternalProject_Add(
"prot_tgt"
BUILD_ALWAYS TRUE
DEPENDS ${PROT_OUTPUT_TGT}
SOURCE_DIR ${MQTT311_PROT_OUTPUT_DIR}
BINARY_DIR ${prot_build_dir}
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
-DOPT_REQUIRE_COMMS_LIB=OFF -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
find_package(Doxygen)
if (MQTT311_BUILD_PROT_DOC AND DOXYGEN_FOUND)
ExternalProject_Add_Step(
"prot_tgt"
"doc"
COMMAND ${CMAKE_COMMAND} --build ${prot_build_dir} --target doc_cc_mqtt311
DEPENDEES "build"
DEPENDERS "install"
)
endif ()
endif ()
endif ()
set (combined_prefix_path ${CMAKE_INSTALL_PREFIX} ${CMAKE_PREFIX_PATH})
string (REPLACE ";" "|" combined_prefix_path_str "${combined_prefix_path}")
if (MQTT311_GEN_TEST)
find_program(COMMSDSL2TEST commsdsl2test PATH_SUFFIXES bin REQUIRED)
execute_process(COMMAND "${COMMSDSL2TEST}" --version OUTPUT_VARIABLE commsdsl2test_version)
if ("${commsdsl2test_version}" VERSION_LESS "${MQTT311_MIN_COMMSDSL_VERSION}")
message (FATAL_ERROR "Version of commsdsl2test is too old, required minimum is v${MQTT311_MIN_COMMSDSL_VERSION}.")
endif ()
set (test_tmp_dir "${CMAKE_BINARY_DIR}/output_test.tmp")
add_custom_target(rm_test_tmp_tgt
COMMAND ${CMAKE_COMMAND} -E remove_directory ${test_tmp_dir}
)
add_custom_command(
OUTPUT ${test_tmp_dir}
DEPENDS ${schema_file} ${src_files} rm_test_tmp_tgt
COMMAND ${COMMSDSL2TEST} ${warn_as_error} ${COMMSDSL2TEST_EXTRA_ARGS}
-o ${test_tmp_dir} -c ${PROJECT_SOURCE_DIR}/src/test ${schema_file}
)
add_custom_target("test_output_tgt" ALL
COMMAND ${CMAKE_COMMAND}
-DGENERATED="${test_tmp_dir}" -DOUTPUT="${MQTT311_TEST_OUTPUT_DIR}"
-P "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake"
DEPENDS ${test_tmp_dir} "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake" ${schema_file})
if (MQTT311_BUILD_TEST)
if ((NOT MQTT311_GEN_PROTOCOL) OR (NOT MQTT311_BUILD_PROTOCOL))
message (FATAL_ERROR "MQTT311_GEN_PROTOCOL and MQTT311_BUILD_PROTOCOL are required for MQTT311_BUILD_TEST")
endif ()
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${MQTT311_TEST_OUTPUT_DIR}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${MQTT311_TEST_OUTPUT_DIR}/dummy.txt
)
set (test_build_dir ${CMAKE_CURRENT_BINARY_DIR}/test_tgt_build)
ExternalProject_Add(
"test_tgt"
BUILD_ALWAYS TRUE
DEPENDS "prot_tgt" "test_output_tgt"
SOURCE_DIR ${MQTT311_TEST_OUTPUT_DIR}
BINARY_DIR ${test_build_dir}
LIST_SEPARATOR |
CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_PREFIX_PATH=${combined_prefix_path_str}
-DOPT_USE_CCACHE=${MQTT311_USE_CCACHE}
-DOPT_CCACHE_EXECUTABLE=${MQTT311_CCACHE_EXECUTABLE}
)
endif ()
endif ()
if (MQTT311_GEN_TOOLS)
find_program(COMMSDSL2TOOLS_QT commsdsl2tools_qt PATH_SUFFIXES bin REQUIRED)
execute_process(COMMAND "${COMMSDSL2TOOLS_QT}" --version OUTPUT_VARIABLE commsdsl2tools_qt_version)
if ("${commsdsl2tools_qt_version}" VERSION_LESS "${MQTT311_MIN_COMMSDSL_VERSION}")
message (FATAL_ERROR "Version of commsdsl2tools_qt is too old, required minimum is v${MQTT311_MIN_COMMSDSL_VERSION}.")
endif ()
set (tools_tmp_dir "${CMAKE_BINARY_DIR}/output_tools.tmp")
add_custom_target(rm_tools_tmp_tgt
COMMAND ${CMAKE_COMMAND} -E remove_directory ${tools_tmp_dir}
)
add_custom_command(
OUTPUT ${tools_tmp_dir}
DEPENDS ${schema_file} ${src_files} rm_tools_tmp_tgt
COMMAND ${COMMSDSL2TOOLS_QT} ${warn_as_error} ${COMMSDSL2TOOLS_QT_EXTRA_ARGS}
--protocol "::CC MQTT v3.1.1:MQTT v3.1.1 protocol.:cc.Mqtt311ProtocolPlugin"
-o ${tools_tmp_dir} -c ${PROJECT_SOURCE_DIR}/src/tools ${schema_file}
)
add_custom_target("tools_output_tgt" ALL
COMMAND ${CMAKE_COMMAND}
-DGENERATED="${tools_tmp_dir}" -DOUTPUT="${MQTT311_TOOLS_OUTPUT_DIR}"
-P "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake"
DEPENDS ${tools_tmp_dir} "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake" ${schema_file})
if (MQTT311_BUILD_TOOLS)
if ((NOT MQTT311_GEN_PROTOCOL) OR (NOT MQTT311_BUILD_PROTOCOL))
message (FATAL_ERROR "MQTT311_GEN_PROTOCOL and MQTT311_BUILD_PROTOCOL are required for MQTT311_BUILD_TOOLS")
endif ()
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${MQTT311_TOOLS_OUTPUT_DIR}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${MQTT311_TOOLS_OUTPUT_DIR}/dummy.txt
)
set (tools_build_dir ${CMAKE_CURRENT_BINARY_DIR}/tools_tgt_build)
ExternalProject_Add(
"tools_tgt"
BUILD_ALWAYS TRUE
DEPENDS "prot_tgt" "tools_output_tgt"
SOURCE_DIR ${MQTT311_TOOLS_OUTPUT_DIR}
BINARY_DIR ${tools_build_dir}
LIST_SEPARATOR |
CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_PREFIX_PATH=${combined_prefix_path_str}
-DOPT_QT_MAJOR_VERSION=${MQTT311_TOOLS_QT_VER} -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DOPT_USE_CCACHE=${MQTT311_USE_CCACHE}
-DOPT_CCACHE_EXECUTABLE=${MQTT311_CCACHE_EXECUTABLE}
)
endif ()
endif ()
if (MQTT311_GEN_SWIG)
find_program(COMMSDSL2SWIG commsdsl2swig PATH_SUFFIXES bin REQUIRED)
execute_process(COMMAND "${COMMSDSL2SWIG}" --version OUTPUT_VARIABLE commsdsl2swig_version)
if ("${commsdsl2swig_version}" VERSION_LESS "${MQTT311_MIN_COMMSDSL_VERSION}")
message (FATAL_ERROR "Version of commsdsl2swig is too old, required minimum is v${MQTT311_MIN_COMMSDSL_VERSION}.")
endif ()
set (swig_tmp_dir "${CMAKE_BINARY_DIR}/output_swig.tmp")
add_custom_target(rm_swig_tmp_tgt
COMMAND ${CMAKE_COMMAND} -E remove_directory ${swig_tmp_dir}
)
add_custom_command(
OUTPUT ${swig_tmp_dir}
DEPENDS ${schema_file} ${src_files} rm_swig_tmp_tgt
COMMAND ${COMMSDSL2SWIG} ${warn_as_error} ${COMMSDSL2SWIG_EXTRA_ARGS}
-c ${MQTT311_SWIG_SRC_DIR} -o ${swig_tmp_dir} ${schema_file}
)
add_custom_target("swig_output_tgt" ALL
COMMAND ${CMAKE_COMMAND}
-DGENERATED="${swig_tmp_dir}" -DOUTPUT="${MQTT311_SWIG_OUTPUT_DIR}"
-P "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake"
DEPENDS ${swig_tmp_dir} "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake" ${schema_file})
if (MQTT311_BUILD_SWIG)
if ((NOT MQTT311_GEN_PROTOCOL) OR (NOT MQTT311_BUILD_PROTOCOL))
message (FATAL_ERROR "MQTT311_GEN_PROTOCOL and MQTT311_BUILD_PROTOCOL are required for MQTT311_BUILD_SWIG")
endif ()
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${MQTT311_SWIG_OUTPUT_DIR}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${MQTT311_SWIG_OUTPUT_DIR}/dummy.txt
)
string (REPLACE ";" "|" combined_languages_str "${MQTT311_SWIG_LANGUAGES}")
set (swig_build_dir ${CMAKE_CURRENT_BINARY_DIR}/swig_tgt_build)
ExternalProject_Add(
"swig_tgt"
BUILD_ALWAYS TRUE
DEPENDS "prot_tgt" "swig_output_tgt"
SOURCE_DIR ${MQTT311_SWIG_OUTPUT_DIR}
BINARY_DIR ${swig_build_dir}
LIST_SEPARATOR |
CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_PREFIX_PATH=${combined_prefix_path_str}
-DOPT_SWIG_LANGUAGES=${combined_languages_str}
-DOPT_USE_CCACHE=${MQTT311_USE_CCACHE}
-DOPT_CCACHE_EXECUTABLE=${MQTT311_CCACHE_EXECUTABLE}
INSTALL_COMMAND
${CMAKE_COMMAND} -E echo "Skipping install"
)
endif ()
endif ()
if (MQTT311_GEN_EMSCRIPTEN)
find_program(COMMSDSL2EMSCRIPTEN commsdsl2emscripten PATH_SUFFIXES bin REQUIRED)
find_program(EMCMAKE_EXECUTABLE emcmake REQUIRED)
execute_process(COMMAND "${COMMSDSL2EMSCRIPTEN}" --version OUTPUT_VARIABLE commsdsl2emscripten_version)
if ("${commsdsl2emscripten_version}" VERSION_LESS "${MQTT311_MIN_COMMSDSL_VERSION}")
message (FATAL_ERROR "Version of commsdsl2emscripten is too old, required minimum is v${MQTT311_MIN_COMMSDSL_VERSION}.")
endif ()
set (emscripten_tmp_dir "${CMAKE_BINARY_DIR}/output_emscripten.tmp")
add_custom_target(rm_emscripten_tmp_tgt
COMMAND ${CMAKE_COMMAND} -E remove_directory ${emscripten_tmp_dir}
)
add_custom_command(
OUTPUT ${emscripten_tmp_dir}
DEPENDS ${schema_file} ${src_files} rm_emscripten_tmp_tgt
COMMAND ${COMMSDSL2EMSCRIPTEN} ${warn_as_error} ${COMMSDSL2EMSCRIPTEN_EXTRA_ARGS}
-o ${emscripten_tmp_dir} -c ${PROJECT_SOURCE_DIR}/src/emscripten ${schema_file}
)
add_custom_target("emscripten_output_tgt" ALL
COMMAND ${CMAKE_COMMAND}
-DGENERATED="${emscripten_tmp_dir}" -DOUTPUT="${MQTT311_EMSCRIPTEN_OUTPUT_DIR}"
-P "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake"
DEPENDS ${emscripten_tmp_dir} "${CMAKE_CURRENT_LIST_DIR}/CopyGenerated.cmake" ${schema_file})
if (MQTT311_BUILD_EMSCRIPTEN)
if ((NOT MQTT311_GEN_PROTOCOL) OR (NOT MQTT311_BUILD_PROTOCOL))
message (FATAL_ERROR "MQTT311_GEN_PROTOCOL and MQTT311_BUILD_PROTOCOL are required for MQTT311_BUILD_EMSCRIPTEN")
endif ()
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${MQTT311_EMSCRIPTEN_OUTPUT_DIR}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${MQTT311_EMSCRIPTEN_OUTPUT_DIR}/dummy.txt
)
find_package(LibComms REQUIRED)
get_target_property(comms_include_dirs cc::comms INTERFACE_INCLUDE_DIRECTORIES)
set (prot_include_dir "${CMAKE_INSTALL_PREFIX}/include")
set (extra_includes_path ${prot_include_dir} ${comms_include_dirs})
string (REPLACE ";" "|" extra_includes_path_str "${extra_includes_path}")
set (emscripten_build_dir ${CMAKE_CURRENT_BINARY_DIR}/emscripten_tgt_build)
ExternalProject_Add(
"emscripten_tgt"
BUILD_ALWAYS TRUE
DEPENDS "prot_tgt" "emscripten_output_tgt"
SOURCE_DIR ${MQTT311_EMSCRIPTEN_OUTPUT_DIR}
BINARY_DIR ${emscripten_build_dir}
CMAKE_COMMAND ${EMCMAKE_EXECUTABLE} ${CMAKE_COMMAND}
LIST_SEPARATOR |
CMAKE_ARGS
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DOPT_MODULARIZE=ON
-DOPT_EXTRA_INCLUDE_DIRS=${extra_includes_path_str}
-DOPT_USE_CCACHE=${MQTT311_USE_CCACHE}
-DOPT_CCACHE_EXECUTABLE=${MQTT311_CCACHE_EXECUTABLE}
)
endif ()
endif ()