<div dir="ltr">Hi,<div><br></div><div>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:</div><div><br></div><div><a href="https://github.com/samaursa/cmake_fetch_content_SDL2">https://github.com/samaursa/cmake_fetch_content_SDL2</a><br></div><div><br></div><div>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.</div><div><br></div><div>This is problematic when installing my libraries or executables that depend on SDL2 because the include directory for SDL is absolute (<a href="https://cmake.org/Bug/view.php?id=15788">https://cmake.org/Bug/view.php?id=15788</a>).</div><div><br></div><div>Is SDL2 setup incorrectly or is there something I am overlooking?</div><div><br></div><div>Here is the CMakeLists.txt in the above mentioned example:</div><div>-------------------------------------------------------------------------------------></div><div><pre>cmake_minimum_required(VERSION 3.11)

project(testProj)

include(FetchContent)

FetchContent_Declare(
  SDL2
  GIT_REPOSITORY "<a href="https://github.com/spurious/SDL-mirror">https://github.com/spurious/SDL-mirror</a>"
  )

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)
</pre></div><div><-------------------------------------------------------------------------------------</div><div><br></div><div>Regards,</div><div>Saad</div><div><br></div></div>