@@ -306,50 +306,21 @@ function(em_validate_asmjs_after_build target)
306
306
message (WARNING "em_validate_asmjs_after_build no longer exists" )
307
307
endfunction ()
308
308
309
- # A global counter to guarantee unique names for js library files.
310
- set (link_js_counter 1 )
311
-
312
309
# Internal function: Do not call from user CMakeLists.txt files. Use one of
313
310
# em_link_js_library()/em_link_pre_js()/em_link_post_js() instead.
314
- function (em_add_tracked_link_flag target flagname )
315
-
311
+ function (em_add_link_deps target flagname )
316
312
# User can input list of JS files either as a single list, or as variable
317
313
# arguments to this function, so iterate over varargs, and treat each item in
318
314
# varargs as a list itself, to support both syntax forms.
319
315
foreach (jsFileList ${ARGN} )
320
316
foreach (jsfile ${jsFileList} )
321
- # If the user edits the JS file, we want to relink the emscripten
322
- # application, but unfortunately it is not possible to make a link step
323
- # depend directly on a source file. Instead, we must make a dummy no-op
324
- # build target on that source file, and make the project depend on
325
- # that target.
326
-
327
- # Sanitate the source .js filename to a good symbol name to use as a dummy
328
- # filename.
329
- get_filename_component (jsname "${jsfile} " NAME )
330
- string (REGEX REPLACE "[/:\\\\ .\ ]" "_" dummy_js_target ${jsname} )
331
- set (dummy_lib_name ${target} _${link_js_counter}_${dummy_js_target} )
332
- set (dummy_c_name "${CMAKE_BINARY_DIR} /${dummy_js_target} _tracker.c" )
333
-
334
- # Create a new static library target that with a single dummy .c file.
335
- add_library (${dummy_lib_name} STATIC ${dummy_c_name} )
336
- # Make the dummy .c file depend on the .js file we are linking, so that if
337
- # the .js file is edited, the dummy .c file, and hence the static library
338
- # will be rebuild (no-op). This causes the main application to be
339
- # relinked, which is what we want. This approach was recommended by
340
- # http://www.cmake.org/pipermail/cmake/2010-May/037206.html
341
- add_custom_command (OUTPUT ${dummy_c_name} COMMAND ${CMAKE_COMMAND} -E touch ${dummy_c_name} DEPENDS ${jsfile} )
342
- target_link_libraries (${target} ${dummy_lib_name} )
343
-
344
- # Link the js-library to the target
345
- # When a linked library starts with a "-" cmake will just add it to the
346
- # linker command line as it is. The advantage of doing it this way is
347
- # that the js-library will also be automatically linked to targets that
348
- # depend on this target.
349
- get_filename_component (js_file_absolute_path "${jsfile} " ABSOLUTE )
350
- target_link_libraries (${target} "${flagname} \" ${js_file_absolute_path} \" " )
351
-
352
- math (EXPR link_js_counter "${link_js_counter} + 1" )
317
+ get_target_property (linkdeps ${target} LINK_DEPENDS )
318
+ if (linkdeps STREQUAL "linkdeps-NOTFOUND" )
319
+ set (linkdeps "" )
320
+ endif ()
321
+ get_filename_component (jsfile_abs "${jsfile} " ABSOLUTE )
322
+ set_target_properties (${target} PROPERTIES LINK_DEPENDS "${linkdeps} ;${jsfile_abs} " )
323
+ target_link_libraries (${target} "${flagname} \" ${jsfile_abs} \" " )
353
324
endforeach ()
354
325
endforeach ()
355
326
endfunction ()
@@ -361,21 +332,21 @@ endfunction()
361
332
# between the linked .js files and the main project, so that editing the .js
362
333
# file will cause the target project to be relinked.
363
334
function (em_link_js_library target )
364
- em_add_tracked_link_flag (${target} "--js-library" ${ARGN} )
335
+ em_add_link_deps (${target} "--js-library" ${ARGN} )
365
336
endfunction ()
366
337
367
338
# This function is identical to em_link_js_library(), except the .js files will
368
339
# be added with '--pre-js file.js' command line flag, which is generally used to
369
340
# add some preamble .js code to a generated output file.
370
341
function (em_link_pre_js target )
371
- em_add_tracked_link_flag (${target} "--pre-js" ${ARGN} )
342
+ em_add_link_deps (${target} "--pre-js" ${ARGN} )
372
343
endfunction ()
373
344
374
345
# This function is identical to em_link_js_library(), except the .js files will
375
346
# be added with '--post-js file.js' command line flag, which is generally used
376
347
# to add some postamble .js code to a generated output file.
377
348
function (em_link_post_js target )
378
- em_add_tracked_link_flag (${target} "--post-js" ${ARGN} )
349
+ em_add_link_deps (${target} "--post-js" ${ARGN} )
379
350
endfunction ()
380
351
381
352
# Experimental support for targeting generation of Visual Studio project files
0 commit comments