1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Emscripten: Allow overriding -sMAIN_MODULE and -sSIDE_MODULE linker flags

Place the flag early on executable link lines so that projects can
override it, e.g., with `-sMAIN_MODULE=2` or `-sMAIN_MODULE=0` via
`target_link_options`.

The `-sSIDE_MODULE` flag already appears early enough on shared library
link lines.

Issue: #27232
This commit is contained in:
Brad King
2025-09-17 19:54:40 -04:00
parent 526c6ff6d2
commit 7f3f6d1ec6

View File

@@ -15,9 +15,10 @@ macro(__emscripten_clang lang)
get_property(_TARGET_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
if(_TARGET_SUPPORTS_SHARED_LIBS)
# Emscripten requires '-sMAIN_MODULE' and '-sSIDE_MODULE' to distinguish
# linking executables from linking shared libraries.
# linking executables from linking shared libraries. Place them early
# so that project-specified link flags can override them.
set(CMAKE_${lang}_LINK_EXECUTABLE
"<CMAKE_${lang}_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -sMAIN_MODULE")
"<CMAKE_${lang}_COMPILER> -sMAIN_MODULE <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-sSIDE_MODULE")
else()
# Emscripten provides a combined toolchain file and platform module that