From d8fe5f960fc5b17fe4862e00e92c42c8ed01ef9b Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 2 Sep 2025 18:09:26 -0400 Subject: [PATCH] build --- 3rdparty/CMakeLists.txt | 83 +++++++++++++++++++++++++++++------------ CMakeLists.txt | 3 ++ miniwin/CMakeLists.txt | 15 ++++++-- 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 54259e63..3ac4a72f 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -48,31 +48,33 @@ add_library(libsmacker STATIC ) target_include_directories(libsmacker PUBLIC ${libsmacker_SOURCE_DIR}) -if(DOWNLOAD_DEPENDENCIES) - include(FetchContent) - FetchContent_Declare( - imgui - GIT_REPOSITORY "https://github.com/ocornut/imgui" - GIT_TAG f5befd2d29e66809cd1110a152e375a7f1981f06 - ) - FetchContent_MakeAvailable(imgui) -else() - set(imgui_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui") -endif() +if(ISLE_DEBUG) + if(DOWNLOAD_DEPENDENCIES) + include(FetchContent) + FetchContent_Declare( + imgui + GIT_REPOSITORY "https://github.com/ocornut/imgui" + GIT_TAG f5befd2d29e66809cd1110a152e375a7f1981f06 + ) + FetchContent_MakeAvailable(imgui) + else() + set(imgui_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui") + endif() -add_library(imgui STATIC - ${imgui_SOURCE_DIR}/imgui.cpp - ${imgui_SOURCE_DIR}/imgui_draw.cpp - ${imgui_SOURCE_DIR}/imgui_tables.cpp - ${imgui_SOURCE_DIR}/imgui_widgets.cpp - ${imgui_SOURCE_DIR}/imgui_demo.cpp - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp - ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp -) -target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) -target_link_libraries(imgui PUBLIC SDL3::Headers) -target_link_libraries(imgui PRIVATE SDL3::SDL3) -set_property(TARGET imgui PROPERTY CXX_CLANG_TIDY "") + add_library(imgui STATIC + ${imgui_SOURCE_DIR}/imgui.cpp + ${imgui_SOURCE_DIR}/imgui_draw.cpp + ${imgui_SOURCE_DIR}/imgui_tables.cpp + ${imgui_SOURCE_DIR}/imgui_widgets.cpp + ${imgui_SOURCE_DIR}/imgui_demo.cpp + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp + ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp + ) + target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) + target_link_libraries(imgui PUBLIC SDL3::Headers) + target_link_libraries(imgui PRIVATE SDL3::SDL3) + set_property(TARGET imgui PROPERTY CXX_CLANG_TIDY "") +endif() if(DOWNLOAD_DEPENDENCIES) include(FetchContent) @@ -93,3 +95,36 @@ add_library(libweaver STATIC ${libweaver_SOURCE_DIR}/lib/sitypes.cpp ) target_include_directories(libweaver PUBLIC ${libweaver_SOURCE_DIR}/lib) + +if(USE_SDL2) + if(DOWNLOAD_DEPENDENCIES) +# include(FetchContent) +# FetchContent_Declare( +# SDL2 +# GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git" +# GIT_TAG 5d249570393f7a37e037abf22cd6012a4cc56a71 +# EXCLUDE_FROM_ALL +# ) +# FetchContent_MakeAvailable(SDL2) + # Find SDL2 normally + find_package(SDL2 REQUIRED) + + endif() + + file(GLOB SDL2_HEADERS "${SDL2_INCLUDE_DIR}/*.h") + foreach(header IN LISTS SDL2_HEADERS) + get_filename_component(fname ${header} NAME) + configure_file(${header} ${CMAKE_CURRENT_BINARY_DIR}/sdl3-shim/SDL3/${fname} COPYONLY) + endforeach() + + + add_library(SDL3_shim INTERFACE) + target_link_libraries(SDL3_shim INTERFACE SDL2::SDL2) + target_include_directories(SDL3_shim INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/sdl3-shim") + target_include_directories(SDL3_shim INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/sdl3-shim/") + + add_library(SDL3::SDL3 ALIAS SDL3_shim) + + add_library(SDL3::Headers ALIAS SDL3_shim) + +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index deebda7e..dff8bd5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ cmake_dependent_option(ISLE_COMPILE_SHADERS "Compile shaders" ON "SDL_SHADERCROS option(CMAKE_POSITION_INDEPENDENT_CODE "Build with -fPIC" ON) option(ENABLE_CLANG_TIDY "Enable clang-tidy") option(DOWNLOAD_DEPENDENCIES "Download dependencies" ON) +option(USE_SDL2 "Use SDL2 instead of SDL3 via a shim" ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CACHE PATH "Directory where to put executables and dll") set(ISLE_EMSCRIPTEN_HOST "" CACHE STRING "Host URL for Emscripten streaming (e.g., https://test.com)") cmake_dependent_option(BUILD_SHARED_LIBS "Build lego1 as a shared library" ON "NOT EMSCRIPTEN" OFF) @@ -74,6 +75,7 @@ if (DOWNLOAD_DEPENDENCIES) message(STATUS "Fetching SDL3 and iniparser. This might take a while...") include(FetchContent) + if(NOT USE_SDL2) if(ANDROID) # Built by Gradle find_package(SDL3 REQUIRED CONFIG COMPONENTS Shared) @@ -95,6 +97,7 @@ if (DOWNLOAD_DEPENDENCIES) endif() FetchContent_MakeAvailable(SDL3) endif() + endif() FetchContent_Declare( iniparser diff --git a/miniwin/CMakeLists.txt b/miniwin/CMakeLists.txt index 07f40b04..e80ec5b1 100644 --- a/miniwin/CMakeLists.txt +++ b/miniwin/CMakeLists.txt @@ -28,7 +28,9 @@ target_compile_definitions(miniwin PRIVATE ) list(APPEND GRAPHICS_BACKENDS USE_SOFTWARE_RENDER) -list(APPEND GRAPHICS_BACKENDS USE_SDL_GPU) +if(NOT USE_SDL2) + list(APPEND GRAPHICS_BACKENDS USE_SDL_GPU) +endif() if(NOT WINDOWS_STORE) find_package(OpenGL) @@ -116,11 +118,16 @@ endif() target_compile_definitions(miniwin PUBLIC MINIWIN) +target_include_directories(miniwin PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src/internal +) + +if(USE_SDL_GPU IN_LIST GRAPHICS_BACKENDS) target_include_directories(miniwin PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/src/internal ${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/generated ) +endif() target_link_libraries(miniwin PUBLIC miniwin-headers) target_link_libraries(miniwin PRIVATE SDL3::SDL3) @@ -129,7 +136,7 @@ target_compile_definitions(miniwin PUBLIC ${GRAPHICS_BACKENDS}) # Shader stuff - +if(USE_SDL_GPU IN_LIST GRAPHICS_BACKENDS) set(shader_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/src") set(shader_gen_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/generated") set(py_gencshadersource "${CMAKE_CURRENT_SOURCE_DIR}/src/d3drm/backends/sdl3gpu/shaders/gencshadersource.py") @@ -213,7 +220,7 @@ endforeach() set(index_cpp "${shader_gen_dir}/ShaderIndex.cpp") set(index_h "${shader_gen_dir}/ShaderIndex.h") - +endif() if(ISLE_COMPILE_SHADERS) add_custom_command(OUTPUT "${index_h}" "${index_cpp}" COMMAND Python3::Interpreter "${py_gencshadersource}" "index"