From 72606d97e631c4e38cf8d1f1289161baa279f446 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 25 May 2023 15:56:35 +0200 Subject: [PATCH] cmake: allow #include "SDL2/SDL.h.h" when using SDL2 as subproject --- CMakeLists.txt | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ec3f3b97..8e22bdcc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2988,7 +2988,7 @@ string(TOLOWER "${CMAKE_BUILD_TYPE}" lower_build_type) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/include-config-${lower_build_type}") # 3. generate SDL_config in an build_type-dependent folder (which should be first in the include search path) file(GENERATE - OUTPUT "${SDL2_BINARY_DIR}/include-config-$>/SDL_config.h" + OUTPUT "${SDL2_BINARY_DIR}/include-config-$>/SDL2/SDL_config.h" INPUT "${SDL2_BINARY_DIR}/SDL_config.h.intermediate") # Prepare the flags and remove duplicates @@ -3039,9 +3039,9 @@ else() endif() configure_file("${SDL2_SOURCE_DIR}/include/SDL_revision.h.cmake" - "${SDL2_BINARY_DIR}/include/SDL_revision.h") + "${SDL2_BINARY_DIR}/include/SDL2/SDL_revision.h") -# Copy all non-generated headers to "${SDL2_BINARY_DIR}/include" +# Copy all non-generated headers to "${SDL2_BINARY_DIR}/include/SDL2" # This is done to avoid the inclusion of a pre-generated SDL_config.h file(GLOB SDL2_INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h) set(SDL2_COPIED_INCLUDE_FILES) @@ -3050,7 +3050,7 @@ foreach(_hdr IN LISTS SDL2_INCLUDE_FILES) list(REMOVE_ITEM SDL2_INCLUDE_FILES "${_hdr}") else() get_filename_component(_name "${_hdr}" NAME) - set(_bin_hdr "${SDL2_BINARY_DIR}/include/${_name}") + set(_bin_hdr "${SDL2_BINARY_DIR}/include/SDL2/${_name}") list(APPEND SDL2_COPIED_INCLUDE_FILES "${_bin_hdr}") add_custom_command(OUTPUT "${_bin_hdr}" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_hdr}" "${_bin_hdr}" @@ -3284,7 +3284,11 @@ if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN) add_dependencies(SDL2main sdl_headers_copy) # alias target for in-tree builds add_library(SDL2::SDL2main ALIAS SDL2main) - target_include_directories(SDL2main BEFORE PRIVATE "${SDL2_BINARY_DIR}/include" PRIVATE "${SDL2_BINARY_DIR}/include-config-$>") + target_include_directories(SDL2main BEFORE + PRIVATE "${SDL2_BINARY_DIR}/include" + PRIVATE "${SDL2_BINARY_DIR}/include/SDL2" + PRIVATE "${SDL2_BINARY_DIR}/include-config-$>/SDL2" + ) target_include_directories(SDL2main PUBLIC "$" $ $) if (WIN32) target_link_libraries(SDL2main PRIVATE shell32) @@ -3375,7 +3379,8 @@ if(SDL_SHARED) target_link_libraries(SDL2 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD} ${CMAKE_DEPENDS}) target_include_directories(SDL2 PUBLIC "$" - "$>>" + "$" + "$>/SDL2>" "$" "$" ) @@ -3410,7 +3415,8 @@ if(SDL_STATIC) target_link_libraries(SDL2-static PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${CMAKE_DEPENDS}) target_include_directories(SDL2-static PUBLIC "$" - "$>>" + "$" + "$>/SDL2>" "$" "$" ) @@ -3441,7 +3447,8 @@ if(SDL_TEST) EXPORT_NAME SDL2test) target_include_directories(SDL2_test PUBLIC "$" - "$>>" + "$" + "$>/SDL2>" "$" "$") target_link_libraries(SDL2_test PRIVATE ${EXTRA_TEST_LIBS}) @@ -3559,8 +3566,8 @@ if(NOT SDL2_DISABLE_INSTALL) install( FILES ${SDL2_INCLUDE_FILES} - "${SDL2_BINARY_DIR}/include/SDL_revision.h" - "${SDL2_BINARY_DIR}/include-config-$>/SDL_config.h" + "${SDL2_BINARY_DIR}/include/SDL2/SDL_revision.h" + "${SDL2_BINARY_DIR}/include-config-$>/SDL2/SDL_config.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SDL2) string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)