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

README-cmake.md instructions on library copying are incorrect #12294

Open
nightmareci opened this issue Feb 14, 2025 · 0 comments
Open

README-cmake.md instructions on library copying are incorrect #12294

nightmareci opened this issue Feb 14, 2025 · 0 comments
Assignees
Milestone

Comments

@nightmareci
Copy link
Contributor

The section in README-cmake.md on library copying isn't strictly correct, because that custom command is dependent on the executable, not the libraries being copied. In my own work on the SDL code, I've run into situations where the executable isn't rebuilt, its POST_BUILD event not triggered, but the libraries were rebuilt, so the custom command ended up not getting rerun. For those not working on the SDL code, a situation where the executable-dependent custom command wouldn't run would be after an update of SDL, with the executable's code unchanged, the user running a build operation at that point. Additionally, using CMAKE_LIBRARY_OUTPUT_DIRECTORY for SDL provided by a package manager, acquired in CMake via find_package(), won't work at all, since the library isn't built as part of your project in such a situation.

This is the correct way to have the copying command dependent on the library. This command does always rerun every build, but using copy_if_different at least optimizes the copying to only actually copy the library when it changes on-disk, it does a file timestamp check to only copy when the timestamp changes. The dependency on the library results in this copy command only running after the library is built:

if(WIN32)
    add_custom_target(Copy-SDL3-shared ALL
        DEPENDS SDL3::SDL3-shared
        COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:mygame>"
        VERBATIM
    )
endif()
@slouken slouken added this to the 3.x milestone Feb 14, 2025
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