Skip to content

Commit

Permalink
CMake modernization
Browse files Browse the repository at this point in the history
Re-write the CMake project from scratch up to some extent using modern
CMake conventions. Tested with GLFW, OpenGL 3 and rlottie.
Available samples: benchmark, demo, lottie
  • Loading branch information
hobyst committed Jun 7, 2023
1 parent 0df1bbb commit fabd5e4
Show file tree
Hide file tree
Showing 24 changed files with 1,116 additions and 139 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ jobs:
include:
- cc: clang
cxx: clang++
cmake_options: -DENABLE_PRECOMPILED_HEADERS=OFF -DSAMPLES_BACKEND=GLFW_GL2
cmake_options: -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF -DRMLUI_SAMPLES_BACKEND=GLFW_GL2
- cc: clang
cxx: clang++
cmake_options: -DSAMPLES_BACKEND=SDL_VK
- cmake_options: -DBUILD_TESTING=ON -DENABLE_PRECOMPILED_HEADERS=OFF
cmake_options: -DRMLUI_SAMPLES_BACKEND=SDL_VK
- cmake_options: -DRMLUI_BUILD_TESTING=ON -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF
enable_testing: true
- cmake_options: -DNO_FONT_INTERFACE_DEFAULT=ON -DENABLE_LOTTIE_PLUGIN=ON -DSAMPLES_BACKEND=X11_GL2
- cmake_options: -DDISABLE_RTTI_AND_EXCEPTIONS=ON -DSAMPLES_BACKEND=SDL_GL2
- cmake_options: -DNO_THIRDPARTY_CONTAINERS=ON -DSAMPLES_BACKEND=SFML_GL2
- cmake_options: -DSAMPLES_BACKEND=SDL_VK -DRMLUI_VK_DEBUG=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_BUILD_TYPE=Debug
- cmake_options: -DRMLUI_NO_FONT_INTERFACE_DEFAULT=ON -DRMLUI_ENABLE_LOTTIE_PLUGIN=ON -DRMLUI_SAMPLES_BACKEND=X11_GL2
- 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 @@ -42,7 +42,7 @@ jobs:
- name: Configure CMake
working-directory: ${{github.workspace}}/Build
run: >-
cmake $GITHUB_WORKSPACE -G Ninja -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_LUA_BINDINGS=ON -DBUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
cmake $GITHUB_WORKSPACE -G Ninja -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRMLUI_BUILD_LUA_BINDINGS=ON -DRMLUI_BUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
${{ matrix.cmake_options }}
- name: Build
Expand All @@ -65,8 +65,8 @@ jobs:
fail-fast: false
matrix:
include:
- cmake_options: -DSAMPLES_BACKEND=auto
- cmake_options: -DSAMPLES_BACKEND=GLFW_GL2
- cmake_options: -DRMLUI_SAMPLES_BACKEND=auto
- cmake_options: -DRMLUI_SAMPLES_BACKEND=GLFW_GL2

steps:
- uses: actions/checkout@v3
Expand All @@ -80,7 +80,7 @@ jobs:
- name: Configure CMake
working-directory: ${{github.workspace}}/Build
run: >-
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_LUA_BINDINGS=ON -DBUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRMLUI_BUILD_LUA_BINDINGS=ON -DRMLUI_BUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
${{ matrix.cmake_options }}
- name: Build
Expand All @@ -99,9 +99,9 @@ jobs:
fail-fast: false
matrix:
include:
- cmake_options: -DSAMPLES_BACKEND=auto -DENABLE_PRECOMPILED_HEADERS=OFF
- cmake_options: -DSAMPLES_BACKEND=Win32_VK -DRMLUI_VK_DEBUG=ON
- cmake_options: -DSAMPLES_BACKEND=SDL_VK -DBUILD_LUA_BINDINGS_FOR_LUAJIT=ON
- cmake_options: -DRMLUI_SAMPLES_BACKEND=auto -DRMLUI_ENABLE_PRECOMPILED_HEADERS=OFF
- cmake_options: -DRMLUI_SAMPLES_BACKEND=Win32_VK -DRMLUI_VK_DEBUG=ON
- cmake_options: -DRMLUI_SAMPLES_BACKEND=SDL_VK -DRMLUI_BUILD_LUA_BINDINGS_FOR_LUAJIT=ON

steps:
- uses: actions/checkout@v3
Expand All @@ -115,7 +115,7 @@ jobs:
- name: Configure CMake
working-directory: ${{github.workspace}}/Build
run: >-
cmake $env:GITHUB_WORKSPACE -A x64 -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=$env:BUILD_TYPE -DBUILD_LUA_BINDINGS=ON -DBUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON
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 }}
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
run: |-
source emsdk-master/emsdk_env.sh
cd Build
emcmake cmake $GITHUB_WORKSPACE -DBUILD_SAMPLES=ON -DBUILD_SHARED_LIBS=OFF -DWARNINGS_AS_ERRORS=ON -DEMSCRIPTEN_EXE_FLAGS="-O1"
emcmake cmake $GITHUB_WORKSPACE -DRMLUI_BUILD_SAMPLES=ON -DBUILD_SHARED_LIBS=OFF -DWARNINGS_AS_ERRORS=ON -DRMLUI_EMSCRIPTEN_EXE_FLAGS="-O1"
- name: Build
run: |-
Expand Down
121 changes: 0 additions & 121 deletions CMake/BackendFileList.cmake

This file was deleted.

