We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2992 - CMakeLists.txt bugs
Summary: CMakeLists.txt bugs
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.14
Depends on:
Blocks:
 
Reported: 2015-05-22 13:43 UTC by Yaroslav
Modified: 2020-06-30 06:40 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yaroslav 2015-05-22 13:43:44 UTC
I just found bugs in your CMakeLists.txt file in root of sources. When you use target_link_libraries, you should set modificator "LINK_PRIVATE". When I include SDL into my project using add_subdirectory, my main project begin to include same *.lib's file as SDL project. 

Also, line 199 contains «add_definitions(-DUSING_GENERATED_CONFIG_H)». This line causes a error “Wrong SDL_config.h, check your include path?”

This bugs were detected when I generate VS project
Comment 1 cseri 2015-08-03 16:20:18 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)
Comment 2 alexander.grund 2020-02-07 15:17:42 UTC
Better would be to require CMake 3.x and use PRIVATE instead of LINK_PRIVATE
Comment 3 Ryan C. Gordon 2020-06-27 00:13:08 UTC
(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.
Comment 4 Ozkan Sezer 2020-06-27 00:55:55 UTC
(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?
Comment 5 alexander.grund 2020-06-30 06:40:00 UTC
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, ...)