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

[SDL2] CMake error in VSCode #38812

Closed
Hedwig7s opened this issue May 18, 2024 · 4 comments
Closed

[SDL2] CMake error in VSCode #38812

Hedwig7s opened this issue May 18, 2024 · 4 comments
Assignees
Labels
requires:repro The issue is not currently repro-able

Comments

@Hedwig7s
Copy link

Operating system

Linux Mint 21.3

Compiler

No response

Steps to reproduce the behavior

Set up a project according to this tutorial: https://learn.microsoft.com/en-us/vcpkg/get_started/get-started-vscode

Add SDL2 to the CMakeLists.txt
Example:
cmake_minimum_required(VERSION 3.0.0)
project(Project LANGUAGES C)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

add_executable(Project main.c)
target_link_libraries(Project ${SDL2_LIBRARIES})

Attempt to build (F7)

Failure logs

[build] CMake Error at build/vcpkg_installed/x64-linux/share/sdl2/SDL2staticTargets.cmake:104 (message):
[build]   The imported target "SDL2::SDL2-static" references the file
[build] 
[build]      "/path/to/project/build/vcpkg_installed/debug/lib/libSDL2d.a"
[build] 
[build]   but this file does not exist.  Possible reasons include:
[build] 
[build]   * The file was deleted, renamed, or moved to another location.
[build] 
[build]   * An install or uninstall procedure did not complete successfully.
[build] 
[build]   * The installation package was faulty and contained
[build] 
[build]      "/path/to/project/build/vcpkg_installed/x64-linux/share/sdl2/SDL2staticTargets.cmake"
[build] 
[build]   but not all the files it references.
[build] 
[build] Call Stack (most recent call first):
[build]   build/vcpkg_installed/x64-linux/share/sdl2/SDL2Config.cmake:56 (include)
[build]   /usr/lib/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
[build]   CMakeLists.txt:5 (find_package)
[build] 
[build] 
[build] ninja: error: rebuilding 'build.ninja': subcommand failed
[build] -- Configuring incomplete, errors occurred!
[build] See also "/path/to/project/build/CMakeFiles/CMakeOutput.log".
[build] FAILED: build.ninja 
[build] /usr/bin/cmake --regenerate-during-build -S/path/to/project -B/path/to/project/build
[proc] The command: /usr/bin/cmake --build /path/to/project/build --parallel 10 exited with code: 1
[driver] Build completed: 00:00:01.355
[build] Build finished with exit code 1

Additional context

The issue seems to come from line 63 of SDL2staticTargets.cmake
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) (aka the third time this is run)
After this is run, it removes the triplet from the path breaking it (e.g. "build/vcpkg_installed/x64-linux" becomes "build/vcpkg_installed")

@Hedwig7s Hedwig7s added the category:port-bug The issue is with a library, which is something the port should already support label May 18, 2024
@Hedwig7s
Copy link
Author

Note: This issue also seems to apply to SDL2mainTargets

@WangWeiLin-MV
Copy link
Contributor

Local tests pass with the given usage:

find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(main
    PRIVATE
    $<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
    $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
)

Could you try the usage provided by the port?

@dg0yt
Copy link
Contributor

dg0yt commented May 20, 2024

Do not use CMake 3.29.1.
Reinstall all packages which were built with that version.

@Hedwig7s
Copy link
Author

Somehow fixed it not sure how
Anyone finding this later try moving your vcpkg directory, installing libsdl2-dev (and uninstalling after) and/or adding vcpkg/installed/x64-linux to your CMAKE_PREFIX_PATH if not using the manifest

@WangWeiLin-MV WangWeiLin-MV added requires:repro The issue is not currently repro-able and removed category:port-bug The issue is with a library, which is something the port should already support labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:repro The issue is not currently repro-able
Projects
None yet
Development

No branches or pull requests

3 participants