| Summary: | CMakeLists.txt bugs | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Yaroslav <saturn4er> |
| Component: | build | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | alexander.grund, cseri9, saturn4er, sezeroz |
| Version: | HG 2.1 | Keywords: | target-2.0.14 |
| Hardware: | x86_64 | ||
| OS: | Windows (All) | ||
|
Description
Yaroslav
2015-05-22 13:43:44 UTC
I found the same issue: adding LINK_PRIVATE in CMakeLists was needed to use SDL with add_subdirectory, otherwise VS wanted to link my program with DirectX's lib files which it couldn't find.
(Note: LINK_PRIVATE was introduced in CMake 2.8.7, if you add this fix you should bump the minimum CMake version as well.)
A diff for SDL 2.0.3 is below:
@@ -2,7 +2,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree built. Please create a build directory
endif()
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 2.8.7)
project(SDL2 C)
include(CheckFunctionExists)
include(CheckLibraryExists)
@@ -1254,7 +1254,7 @@ if(SDL_SHARED)
OUTPUT_NAME "SDL2")
endif()
set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
- target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
+ target_link_libraries(SDL2 LINK_PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
endif()
if(SDL_STATIC)
Better would be to require CMake 3.x and use PRIVATE instead of LINK_PRIVATE (In reply to alexander.grund from comment #2) > Better would be to require CMake 3.x and use PRIVATE instead of LINK_PRIVATE I decided to do that. https://hg.libsdl.org/SDL/rev/f027f0932dba I'm resolving this bug, but I don't have an external project to test against, so please reopen if I screwed this up in some way! --ryan. (In reply to alexander.grund from comment #2) > Better would be to require CMake 3.x and use PRIVATE instead of LINK_PRIVATE Why is it better? Does newer cmake versions warn with LINK_PRIVATE or something? See https://cmake.org/cmake/help/latest/command/target_link_libraries.html#libraries-for-a-target-and-or-its-dependents-legacy > This signature is for compatibility only. Prefer the PUBLIC or PRIVATE keywords instead. So PRIVATE is the preferred approach and the updated CMake version isn't really an issue as getting a more recent version installed is a no-brainer (build with CMake, install via package, pip, ...) |