diff --git a/.circleci/config.yml b/.circleci/config.yml index 92d3d1e352277..c0536063facaa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -799,6 +799,7 @@ jobs: EMTEST_SKIP_NODE_CANARY: "1" EMTEST_SKIP_RUST: "1" EMTEST_SKIP_WASM64: "1" + EMTEST_SKIP_NEW_CMAKE: "1" steps: - install-rust - run: apt-get install -q -y ninja-build scons ccache diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index 0922fb856bcc3..0036d4c564c0b 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -279,6 +279,10 @@ set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") +# Enable $ for CMake 3.24+ +set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "-Wl,--whole-archive" "" "-Wl,--no-whole-archive") +set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED True) + # Set a global EMSCRIPTEN variable that can be used in client CMakeLists.txt to # detect when building using Emscripten. set(EMSCRIPTEN 1 CACHE INTERNAL "If true, we are targeting Emscripten output.") diff --git a/test/cmake/whole_archive/CMakeLists.txt b/test/cmake/whole_archive/CMakeLists.txt new file mode 100644 index 0000000000000..92b07b985eb66 --- /dev/null +++ b/test/cmake/whole_archive/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.24) + +project(whole) + +add_library(whole_lib STATIC lib.c) +add_executable(whole main.c) +target_link_libraries(whole $) diff --git a/test/cmake/whole_archive/lib.c b/test/cmake/whole_archive/lib.c new file mode 100644 index 0000000000000..f68845002a080 --- /dev/null +++ b/test/cmake/whole_archive/lib.c @@ -0,0 +1,5 @@ +#include + +__attribute__((constructor)) void init(void) { + printf("init\n"); +} diff --git a/test/cmake/whole_archive/main.c b/test/cmake/whole_archive/main.c new file mode 100644 index 0000000000000..76929edbaa08e --- /dev/null +++ b/test/cmake/whole_archive/main.c @@ -0,0 +1,5 @@ +#include + +int main() { + printf("main\n"); +} diff --git a/test/cmake/whole_archive/out.txt b/test/cmake/whole_archive/out.txt new file mode 100644 index 0000000000000..9ac7e01535b94 --- /dev/null +++ b/test/cmake/whole_archive/out.txt @@ -0,0 +1,2 @@ +init +main diff --git a/test/test_other.py b/test/test_other.py index 24a77aef0ccc6..d7debd9c29ae9 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -913,14 +913,18 @@ def test_emstrip(self): # would take 10 minutes+ to finish (CMake feature detection is slow), so # combine multiple features into one to try to cover as much as possible # while still keeping this test in sensible time limit. - 'js': ('target_js', 'test_cmake.js', ['-DCMAKE_BUILD_TYPE=Debug']), - 'html': ('target_html', 'hello_world_gles.html', ['-DCMAKE_BUILD_TYPE=Release']), - 'library': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=MinSizeRel']), - 'static_cpp': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DCPP_LIBRARY_TYPE=STATIC']), - 'stdproperty': ('stdproperty', 'helloworld.js', []), - 'post_build': ('post_build', 'hello.js', []), + 'js': ('target_js', 'test_cmake.js', ['-DCMAKE_BUILD_TYPE=Debug']), + 'html': ('target_html', 'hello_world_gles.html', ['-DCMAKE_BUILD_TYPE=Release']), + 'library': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=MinSizeRel']), + 'static_cpp': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DCPP_LIBRARY_TYPE=STATIC']), + 'whole_archive': ('whole_archive', 'whole.js', []), + 'stdproperty': ('stdproperty', 'helloworld.js', []), + 'post_build': ('post_build', 'hello.js', []), }) def test_cmake(self, test_dir, output_file, cmake_args): + if test_dir == 'whole_archive' and 'EMTEST_SKIP_NEW_CMAKE' in os.environ: + self.skipTest('EMTEST_SKIP_NEW_CMAKE set') + # Test all supported generators. if WINDOWS: generators = ['MinGW Makefiles', 'NMake Makefiles']