Fixed bug 3166 - It would be nice, if SDL would support including SDL project as a subdirectory into another CMake project

Wayde Reitsma

After attempting to use SDL2 in the way described in this bug, I found the main issue was the includes not being added to the compiler command.

I found the issue was that the target_include_directories commands for the SDL2, SDL2-static and SDL2main targets only sets the public includes for installations using the INSTALL_INTERFACE generator expression.

I have written a patch to CMakeLists.txt that fixes this issue by adding another item to the target_include_directories commands, utilizing the BUILD_INTERFACE generator expression to correctly add the include directory during builds.
This commit is contained in:
Sam Lantinga 2018-09-24 08:41:59 -07:00
parent d07fe7ad95
commit 8aaef4b914

View file

@ -1718,7 +1718,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
# Always build SDLmain # Always build SDLmain
add_library(SDL2main STATIC ${SDLMAIN_SOURCES}) add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
target_include_directories(SDL2main PUBLIC $<INSTALL_INTERFACE:include/SDL2>) target_include_directories(SDL2main PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include/SDL2>)
set(_INSTALL_LIBS "SDL2main") set(_INSTALL_LIBS "SDL2main")
if (NOT ANDROID) if (NOT ANDROID)
set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX}) set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
@ -1747,7 +1747,7 @@ if(SDL_SHARED)
endif() endif()
set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS}) set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
target_include_directories(SDL2 PUBLIC $<INSTALL_INTERFACE:include/SDL2>) target_include_directories(SDL2 PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include/SDL2>)
if (NOT ANDROID) if (NOT ANDROID)
set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX}) set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
endif() endif()
@ -1773,7 +1773,7 @@ if(SDL_STATIC)
# libraries - do we need to consider this? # libraries - do we need to consider this?
set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS}) set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
target_include_directories(SDL2-static PUBLIC $<INSTALL_INTERFACE:include/SDL2>) target_include_directories(SDL2-static PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include/SDL2>)
if (NOT ANDROID) if (NOT ANDROID)
set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX}) set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
endif() endif()