Skip to content

Commit

Permalink
Work on fetch sdl
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 18, 2023
1 parent 3b10ee4 commit 99d8e00
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 34 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ endif()
#------------------------------------------------------------------------------
if (EMSCRIPTEN AND NOT HELLOIMGUI_USE_SDL_OPENGL3 AND NOT HELLOIMGUI_USE_GLFW_OPENGL3)
set(HELLOIMGUI_USE_SDL_OPENGL3 ON)
set(HELLOIMGUI_USE_GLFW_OPENGL3 OFF)
endif()


Expand Down
2 changes: 1 addition & 1 deletion _example_integration
Submodule _example_integration updated 1 files
+3 −10 Readme.md
14 changes: 0 additions & 14 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,3 @@ if (HELLOIMGUI_BUILD_IMGUI)
endif()
endif()

if (HELLOIMGUI_USE_SDL_OPENGL3)
# On desktop (linux, windows, osx) sdl is provided via vcpkg
# On iOS, the build is done externally via tools/ios/sdl_compile_ios.sh

if (ANDROID OR IOS)
# if the folder SDL is not present, it means that the user did not download the submodule
# we download it for him
if(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/SDL)
message(FATAL_ERROR "Please download SDL by running ${HELLOIMGUI_BASEPATH}/tools/sdl_download.sh")
endif()

add_subdirectory(SDL)
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ function(apkCMake_makeSymLinks)
set(links_folder ${apkCMake_outputProjectFolder}/app/jni)
file(CREATE_LINK ${HELLOIMGUI_BASEPATH} ${links_folder}/hello_imgui_subrepo SYMBOLIC)
file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR} ${links_folder}/appDir SYMBOLIC)

# apkCMake_sdl_symlink_target was filled by _him_prepare_android_sdl_symlink() is src/hello_imgui/CMakeLists.txt
file(CREATE_LINK ${apkCMake_sdl_symlink_target} ${links_folder}/SDL SYMBOLIC)
endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ add_subdirectory(appDir)
if (NOT TARGET hello_imgui)
add_subdirectory(hello_imgui_subrepo)
endif()
add_subdirectory(SDL)
56 changes: 48 additions & 8 deletions src/hello_imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###################################################################################################
# Global variables and + objective-c++ for apple
###################################################################################################
include(FetchContent)

# Set target name
set(helloimgui_target hello_imgui)
Expand All @@ -16,13 +17,6 @@ endif()
# Global variable for this file
set(imgui_backends_dir ${HELLOIMGUI_IMGUI_SOURCE_DIR}/backends)

# Force emscripten to use opengl3 + sdl
# (this is dirty, maybe this should be done at the root CMakeLists.txt, to be more visible)
if (EMSCRIPTEN)
set(HELLOIMGUI_USE_SDL_OPENGL3 ON)
set(HELLOIMGUI_USE_GLFW_OPENGL3 OFF)
endif()


###################################################################################################
# Add library and sources: API = him_add_target
Expand Down Expand Up @@ -90,6 +84,7 @@ function(him_add_linux_options)
endif()
endfunction()


###################################################################################################
# Windows related options: API = him_add_windows_options
###################################################################################################
Expand Down Expand Up @@ -185,14 +180,59 @@ endfunction()
# SDL backend: API = him_use_sdl2_backend
###################################################################################################
function (him_use_sdl2_backend target)
_him_fetch_sdl_if_needed()
_him_link_sdl(${helloimgui_target})

target_sources(${target} PRIVATE
${imgui_backends_dir}/imgui_impl_sdl2.h
${imgui_backends_dir}/imgui_impl_sdl2.cpp
)
_him_link_sdl(${helloimgui_target})
target_compile_definitions(${helloimgui_target} PUBLIC HELLOIMGUI_USE_SDL)
endfunction()


function(_him_fetch_sdl_if_needed)
if (HELLOIMGUI_USE_SDL_OPENGL3 AND (IOS OR ANDROID))
_him_fetch_declare_sdl()
if(ANDROID)
FetchContent_Populate(sdl)
_him_prepare_android_sdl_symlink()
endif()
if(IOS)
FetchContent_MakeAvailable(sdl)
endif()
endif()
endfunction()

function(_him_prepare_android_sdl_symlink)
# We now have SDL in _deps/sdl-src
set(sdl_location ${CMAKE_BINARY_DIR}/_deps/sdl-src)
# We need to communicate this location to the function apkCMake_makeSymLinks()
# so that it can create the symlinks in the right place:
# it will use the variable apkCMake_sdl_symlink_target
set(apkCMake_sdl_symlink_target ${CMAKE_BINARY_DIR}/_deps/sdl-src CACHE STRING "" FORCE)
endfunction()

function(_him_fetch_declare_sdl)
# iOS and Android were tested with SDL 2.28.5
# other platforms, not yet
if (IOS OR ANDROID)
set(sdl_version 2.28.5)
else()
set(sdl_version 2.24.2)
endif()

message(STATUS "Fetching SDL version ${sdl_version}")
include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(sdl
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-${sdl_version}
GIT_PROGRESS TRUE
)
endfunction()


function(_him_link_sdl target)
if (need_fetch_make_available_sdl)
FetchContent_MakeAvailable(sdl)
Expand Down
11 changes: 0 additions & 11 deletions tools/sdl_download.sh

This file was deleted.

0 comments on commit 99d8e00

Please sign in to comment.