139 changes: 139 additions & 0 deletions CMake/Backends.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
set(BACKEND_COMMON_HDR_FILES
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend.h
)

add_library(rmlui_backend_Win32_GL2 INTERFACE)
target_sources(rmlui_backend_Win32_GL2 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_Win32.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_Win32_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_Win32.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Include_Windows.h
)
target_link_libraries(rmlui_backend_Win32_GL2 INTERFACE OpenGL::GL)

add_library(rmlui_backend_Win32_VK INTERFACE)
target_sources(rmlui_backend_Win32_VK INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_Win32.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_Win32_VK.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_Win32.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Vulkan/ShadersCompiledSPV.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Vulkan/vk_mem_alloc.h
)
target_link_libraries(rmlui_backend_Win32_VK INTERFACE Vulkan::Vulkan)

add_library(rmlui_backend_X11_GL2 INTERFACE)
target_sources(rmlui_backend_X11_GL2 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_X11.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_X11_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_X11.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Include_Xlib.h
)

# RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
# Once the minimum CMake version is CMake >= 3.14, "${X11_LIBRARIES}" should
# be substituted by "X11:X11" in addition to any of the other imported that might
# be required. More info:
# https://cmake.org/cmake/help/latest/module/FindX11.html
target_link_libraries(rmlui_backend_X11_GL2 INTERFACE OpenGL::GL ${X11_LIBRARIES})


add_library(rmlui_backend_SDL_GL2 INTERFACE)
target_sources(rmlui_backend_SDL_GL2 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_SDL_GL2.cpp
${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)

add_library(rmlui_backend_SDL_GL3 INTERFACE)
target_sources(rmlui_backend_SDL_GL3 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_SDL_GL3.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.h
${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)

add_library(rmlui_backend_SDL_VK INTERFACE)
target_sources(rmlui_backend_SDL_VK INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_SDL_VK.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.h
${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)

add_library(rmlui_backend_SDL_SDLrenderer INTERFACE)
target_sources(rmlui_backend_SDL_SDLrenderer INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_SDL.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_SDL_SDLrenderer.cpp
${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)

add_library(rmlui_backend_SFML_GL2 INTERFACE)
target_sources(rmlui_backend_SFML_GL2 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SFML.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_SFML_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_SFML.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.h
)
target_link_libraries(rmlui_backend_SFML_GL2 INTERFACE OpenGL::GL SFML::Graphics SFML::Window SFML::System)

add_library(rmlui_backend_GLFW_GL2 INTERFACE)
target_sources(rmlui_backend_GLFW_GL2 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_GLFW.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_GLFW_GL2.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_GLFW.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL2.h
)
target_link_libraries(rmlui_backend_GLFW_GL2 INTERFACE OpenGL::GL glfw)

add_library(rmlui_backend_GLFW_GL3 INTERFACE)
target_sources(rmlui_backend_GLFW_GL3 INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_GLFW.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_GLFW_GL3.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_GLFW.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Include_GL3.h
)
target_link_libraries(rmlui_backend_GLFW_GL3 INTERFACE OpenGL::GL glfw)

add_library(rmlui_backend_GLFW_VK INTERFACE)
target_sources(rmlui_backend_GLFW_VK INTERFACE
${BACKEND_COMMON_HDR_FILES}
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_GLFW.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Backend_GLFW_VK.cpp
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Platform_GLFW.h
${PROJECT_SOURCE_DIR}/Backends/RmlUi_Renderer_VK.h
)
target_link_libraries(rmlui_backend_GLFW_VK INTERFACE Vulkan::Vulkan glfw)
48 changes: 48 additions & 0 deletions CMake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#[[
Function to print a message to the console indicating a dependency hasn't been found
Arguments:
- friendly_name: Friendly name of the target
- target_name: Name of the CMake target the project is supposed to link against
]]
function(report_not_found_dependency friendly_name target_name)
message(FATAL_ERROR
"${friendly_name} has not been found by CMake. If you are consuming RmlUi as a subdirectory "
"inside another CMake project, please ensure that ${friendly_name} can be linked using \"${target_name}\" "
"as its target name. You can create an ALIAS target to offer an alternative name for a CMake target."
)
endfunction()

# Freetype
if(RMLUI_FONT_INTERFACE STREQUAL "freetype")
# Declaring Freetype as a soft dependency so that it doesn't error out if the package
# is declared by other means
find_package("Freetype")

# Instead of relying on the Freetype_NOTFOUND variable, we check directly for the target
if(NOT TARGET Freetype::Freetype)
report_not_found_dependency("Freetype" Freetype::Freetype)
endif()

# Warn about problematic versions of the library with MSVC
if(DEFINED FREETYPE_VERSION_STRING)
if((${FREETYPE_VERSION_STRING} VERSION_GREATER_EQUAL "2.11.0") AND (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC"))
message(WARNING "Using Freetype 2.11.0 or greater with MSVC can cause issues.")
endif()
else()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
message(WARNING "Using Freetype 2.11.0 or greater with MSVC can cause issues.")
endif()
endif()
endif()

# rlottie
if(RMLUI_ENABLE_LOTTIE_PLUGIN)
# Declaring rlottie as a soft dependency so that it doesn't error out if the package
# is declared by other means
find_package("rlottie")

# Instead of relying on the rlottie_NOTFOUND variable, we check directly for the target
if(NOT TARGET rlottie::rlottie)
report_not_found_dependency("rlottie" rlottie::rlottie)
endif()
endif()
Loading

0 comments on commit fabd5e4

Please sign in to comment.