Patch submitted upstream: https://github.com/OpenBoardView/OpenBoardView/pull/233 diff --git a/CMakeModules/FindImGui.cmake b/CMakeModules/FindImGui.cmake new file mode 100644 index 0000000..4d1fa42 --- /dev/null +++ b/CMakeModules/FindImGui.cmake @@ -0,0 +1,36 @@ +# Copyright (C) 2018, 2022 Maxim Cournoyer +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the LICENSE file distributed with OpenBoardView. +# Note: +# Searching headers and libraries is very simple and is NOT as powerful as scripts +# distributed with CMake, because LuaDist defines directories to search for. +# Everyone is encouraged to contact the author with improvements. Maybe this file +# becomes part of CMake distribution sometimes. + +# - Find ImGui +# Find the native imgui headers and libraries. +# +# IMGUI_INCLUDE_DIRS - where to find imgui/imgui.h, etc. +# IMGUI_LIBRARIES - List of libraries when using imgui. +# IMGUI_FOUND - True if imgui is found. + +# Look for the header file. +FIND_PATH(IMGUI_INCLUDE_DIR NAMES imgui.h PATH_SUFFIXES imgui) + +# Look for the library. +FIND_LIBRARY(IMGUI_LIBRARY NAMES ImGui imgui) + +# Handle the QUIETLY and REQUIRED arguments and set IMGUI_FOUND to TRUE if all listed variables are TRUE. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ImGui DEFAULT_MSG IMGUI_LIBRARY IMGUI_INCLUDE_DIR) + +# Copy the results to the output variables. +IF(IMGUI_FOUND) + SET(IMGUI_LIBRARIES ${IMGUI_LIBRARY}) + SET(IMGUI_INCLUDE_DIRS ${IMGUI_INCLUDE_DIR}) +ELSE() + SET(IMGUI_LIBRARIES) + SET(IMGUI_INCLUDE_DIRS) +ENDIF() + +MARK_AS_ADVANCED(IMGUI_INCLUDE_DIRS IMGUI_LIBRARIES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b359dde..f11fbab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -96,12 +96,16 @@ endif() # note: in the future there may be integrated CMake support into imgui # see: https://github.com/ocornut/imgui/pull/1713 # for now do it manually, after SDL2 because we use the includes for the sdl_opengl examples -execute_process( +find_package(ImGui) # search ImGui from system +if(NOT IMGUI_FOUND) # else fallback to bundled copy + execute_process( COMMAND git submodule update --init src/imgui WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} -) + ) -set(SOURCES + set(IMGUI_LIBRARIES imgui) + + set(SOURCES imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp @@ -109,34 +113,29 @@ set(SOURCES imgui/misc/cpp/imgui_stdlib.cpp imgui/backends/imgui_impl_sdl2.cpp) + if(ENABLE_GL3) + LIST(APPEND SOURCES imgui/backends/imgui_impl_opengl3.cpp) + endif() -if(ENABLE_GL3) - LIST(APPEND SOURCES - imgui/backends/imgui_impl_opengl3.cpp - ) + add_library(imgui STATIC ${SOURCES}) + target_compile_definitions(imgui PUBLIC "-DImDrawIdx=unsigned int") # short is not enough for us + # Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled + if(ENABLE_GLES2) + target_compile_definitions(imgui PUBLIC "-DIMGUI_IMPL_OPENGL_ES2") + endif() + target_include_directories(imgui PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/imgui + ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples + ${CMAKE_CURRENT_SOURCE_DIR}/imgui/misc/cpp + ) + + if(MINGW) + target_link_libraries(imgui SDL2::SDL2-static) + else() + target_link_libraries(imgui SDL2::SDL2) + endif() endif() -add_library(imgui STATIC ${SOURCES}) -target_compile_definitions(imgui PUBLIC "-DImDrawIdx=unsigned int") # short is not enough for us -# Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled -if(ENABLE_GLES2) - target_compile_definitions(imgui PUBLIC "-DIMGUI_IMPL_OPENGL_ES2") -endif() -target_include_directories(imgui PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/imgui - ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples - ${CMAKE_CURRENT_SOURCE_DIR}/imgui/misc/cpp -) - -if(MINGW) -target_link_libraries(imgui - SDL2::SDL2-static -) -else() -target_link_libraries(imgui - SDL2::SDL2 -) -endif() #install(TARGETS imgui DESTINATION ${INSTALL_ARCHIVE_DIR}) # No need to install a static lib diff --git a/src/openboardview/CMakeLists.txt b/src/openboardview/CMakeLists.txt index 470a145..649a373 100644 --- a/src/openboardview/CMakeLists.txt +++ b/src/openboardview/CMakeLists.txt @@ -181,7 +181,7 @@ target_include_directories(${PROJECT_NAME_LOWER} PRIVATE ) target_link_libraries(${PROJECT_NAME_LOWER} - imgui + ${IMGUI_LIBRARIES} SQLite::SQLite3 mpc opengl_target