Skip to content

Commit

Permalink
CI: Change Ubuntu version and fix SDL issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hobyst committed Sep 7, 2023
1 parent 6304d18 commit 6714893
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 206 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ on: [push, pull_request]

jobs:
Linux:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

env:
BUILD_TYPE: Release
CC: "${{ matrix.cc }}"
CXX: "${{ matrix.cxx }}"
CMAKE_PREFIX_PATH: "/usr"

strategy:
fail-fast: false
Expand All @@ -21,13 +20,13 @@ jobs:
cmake_options: -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF -DRMLUI_SAMPLES_BACKEND=GLFW_GL2
- cc: clang
cxx: clang++
cmake_options: -DRMLUI_SAMPLES_BACKEND=SDL_VK -DSDL_LIBRARY=SDL2 -DSDL_INCLUDE_DIR=/usr/include/SDL2
cmake_options: -DRMLUI_SAMPLES_BACKEND=SDL_VK
- cmake_options: -DRMLUI_BUILD_TESTING=ON -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF
enable_testing: true
- cmake_options: -DRMLUI_ENABLE_LOTTIE_PLUGIN=ON -DRMLUI_SAMPLES_BACKEND=X11_GL2
- cmake_options: -DRMLUI_DISABLE_RTTI_AND_EXCEPTIONS=ON -DRMLUI_SAMPLES_BACKEND=SDL_GL2 -DSDL_LIBRARY=SDL2 -DSDL_INCLUDE_DIR=/usr/include/SDL2 -DSDL_IMAGE_LIBRARY=/usr/lib/x86_64-linux-gnu/libSDL2_image-2.0.so.0 -DSDL_IMAGE_INCLUDE_DIR=/usr/include/SDL2
- cmake_options: -DRMLUI_NO_THIRDPARTY_CONTAINERS=ON -DRMLUI_SAMPLES_BACKEND=SFML_GL2
- cmake_options: -DRMLUI_SAMPLES_BACKEND=SDL_VK -DRMLUI_VK_DEBUG=ON -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_BUILD_TYPE=Debug -DSDL_LIBRARY=SDL2 -DSDL_INCLUDE_DIR=/usr/include/SDL2
- cmake_options: -DRMLUI_DISABLE_RTTI_AND_EXCEPTIONS=ON -DRMLUI_SAMPLES_BACKEND=SDL_GL2
- cmake_options: -DRMLUI_NO_THIRDPARTY_CONTAINERS=ON -DRMLUI_SAMPLES_BACKEND=SFML_GL2
- cmake_options: -DRMLUI_SAMPLES_BACKEND=SDL_VK -DRMLUI_VK_DEBUG=ON -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_BUILD_TYPE=Debug

steps:
- uses: actions/checkout@v3
Expand All @@ -44,6 +43,7 @@ jobs:
working-directory: ${{github.workspace}}/Build
run: >-
cmake $GITHUB_WORKSPACE -G Ninja -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRMLUI_BUILD_LUA_BINDINGS=ON -DRMLUI_BUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
-DCMAKE_MODULE_PATH=$GITHUB_WORKSPACE/CMake/Modules/CI/Linux
${{ matrix.cmake_options }}
- name: Build
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
working-directory: ${{github.workspace}}/Build
run: >-
cmake $env:GITHUB_WORKSPACE -A x64 -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=$env:BUILD_TYPE -DRMLUI_BUILD_LUA_BINDINGS=ON -DRMLUI_BUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ${{ matrix.cmake_options }} -DRMLUI_USING_VCPKG=TRUE
-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ${{ matrix.cmake_options }}
- name: Build
working-directory: ${{github.workspace}}/Build
Expand Down
28 changes: 24 additions & 4 deletions CMake/Backends.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ target_sources(rmlui_backend_SDL_GL2 INTERFACE
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.h
)
target_link_libraries(rmlui_backend_SDL_GL2 INTERFACE OpenGL::GL SDL::SDL GLEW::GLEW SDL::Image)
target_link_libraries(rmlui_backend_SDL_GL2 INTERFACE OpenGL::GL SDL2::SDL2 GLEW::GLEW SDL2_image::SDL2_image)

