Skip to content

Link library whole archive doesn't work with CMake Ninja generator #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ahayzen opened this issue Feb 12, 2023 · 6 comments
Closed

Link library whole archive doesn't work with CMake Ninja generator #442

ahayzen opened this issue Feb 12, 2023 · 6 comments
Assignees
Labels
🪲 bug Something isn't working
Milestone

Comments

@ahayzen
Copy link

ahayzen commented Feb 12, 2023

If you use -G Ninja then it doesn't understand the WHOLE_ARCHIVE workaround ? Is there a way to make this work with Ninja too (seems some use --whole-archive?) or do we need to look for an alternate route to WHOLE_ARCHIVE ?

[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,qml-features-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,qml-minimal-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,cxx-qt-demo-threading-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,qml-features-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,qml-minimal-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,cxx-qt-demo-threading-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,qml-features-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,qml-minimal-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
[cmake] 
[cmake] CMake Error:
[cmake]   Error evaluating generator expression:
[cmake] 
[cmake]     $<LINK_LIBRARY:WHOLE_ARCHIVE,cxx-qt-demo-threading-static>
[cmake] 
[cmake]   Expression did not evaluate to a known generator expression
[cmake] 
@Be-ing
Copy link
Contributor

Be-ing commented Feb 12, 2023

I use the Ninja generator. What version of CMake are you using? The LINK_LIBRARY generator expression was added in CMake 3.24.

@ahayzen-kdab
Copy link
Collaborator

This is with CMake from Ubuntu 22.04, curious that CI doesn't fail, i guess github are installing a new CMake from somewhere.

$ cmake --version
cmake version 3.22.1

So it looks like we either need to

  • Use target_link_options(${APP_NAME}_lib INTERFACE "SHELL:-Wl,--whole-archive $<TARGET_FILE:${CRATE}-static> -Wl,--no-whole-archive") instead of "$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>" as described in WASM Example #414
  • Bump the CMake minimum version to 3.24 in the CMakeLists.txt

Note that the Qt online installer has 3.24 so developers can use that to retrieve the newer version.

@ahayzen-kdab ahayzen-kdab added the 🪲 bug Something isn't working label Feb 13, 2023
@ahayzen-kdab ahayzen-kdab added this to the 0.5 milestone Feb 13, 2023
@ahayzen-kdab
Copy link
Collaborator

Although as detailed in the wasm issue a newer CMake doesn't work with the wasm target only x86_64. Wonder if this is due to the platforms that the CMake docs say are supported. Also note that it doesn't list MinGW ?

Are there any other alternate ways of solving this? 🤔

@Be-ing
Copy link
Contributor

Be-ing commented Feb 13, 2023

Use target_link_options(${APP_NAME}_lib INTERFACE "SHELL:-Wl,--whole-archive $&lt;TARGET_FILE:${CRATE}-static> -Wl,--no-whole-archive")

That would require platform-specific code for Unix and Windows. :/

Bump the CMake minimum version to 3.24 in the CMakeLists.txt

I'd prefer to do this.

Although as detailed in the wasm issue a newer CMake doesn't work with the wasm target

Yeah, this seems to be a limitation in CMake currently. But it seems the platform linker does support it, just not CMake.

@ahayzen-kdab
Copy link
Collaborator

Use target_link_options(${APP_NAME}_lib INTERFACE "SHELL:-Wl,--whole-archive Unable to render expression.

    $&lt;TARGET_FILE:${CRATE}-static> -Wl,--no-whole-archive")

That would require platform-specific code for Unix and Windows. :/

Bump the CMake minimum version to 3.24 in the CMakeLists.txt

I'd prefer to do this.

Let's do this for now.

Although as detailed in the wasm issue a newer CMake doesn't work with the wasm target

Yeah, this seems to be a limitation in CMake currently. But it seems the platform linker does support it, just not CMake.

And can we if (wasm) then use manual linkers else WHOLE_ARCHIVE thing when/if we add wasm support until upstream CMake fixes it ? Eg can we determine that we are building a CMake target for wasm later ?

@ahayzen-kdab
Copy link
Collaborator

Fixed in #445 wasm discussions can be in the other issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants