Skip to content

Commit

Permalink
cmake: add option HELLOIMGUI_DOWNLOAD_THIRD (OFF under Linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 15, 2023
1 parent b2f6546 commit ce61665
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_automation_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
with:
submodules: true

- name: install xorg-dev (ubuntu only)
- name: apt install libglfw3-dev xorg-dev (ubuntu only)
if: ${{ matrix.platform == 'ubuntu-latest' }}
run: sudo apt-get update && sudo apt-get install -y xorg-dev
run: sudo apt-get update && sudo apt-get install -y xorg-dev libglfw3-dev

- name: Install & Start Xvfb (ubuntu only)
if: ${{ matrix.platform == 'ubuntu-latest' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/easy_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
# - name: Setup interactive tmate session
# uses: mxschmitt/action-tmate@v3

- name: install xorg-dev (ubuntu only)
- name: apt install xorg-dev libglfw3-dev (ubuntu only)
if: ${{ matrix.platform == 'ubuntu-latest' }}
run: sudo apt-get update && sudo apt-get install -y xorg-dev
run: sudo apt-get update && sudo apt-get install -y xorg-dev libglfw3-dev

- name: Build _example_integration
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/multiplatform_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
with:
submodules: true

- name: install xorg-dev (ubuntu only)
- name: apt install xorg-dev libglfw3-dev (ubuntu only)
if: ${{ matrix.platform == 'ubuntu-latest' }}
run: sudo apt-get update && sudo apt-get install -y xorg-dev
run: sudo apt-get update && sudo apt-get install -y xorg-dev libglfw3-dev

- name: Build and install
shell: bash
Expand Down
105 changes: 81 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,40 @@ if(MACOSX)
endif()

#------------------------------------------------------------------------------
# Options / Backend selection
# Options / backend selection
#------------------------------------------------------------------------------
# If no backend option is selected, automatically download glfw and build it
if (NOT HELLOIMGUI_WITH_GLFW
AND NOT HELLOIMGUI_WITH_SDL
AND NOT HELLOIMGUI_USE_SDL_OPENGL3
AND NOT HELLOIMGUI_USE_GLFW_OPENGL3
AND NOT HELLOIMGUI_USE_QT
AND NOT EMSCRIPTEN
)
set(HELLOIMGUI_WITH_GLFW ON CACHE BOOL "")
message(WARNING "
HelloImGui: using Glfw as default default backend (it will be downloaded and built inside {CMAKE_CURRENT_BINARY_DIR}/_deps/glfw-*)
In order to select your own backend, use one of the cmake options below:
-DHELLOIMGUI_WITH_GLFW=ON # To download and build glfw automatically
-DHELLOIMGUI_WITH_SDL=ON # To download and build SDL automatically
-DHELLOIMGUI_USE_GLFW_OPENGL3=ON # To use your own version of GLFW (it should be findable via find_package(glfw3))
-DHELLOIMGUI_USE_SDL_OPENGL3=ON # To use your own version of SDL (it should be findable via find_package(SDL2))
")
endif()

# Backend selection with automatic backend compilation
# Backend selection with automatic backend download
# (if you set any of those options, the corresponding backend will be automatically downloaded at build time)
# Note: if HELLOIMGUI_DOWNLOAD_THIRD is OFF, these options will not work (this is the default under Linux)
option(HELLOIMGUI_WITH_GLFW "Add GLFW+OpenGl3 support (glfw will be automatically compiled via ExternalProject_Add)" OFF)
option(HELLOIMGUI_WITH_SDL "Add SDL+OpenGl3 support (SDL will be automatically compiled via ExternalProject_Add)" OFF)

# Backend selection with manual backend compilation
# Backend selection without automatic download (you need to provide them system-wide, or via a package manager)
# (setting those options without setting HELLOIMGUI_WITH_XXX will require that the backend can be found by find_package())
option(HELLOIMGUI_USE_SDL_OPENGL3 "Build HelloImGui for SDL+OpenGL3" OFF)
option(HELLOIMGUI_USE_GLFW_OPENGL3 "Build HelloImGui for GLFW+OpenGL3" OFF)
option(HELLOIMGUI_USE_QT "Build HelloImGui for Qt" OFF)


#------------------------------------------------------------------------------
# HELLOIMGUI_DOWNLOAD_THIRD: download third party libraries as part of the build
# This is the default, except under Linux, where it is expected that the libraries are installed system-wide.
#
# When ON, the libraries that can be downloaded are SDL and Glfw. This is governed by the options
# HELLOIMGUI_WITH_GLFW and HELLOIMGUI_WITH_SDL, where HELLOIMGUI_WITH_GLFW is set to ON if no backend
# is selected manually.
#------------------------------------------------------------------------------
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
option(HELLOIMGUI_DOWNLOAD_THIRD "Automatically download third party libraries during the build" OFF)
else()
option(HELLOIMGUI_DOWNLOAD_THIRD "Automatically download third party libraries during the build" ON)
endif()
if (NOT HELLOIMGUI_DOWNLOAD_THIRD)
set(HELLOIMGUI_WITH_GLFW OFF)
set(HELLOIMGUI_WITH_SDL OFF)
endif()


#------------------------------------------------------------------------------
# Build options / ImGui
#------------------------------------------------------------------------------
Expand Down Expand Up @@ -167,6 +169,61 @@ option(HELLOIMGUI_USE_GLAD "Use Glad OpenGl loader" ${need_opengl_loader})
###############################################################################


#------------------------------------------------------------------------------
# Backend check: If no backend option is selected,
# either select Glfw automatically if possible, or fail
#------------------------------------------------------------------------------
#
if (NOT HELLOIMGUI_WITH_GLFW
AND NOT HELLOIMGUI_WITH_SDL
AND NOT HELLOIMGUI_USE_SDL_OPENGL3
AND NOT HELLOIMGUI_USE_GLFW_OPENGL3
AND NOT HELLOIMGUI_USE_QT
AND NOT EMSCRIPTEN
)
set(backend_message "
In order to select your own backend, use one of the cmake options below:
-DHELLOIMGUI_WITH_GLFW=ON # To download and build glfw automatically
-DHELLOIMGUI_WITH_SDL=ON # To download and build SDL automatically
-DHELLOIMGUI_USE_GLFW_OPENGL3=ON # To use your own version of GLFW (it should be findable via find_package(glfw3))
-DHELLOIMGUI_USE_SDL_OPENGL3=ON # To use your own version of SDL (it should be findable via find_package(SDL2))
(Note: under Linux, it is advised to use system-wide libraries, and not to use
-DHELLOIMGUI_WITH_GLFW=ON or -DHELLOIMGUI_WITH_SDL=ON)
")
if (HELLOIMGUI_DOWNLOAD_THIRD)
set(HELLOIMGUI_WITH_GLFW ON)
message(STATUS "
HelloImGui: using Glfw as default default backend (it will be downloaded and built inside {CMAKE_CURRENT_BINARY_DIR}/_deps/glfw-*)
${backend_message}
")
else()
# Check if Glfw can be found
find_package(glfw3 QUIET)
if (glfw3_FOUND)
set(HELLOIMGUI_USE_GLFW_OPENGL3 ON)
message(STATUS
"HelloImGui: using Glfw as default default backend (it was found via find_package(glfw3))
${backend_message}
")
else()
set(glfw_help_msg "")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(glfw_help_msg "
you can install glfw via your package manager (apt, pacman, etc).
For example, on Ubuntu, you can run:
sudo apt install libglfw3-dev
")
endif()
message(FATAL_ERROR "
HelloImGui: no backend selected, and could not find Glfw via find_package(glfw3).
${backend_message} ${glfw_help_msg}
")
endif()
endif()
endif()


###############################################################################
# HelloImGui Build Actions
###############################################################################
Expand All @@ -182,7 +239,7 @@ endif()
# Download backend glfw or sdl if required
#------------------------------------------------------------------------------
if (HELLOIMGUI_WITH_GLFW)
set(HELLOIMGUI_USE_GLFW_OPENGL3 ON CACHE BOOL "" FORCE)
set(HELLOIMGUI_USE_GLFW_OPENGL3 ON)
if (NOT TARGET glfw AND NOT EMSCRIPTEN)
include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
Expand All @@ -196,7 +253,7 @@ if (HELLOIMGUI_WITH_GLFW)
endif()

if (HELLOIMGUI_WITH_SDL)
set(HELLOIMGUI_USE_SDL_OPENGL3 ON CACHE BOOL "" FORCE)
set(HELLOIMGUI_USE_SDL_OPENGL3 ON)
if (NOT TARGET sdl AND NOT EMSCRIPTEN)
include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
Expand Down

0 comments on commit ce61665

Please sign in to comment.