From d5f713caa184ec34e5c200b5dec63bd70dd9b9df Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Sat, 25 Dec 2021 22:35:30 +0300 Subject: [PATCH 1/2] Add SDL2 fallback in backend_test\CMakeLists.txt If SDL was installed using CMake, it normally goes to a location Where it can be found by `find_package`. There is no need to force `SDL_PATH` on users, and this commit allows building `backend_test` Without having to specify it. Backwards compatible. --- README.md | 2 +- backend_test/CMakeLists.txt | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b503bd6..dfed686 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Notes: * cmake options are IMGUI_STATIC (compiling as static library), IMGUI_FREETYPE (for using Freetype2) and FREETYPE_PATH (Freetype2 cmake install location) * or as in https://github.com/sonoro1234/LuaJIT-ImGui/tree/master/build - For compiling with backends there is now an example with SDL2 and opengl3 in folder backend_test. It will generate a cimgui_sdl module and a test_sdl executable. You only need to provide SDL_PATH telling cmake where to look for SDL2 cmake installation. + For compiling with backends there is now an example with SDL2 and opengl3 in folder backend_test. It will generate a cimgui_sdl module and a test_sdl executable. # using generator diff --git a/backend_test/CMakeLists.txt b/backend_test/CMakeLists.txt index 60a9365..46808b5 100644 --- a/backend_test/CMakeLists.txt +++ b/backend_test/CMakeLists.txt @@ -66,7 +66,13 @@ endif(WIN32) list(APPEND IMGUI_SOURCES ${BAKENDS_FOLDER}imgui_impl_sdl.cpp) if(DEFINED SDL_PATH) message(STATUS "SDL_PATH defined as " ${SDL_PATH}) - FIND_PACKAGE(SDL2 REQUIRED PATHS ${SDL_PATH}) + FIND_PACKAGE(SDL2 PATHS ${SDL_PATH}) +else(DEFINED SDL_PATH) + # If SDL_PATH is not set, fallback and attempt to find SDL cmake script at a default location + find_package(SDL2) +endif(DEFINED SDL_PATH) + +if(SDL2_FOUND) get_target_property(SDL_INCLUDE SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES) message(STATUS "sdlinclude is " ${SDL_INCLUDE}) if ("${SDL_INCLUDE}" STREQUAL "" OR "${SDL_INCLUDE}" STREQUAL "SDL_INCLUDE-NOTFOUND") #if not found latest SDL2 cmake config use older @@ -80,10 +86,15 @@ if(DEFINED SDL_PATH) set(SDL_MAIN SDL2::SDL2main) message(STATUS ${SDL_MAIN} ${IMGUI_SDL_LIBRARY}) endif() -else(DEFINED SDL_PATH) - message(STATUS "SDL_PATH not defined") +else(SDL2_FOUND) + if(DEFINED SDL_PATH) + message(FATAL_ERROR "Cannot find SDL at SDL_PATH") + else(DEFINED SDL_PATH) + message(FATAL_ERROR "Cannot find SDL. Maybe try specifying SDL_PATH?") + endif(DEFINED SDL_PATH) + set(IMGUI_SDL_LIBRARY SDL2) -endif(DEFINED SDL_PATH) +endif(SDL2_FOUND) add_library(cimgui_sdl SHARED ${IMGUI_SOURCES}) target_link_libraries(cimgui_sdl ${IMGUI_LIBRARIES} ${IMGUI_SDL_LIBRARY}) From 52bbaf1117efe7e5487e018b15dc47758a5c0985 Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Sun, 26 Dec 2021 20:06:20 +0300 Subject: [PATCH 2/2] Remove IMGUI_SDL_LIBRARY --- backend_test/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend_test/CMakeLists.txt b/backend_test/CMakeLists.txt index 46808b5..defe939 100644 --- a/backend_test/CMakeLists.txt +++ b/backend_test/CMakeLists.txt @@ -92,8 +92,6 @@ else(SDL2_FOUND) else(DEFINED SDL_PATH) message(FATAL_ERROR "Cannot find SDL. Maybe try specifying SDL_PATH?") endif(DEFINED SDL_PATH) - - set(IMGUI_SDL_LIBRARY SDL2) endif(SDL2_FOUND) add_library(cimgui_sdl SHARED ${IMGUI_SOURCES})