mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Emscripten: Enable de-duplication of libraries for CMP0156 with LLD
LLD automatically resolves newly encountered symbols using object files previously encountered. Also, the Emscripten compiler driver invokes the LLD linker with `--whole-archive ... --no-whole-archive` around all the libraries. Therefore we should not repeat any. Issue: #27232 Suggested-by: Marc Chevrier <marc.chevrier@gmail.com>
This commit is contained in:
@@ -8,4 +8,7 @@ macro(__emscripten_linker_lld lang)
|
||||
set(CMAKE_${lang}_LINK_LIBRARY_USING_WHOLE_ARCHIVE "-Wl,--whole-archive" "<LINK_ITEM>" "-Wl,--no-whole-archive")
|
||||
set(CMAKE_${lang}_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
|
||||
set(CMAKE_${lang}_LINK_LIBRARY_WHOLE_ARCHIVE_ATTRIBUTES LIBRARY_TYPE=STATIC DEDUPLICATION=YES OVERRIDE=DEFAULT)
|
||||
|
||||
set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
|
||||
set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
|
||||
endmacro()
|
||||
|
||||
10
Tests/RunCMake/Emscripten/C-lib-circular.cmake
Normal file
10
Tests/RunCMake/Emscripten/C-lib-circular.cmake
Normal file
@@ -0,0 +1,10 @@
|
||||
enable_language(C)
|
||||
|
||||
add_library(circular1 STATIC circular1.c)
|
||||
add_library(circular2 STATIC circular2.c)
|
||||
|
||||
target_link_libraries(circular1 PRIVATE circular2)
|
||||
target_link_libraries(circular2 PRIVATE circular1)
|
||||
|
||||
add_executable(main_circular main_circular.c)
|
||||
target_link_libraries(main_circular PRIVATE circular1)
|
||||
@@ -63,6 +63,11 @@ foreach(_emscripten_toolchain IN LISTS _emscripten_toolchains)
|
||||
-DCMAKE_C_COMPILER=${c_comp}
|
||||
)
|
||||
|
||||
run_toolchain(C-lib-circular
|
||||
-DCMAKE_SYSTEM_NAME=Emscripten
|
||||
-DCMAKE_C_COMPILER=${c_comp}
|
||||
)
|
||||
|
||||
run_cmake_with_options(C-WHOLE_ARCHIVE
|
||||
-DCMAKE_SYSTEM_NAME=Emscripten
|
||||
-DCMAKE_C_COMPILER=${c_comp}
|
||||
|
||||
Reference in New Issue
Block a user