add_library(rmlui_backend_SDL_GL3 INTERFACE)
target_sources(rmlui_backend_SDL_GL3 INTERFACE
Expand All @@ -73,7 +73,12 @@ target_sources(rmlui_backend_SDL_GL3 INTERFACE
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Include_GL3.h
)
target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE OpenGL::GL SDL::SDL SDL::Image)
target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE OpenGL::GL SDL2::SDL2 SDL2_image::SDL2_image)
if(UNIX)
# The OpenGL 3 renderer implementation uses dlopen/dlclose
# This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime
target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE ${CMAKE_DL_LIBS})
endif()

add_library(rmlui_backend_SDL_VK INTERFACE)
target_sources(rmlui_backend_SDL_VK INTERFACE
Expand All @@ -86,7 +91,12 @@ target_sources(rmlui_backend_SDL_VK INTERFACE
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Vulkan/ShadersCompiledSPV.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Vulkan/vk_mem_alloc.h
)
target_link_libraries(rmlui_backend_SDL_VK INTERFACE Vulkan::Vulkan SDL::SDL)
target_link_libraries(rmlui_backend_SDL_VK INTERFACE Vulkan::Vulkan SDL2::SDL2)
if(UNIX)
# The Vulkan renderer implementation uses dlopen/dlclose
# This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime
target_link_libraries(rmlui_backend_SDL_VK INTERFACE ${CMAKE_DL_LIBS})
endif()

add_library(rmlui_backend_SDL_SDLrenderer INTERFACE)
target_sources(rmlui_backend_SDL_SDLrenderer INTERFACE
Expand All @@ -97,7 +107,7 @@ target_sources(rmlui_backend_SDL_SDLrenderer INTERFACE
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_SDL.h
)
target_link_libraries(rmlui_backend_SDL_SDLrenderer INTERFACE SDL::SDL SDL::Image)
target_link_libraries(rmlui_backend_SDL_SDLrenderer INTERFACE SDL2::SDL2 SDL2_image::SDL2_image)

add_library(rmlui_backend_SFML_GL2 INTERFACE)
target_sources(rmlui_backend_SFML_GL2 INTERFACE
Expand Down Expand Up @@ -137,6 +147,11 @@ target_sources(rmlui_backend_GLFW_GL3 INTERFACE
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Include_GL3.h
)
target_link_libraries(rmlui_backend_GLFW_GL3 INTERFACE OpenGL::GL glfw)
if(UNIX)
# The OpenGL 3 renderer implementation uses dlopen/dlclose
# This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime
target_link_libraries(rmlui_backend_GLFW_GL3 INTERFACE ${CMAKE_DL_LIBS})
endif()

add_library(rmlui_backend_GLFW_VK INTERFACE)
target_sources(rmlui_backend_GLFW_VK INTERFACE
Expand All @@ -148,3 +163,8 @@ target_sources(rmlui_backend_GLFW_VK INTERFACE
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.h
)
target_link_libraries(rmlui_backend_GLFW_VK INTERFACE Vulkan::Vulkan glfw)
if(UNIX)
# The Vulkan renderer implementation uses dlopen/dlclose
# This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime
target_link_libraries(rmlui_backend_GLFW_VK INTERFACE ${CMAKE_DL_LIBS})
endif()
103 changes: 47 additions & 56 deletions CMake/BackendsDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
#[[
Set up of external dependencies required by the sample backends

All dependencies are searched as soft dependencies so that they won't error out if the library
is declared by other means
#]]

include("${PROJECT_SOURCE_DIR}/CMake/Utils.cmake")

# --- Window/input APIs ---
# SDL
if(RMLUI_SAMPLES_BACKEND MATCHES "^SDL")
# All dependencies are searched as soft dependencies so that they won't error out if the library
# is declared by other means
if(VCPKG_TOOLCHAIN)
# vcpkg uses a different name for their SDL find module and target than the official CMake one
find_package("SDL2")

# If the target has been successfully imported
if(TARGET SDL2::SDL2)
# Report SDL as found
set(SDL_FOUND TRUE)

# Add the target to SDL_LIBRARIES
# This way no other pieces of code will need to be modified for the CMake project to work with vcpkg's SDL
list(APPEND SDL_LIBRARIES SDL2::SDL2)
endif()
else()
find_package("SDL" "2")
endif()
# Although the official CMake find module is called FindSDL.cmake, the official config module
# provided by the SDL package for its version 2 is called SDL2Config.cmake
# Following this trend, the official SDL config files change their name according to their major version number
find_package("SDL2" REQUIRED)

#[[
RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
Current code operates using a hybrid mode by detecting either the variable or the target due to the possibility
of package managers such as Conan and vcpkg of setting up SDL in their own way but always following the
target naming conventions of the official SDL config files
#]]

# RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
# In CMake 3.19 the IMPORTED target SDL::SDL is available when using the FindSDL find module.
# More info: https://cmake.org/cmake/help/latest/module/FindSDL.html
# Current code operates using a hybrid mode by detecting either the variable or the target due to the possibility
# of package managers such as Conan and vcpkg of setting up SDL in their own way but always following the
# target naming conventions of the official CMake find modules
if(NOT TARGET SDL::SDL AND NOT SDL_FOUND)
report_not_found_dependency("SDL" SDL::SDL)
if(NOT TARGET SDL2::SDL2 AND NOT SDL2_FOUND)
report_not_found_dependency("SDL2" SDL2::SDL2)
endif()

# Set up the detected SDL as the SDL::SDL INTERFACE target if it hasn't already been created
# Set up the detected SDL as the SDL2::SDL2 INTERFACE target if it hasn't already been created
# This is done for consistent referencing across the CMake code regardless of the CMake version used
if(NOT TARGET SDL::SDL)
add_library(SDL::SDL INTERFACE IMPORTED)
if(NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 INTERFACE IMPORTED)

# Any CMake target linking against SDL::SDL will link against the SDL libraries and have
# Any CMake target linking against SDL2::SDL2 will link against the SDL libraries and have
# their include directories added to their target properties
target_link_libraries(SDL::SDL INTERFACE ${SDL_LIBRARIES})
target_include_directories(SDL::SDL INTERFACE ${SDL_INCLUDE_DIRS})
target_link_libraries(SDL2::SDL2 INTERFACE ${SDL2_LIBRARIES})
target_include_directories(SDL2::SDL2 INTERFACE ${SDL2_INCLUDE_DIRS})
endif()

# SDL_GL2 backend requires GLEW
Expand All @@ -52,8 +46,8 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SDL")
endif()

# Check version requirement for the SDL renderer
if(RMLUI_SAMPLES_BACKEND STREQUAL "SDL_SDLrenderer" AND SDL_VERSION VERSION_LESS "2.0.20")
message(FATAL_ERROR "SDL native renderer backend (${RMLUI_SAMPLES_BACKEND}) requires SDL 2.0.20 (found ${SDL_VERSION}).")
if(RMLUI_SAMPLES_BACKEND STREQUAL "SDL_SDLrenderer" AND SDL2_VERSION VERSION_LESS "2.0.20")
message(FATAL_ERROR "SDL native renderer backend (${RMLUI_SAMPLES_BACKEND}) requires SDL 2.0.20 (found ${SDL2_VERSION}).")
endif()

# List of SDL backends that require SDL_image to work with samples
Expand All @@ -74,26 +68,10 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SDL")

# Require SDL_image if needed
if(RMLUI_SDLIMAGE_REQUIRED)
find_package("SDL_image" "2")

# RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
# FindSDL_image doesn't provide an imported target to check against
# Using old method of using a variable to check
if(NOT SDL_IMAGE_FOUND AND NOT TARGET SDL::Image)
report_not_found_dependency("SDL_image" SDL::Image)
endif()
find_package("SDL2_image")

# RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
# No official target name has been decided for SDL_image yet, but we pretend there's one
# to make the code more future-proof
# For us, its name will be SDL::Image
if(NOT TARGET SDL::Image)
add_library(SDL::Image INTERFACE IMPORTED)

# Any CMake target linking against SDL::Image will link against the SDL_image libraries
# and have their include directories added to their target properties
target_link_libraries(SDL::Image INTERFACE ${SDL_IMAGE_LIBRARIES})
target_include_directories(SDL::Image INTERFACE ${SDL_IMAGE_INCLUDE_DIRS})
if(NOT TARGET SDL2_image::SDL2_image)
report_not_found_dependency("SDL2_image" SDL2_image::SDL2_image)
endif()
endif()
endif()
Expand Down Expand Up @@ -134,8 +112,10 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SFML")

# Run find package with component names both capitalized and lower-cased
find_package("SFML" "2" COMPONENTS ${RMLUI_SFML_REQUIRED_COMPONENTS})
list(TRANSFORM RMLUI_SFML_REQUIRED_COMPONENTS TOLOWER OUTPUT_VARIABLE RMLUI_SFML_REQUIRED_COMPONENTS_LOWER)
find_package("SFML" "2" COMPONENTS ${RMLUI_SFML_REQUIRED_COMPONENTS_LOWER})
if(NOT SFML_FOUND)
list(TRANSFORM RMLUI_SFML_REQUIRED_COMPONENTS TOLOWER OUTPUT_VARIABLE RMLUI_SFML_REQUIRED_COMPONENTS_LOWER_CASE)
find_package("SFML" "2" COMPONENTS ${RMLUI_SFML_REQUIRED_COMPONENTS_LOWER_CASE})
endif()

# Since we are using find_package() in basic mode, we can check the _FOUND variable
if(NOT SFML_FOUND)
Expand Down Expand Up @@ -165,8 +145,19 @@ if(RMLUI_SAMPLES_BACKEND MATCHES "^SFML")
string(TOLOWER ${sfml_component} sfml_component_lower)

if(TARGET sfml-${sfml_component_lower})
#[[
RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
Because the target CMake version is 3.10, we can't alias non-global targets nor global imported targets.

Promoting an imported target to the global scope without it being necessary can cause undesired behavior,
specially when the project is consumed as a subdirectory inside another CMake project, therefore is not
recommended. Instead of that, we pseudo-alias the target creating a second INTERFACE target with alias name.
More info: https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries
#]]

# If the target exists, alias it
add_library(SFML::${sfml_component} ALIAS sfml-${sfml_component_lower})
add_library(SFML::${sfml_component} INTERFACE IMPORTED)
target_link_libraries(SFML::${sfml_component} INTERFACE sfml-${sfml_component_lower})
endif()
endforeach()

Expand Down
12 changes: 12 additions & 0 deletions CMake/Modules/CI/Linux/FindSDL2_image.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[[
Find module for SDL_image version 2 that matches the naming convention of the SDL2_imageConfig.cmake file
provided in official distributions of the SDL2_image library

This is necessary on Ubuntu 20.04 because the libsdl2-image-dev package doesn't provide the config file.
https://packages.ubuntu.com/focal/amd64/libsdl2-image-dev/filelist
#]]

set(SDL2_image_FOUND TRUE)

add_library(SDL2_image::SDL2_image INTERFACE IMPORTED)
target_link_libraries(SDL2_image::SDL2_image INTERFACE "SDL2_image")
67 changes: 0 additions & 67 deletions CMake/Modules/Emscripten/FindSDL.cmake

This file was deleted.

Loading

0 comments on commit 6714893

Please sign in to comment.