Skip to content
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

CMake issues when linking to SDL3::SDL3-shared #12057

Closed
chrismile opened this issue Jan 22, 2025 · 5 comments
Closed

CMake issues when linking to SDL3::SDL3-shared #12057

chrismile opened this issue Jan 22, 2025 · 5 comments
Assignees
Milestone

Comments

@chrismile
Copy link

First of all, congratulations on the release of SDL 3.2.0!

I tried linking my application to SDL3::SDL3-shared via CMake, but encountered some weird behavior on Ubuntu 22.04.

When building SDL3 as follows...

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/christoph/build/SDL-3.2.0
make -j 12
make install

... everything works as it should. However, when I instead use the following commands to build SDL3:

cmake -S . -B build
cmake --build build --config Release
cmake --install build --config Release --prefix /home/christoph/build/SDL-3.2.0

... then I encounter the following error when trying to link to SDL3 in my application:

CMake Error in CMakeLists.txt:
  IMPORTED_LOCATION not set for imported target "SDL3::SDL3-shared"

Please find the output of diff for the two generated lib/cmake/SDL3/SDL3sharedTargets-release.cmake files attached. While this is not a huge issue for me (after all, I can just use the former command for building SDL), it might still an issue that should eventually be fixed.

Some system information:

  • Ubuntu 22.04
  • CMake version: 3.31.3
@slouken slouken added this to the 3.2.2 milestone Jan 22, 2025
@madebr
Copy link
Contributor

madebr commented Jan 23, 2025

I think you're seeing a CMake quirk. I'd argue it is even a (small) CMake bug.

Let's dissect your second set of commands

cmake -S . -B build

This will configure SDL with the default build type. Because you have not configured one (using -DCMAKE_BUILD_TYPE=... and SDL is the root project, RelWithDebInfo is selected.

cmake --build build --config Release

This will build SDL. Because you are building on Linux with a CMake generator that does not support multiple configurations (Visual Studio and Ninja Multi-Config support this), --config Release is ignored. Building with --config NonsenseConfiguration will succeed also. You can drop it.

cmake --install build --config Release --prefix /home/christoph/build/SDL-3.2.0

This will install SDL to the prefix folder with Release configuration.
The only configuration-dependent file that SDL installs are <prefix>/lib/cmake/SDL3/SDL3{shared,static,test,headers}Targets-<configuration>.cmake.
--config Release should be ignored for the same reasons as --build, but apparantly it is not.
It will fail to install <prefix>/lib/cmake/SDL3/SDL3sharedTargets-release.cmake.

CMake should ignore --config Release here, as it does with --build.

Using --config RelWithDebInfo in your install command works.
Simpler is just leaving out the --config <xxx>.

@slouken
Copy link
Collaborator

slouken commented Jan 23, 2025

(but you'll need --config on Windows!)

@slouken slouken closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2025
@madebr
Copy link
Contributor

madebr commented Jan 23, 2025

Yes! You need it with Multi-Config generators: Visual Studio on Windows, or Ninja Multi-Config on all platforms.

@madebr
Copy link
Contributor

madebr commented Jan 23, 2025

I've created an issue on the CMake bug tracker here. Perhaps this is expected behavior.

@chrismile
Copy link
Author

@madebr Thanks for the clarification (and for opening the CMake issue)! I agree with your statement in the CMake issue report that the most sensible solution would be that CMake emits an error. As it stands, a quite basic chain of commands that is perfectly valid for some generators (like VS) will generate broken installations for other generators without even giving the user any information that something possibly went wrong.

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

No branches or pull requests

3 participants