--js-library and CMake

797 views
Skip to first unread message

Thaddaeus Frogley

unread,
Sep 6, 2013, 11:38:50 AM9/6/13
to emscripte...@googlegroups.com
Hi,

A the moment, to include javascript into a application compiled with emscripten, you pass it in using the --js-library command line for the link phase.

In CMake you specify libraries to link against using:

target_link_libraries(${TARGET} parallelogramlib.js)

This doesn't work with javascript source libraries.

To get this to work with CMake temporarily I've done this instead:

set_target_properties (${TARGET} PROPERTIES LINK_FLAGS "--js-library parallelogramlib.js")

The problem with that is that the javascript library isn't recognized as dependency.

What is the correct way to do this?

Thanks

Thad

Thaddaeus Frogley

Senior Game Engine Developer

Jagex Games Studio

 

 


Floh

unread,
Sep 7, 2013, 8:38:57 AM9/7/13
to emscripte...@googlegroups.com
Not sure whether there's a better way, but that's the way I'm doing it as well. I'm only using target_link_libraries() for actual static link libraries generated with emar. For JS files added with --js-library and --pre-js I wrote a couple of cmake custom macros, which collect the files and build a single set_target_properties(... LINK_FLAGS ...) statement for each target.

However, simply being able to use .js files everywhere where a static link library would be expected would be nice as well...

Cheers,
-Floh.

Jukka Jylänki

unread,
Sep 7, 2013, 10:33:33 AM9/7/13
to emscripte...@googlegroups.com
I think the approach 'target_link_libraries(${TARGET} parallelogramlib.js)' will never be good, since there are multiple ways to link a .js to the project (--pre-js, --post-js and --js-library). Therefore the best way is probably to advocate the use of 'set_target_properties (${TARGET} PROPERTIES LINK_FLAGS "--js-library parallelogramlib.js")' as the correct approach and document that.

The issue that cmake doesn't detect the dependency might be correctable simply by adding an ADD_DEPENDENCIES instruction, see http://www.cmake.org/pipermail/cmake/2010-March/035621.html and http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:add_dependencies . In that case, I think we could provide a wrapper that both adds a link flag and does the dependency in the emscripten toolchain file, something like

em_link_js_library(target ${list_of_js_files})
em_link_pre_js(target ${list_of_js_files})
em_link_post_js(target ${list_of_js_files})

to ease the process. What do you think?

Jukka 


2013/9/7 Floh <flo...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Floh

unread,
Sep 8, 2013, 7:46:00 AM9/8/13
to emscripte...@googlegroups.com
Sounds good :)


2013/9/7 Floh <flo...@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Thaddaeus Frogley

unread,
Sep 9, 2013, 4:27:22 AM9/9/13
to emscripte...@googlegroups.com
I think we could provide a wrapper that both adds a link flag and does the dependency in the emscripten toolchain file, something like

em_link_js_library(target ${list_of_js_files})
em_link_pre_js(target ${list_of_js_files})
em_link_post_js(target ${list_of_js_files})

to ease the process. What do you think?

Jukka 

That would be perfect!

Thad

Jukka Jylänki

unread,
Sep 9, 2013, 3:15:50 PM9/9/13
to emscripte...@googlegroups.com
I implemented this in commit https://github.com/juj/emscripten/commit/365ac67e3242be933a2254ed1b69751a510aaa9e . It is pending merge to upstream. The functionality ended up being a bit more messy than I anticipated, since CMake lacks support for adding dependencies to targets from files directly.


2013/9/9 Thaddaeus Frogley <codemo...@gmail.com>
Reply all
Reply to author
Forward
0 new messages