Emscripten: Drop hard-coded -fPIC flag

In commit 96d9b94a98 (Emscripten: Add platform modules, 2025-05-16,
v4.2.0-rc1~607^2~3) this flag was added as part of an attempt to support
shared libraries without requiring projects to set much themselves. That
attempt was reverted by commit d361bf365e (Emscripten: Drop hard-coded
-sMAIN_MODULE and -sSIDE_MODULE flags, 2025-09-18, v4.2.0-rc1~146^2).
Also avoid hard-coding `-fPIC`.  `POSITION_INDEPENDENT_CODE` is already
enabled for shared library targets.  Projects can enable it themselves
where `-fPIC` is needed outside of shared libraries.

Fixes: #27424
Issue: #27240
This commit is contained in:
Brad King
2025-11-25 10:32:04 -05:00
parent 5a3f22145f
commit 86574083a8
3 changed files with 3 additions and 2 deletions

View File

@@ -16,6 +16,4 @@ macro(__emscripten_clang lang)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
set(CMAKE_${lang}_COMPILE_OBJECT
"<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -fPIC")
endmacro()

View File

@@ -2,6 +2,7 @@
enable_language(C)
add_library(base STATIC base.c unref.c)
set_property(TARGET base PROPERTY POSITION_INDEPENDENT_CODE 1)
target_compile_definitions(base PUBLIC STATIC_BASE)
add_library(lib SHARED lib.c)
@@ -9,6 +10,7 @@ target_link_libraries(lib PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,base>")
target_link_options(lib PRIVATE -sSIDE_MODULE)
add_executable(main main.c)
set_property(TARGET main PROPERTY POSITION_INDEPENDENT_CODE 1)
target_link_libraries(main PRIVATE lib)
target_link_options(main PRIVATE -sMAIN_MODULE)

View File

@@ -3,6 +3,7 @@ add_library(emscripten-test-lib SHARED libmod.c)
target_link_options(emscripten-test-lib PRIVATE -sSIDE_MODULE)
add_executable(exec-lib-c module.c)
set_property(TARGET exec-lib-c PROPERTY POSITION_INDEPENDENT_CODE 1)
target_compile_definitions(exec-lib-c PRIVATE __USE_LIBFUN)
target_link_libraries(exec-lib-c PRIVATE emscripten-test-lib)
target_link_options(exec-lib-c PRIVATE -sMAIN_MODULE)