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
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake