Skip to content

Conversation

@eagleoflqj
Copy link
Contributor

Related: https://discourse.cmake.org/t/error-when-crosscompiling-with-whole-archive-target-link/9394

whole-archive support needs to be explicitly declared in toolchain file, see cmake official GNU.

Test:

CMakeLists.txt

cmake_minimum_required(VERSION 3.24)

project(whole)

add_library(whole_lib STATIC lib.cpp)
add_executable(whole main.cpp)
target_link_libraries(whole $<LINK_LIBRARY:WHOLE_ARCHIVE,whole_lib>)

lib.cpp

#include <iostream>

static void init(void) __attribute__((constructor));
static void init(void) {
    std::cout << "init" << std::endl;
}

main.cpp

#include <iostream>

int main() {
    std::cout << "main" << std::endl;
}

With latest emsdk, emcmake cmake -B build complains

configure: cmake -B build -DCMAKE_TOOLCHAIN_FILE=/path/to/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/Users/liumeo/github/emsdk/node/20.18.0_64bit/bin/node
-- Configuring done (2.2s)
CMake Error at CMakeLists.txt:6 (add_executable):
  Feature 'WHOLE_ARCHIVE', specified through generator-expression
  '$<LINK_LIBRARY>' to link target 'whole', is not supported for the 'CXX'
  link language.

After overriding emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake, it passes, and cmake --build build passes, node build/whole.js outputs

init
main

as expected.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, but can you add a new test to test_cmake in test_other.py that uses this feature?

@eagleoflqj eagleoflqj requested a review from sbc100 November 23, 2024 13:50
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % nits

@eagleoflqj eagleoflqj requested a review from sbc100 November 28, 2024 05:09
@sbc100 sbc100 merged commit b88d479 into emscripten-core:main Dec 2, 2024
28 checks passed
@eagleoflqj eagleoflqj deleted the whole-archive branch December 2, 2024 23:43
@dschuff
Copy link
Member

dschuff commented Dec 3, 2024

@sbc100
Copy link
Collaborator

sbc100 commented Dec 3, 2024

Yes we need to add EMTEST_SKIP_NEW_CMAKE there too.

@dschuff
Copy link
Member

dschuff commented Dec 3, 2024

I guess the other option would be to just update the install of CMake we have on those builders.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 3, 2024

I guess the other option would be to just update the install of CMake we have on those builders.

Maybe .. although then we loose coverage of older cmake versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants