[CMake] Why isn't target_link_libraries not enough in some cases?
Saad Khattak
saadrustam at gmail.com
Wed Apr 4 23:18:59 EDT 2018
Hi,
I am fetching and building SDL2 using FetchContent and then using
target_link_libraries(MyExe SDL2) in the hopes that the required include
directories and libraries will be added populated properly. The example
project can be found here:
https://github.com/samaursa/cmake_fetch_content_SDL2
Unfortunately, it seems that I have to manually specify the include
directories. Although target_link_directories(...) does take care of the
linking against the correct libraries. When it comes to my own CMake
enabled libraries, I do not have to specify the include directories.
This is problematic when installing my libraries or executables that depend
on SDL2 because the include directory for SDL is absolute (
https://cmake.org/Bug/view.php?id=15788).
Is SDL2 setup incorrectly or is there something I am overlooking?
Here is the CMakeLists.txt in the above mentioned example:
------------------------------------------------------------------------------------->
cmake_minimum_required(VERSION 3.11)
project(testProj)
include(FetchContent)
FetchContent_Declare(
SDL2
GIT_REPOSITORY "https://github.com/spurious/SDL-mirror"
)
FetchContent_GetProperties(SDL2)
if(NOT sdl2_POPULATED)
FetchContent_Populate(SDL2)
message(STATUS "Catch source dir: ${sdl2_SOURCE_DIR}")
message(STATUS "Catch binary dir: ${sdl2_BINARY_DIR}")
add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR})
endif()
add_executable(testExe
main.cpp
)
message(STATUS "Catch include dir: ${sdl2_SOURCE_DIR}/include")
target_link_libraries(testExe SDL2)
# the following line is necessary, target_link_libraries for SDL2
# does not automatically set the correct include directories
target_include_directories(testExe PUBLIC ${sdl2_SOURCE_DIR}/include)
<-------------------------------------------------------------------------------------
Regards,
Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180405/644a8128/attachment-0001.html>
More information about the CMake
mailing list