Skip to content

Commit

Permalink
Add CMake presets
Browse files Browse the repository at this point in the history
I also experimented with more detailed, platform-dependent presets, but found that it is not really that useful. In particular, we want users themselves to use whichever compilers and generators they want to rather than to constrain the choices. We strive to be agnostict toward both generators and platforms. This way, we we can also give more common build instructions regardless of platform.

Furthermore, choosing not to add compiler-specific flags to the presets as discussed in this previous commit: ee9d7f4 "Add common target options to cmake libraries and executables".

Also tested with making presets for e.g. vcpkg and mingw toolchains. However, this doesn't really make sense in presets. First of all, the choice of such a toolchain is not mutually exclusive with the current presets, so we would have to replicate most of them for each toolchain we wanted to support. Further, the exact specifics of these toolcahins, like version, platform, install location, and so on, is very specific to each case. Thus, if we wanted to handle these it would create additional dimensions to the presets, and we'd end up with a huge list of similar presets we would have to mainatain and which users would have to choose from. Or alternatively, users would have to provide a lot of their setup in any case, thereby dismissing some of the initially considered usefulness. Instead, many tools already allow you to setup a toolchain first which can then be used with a given preset. Thus, making the choice of toolchains and cmake presets orthogonal makes a lot more sense.

One unfortunate issue from a user-friendliness perspective is that the cmake gui doesn't allow you to select a preset without a specified generator. There's an issue for this here: https://gitlab.kitware.com/cmake/cmake/-/issues/23341
I figured accepting this for now is better than duplicating all our presets to specify different generators. But the situations is not ideal, hopefully it will be fixed soon.
  • Loading branch information
mikke89 committed Mar 31, 2024
1 parent 579676a commit 27cf1df
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[CMakePresets.json]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Primary CMake build target
/Build/

# Primary CMake install target for development
/Install/

# Other common build targets
/build*/
/Build*/
Expand All @@ -9,6 +12,8 @@
/Lib/
/lib/
/out/
/Install*/
/install*/

# Distribution target
/Distribution/
Expand All @@ -22,6 +27,9 @@
# Not ignore .github/
!.github/

# CMake user files
CMakeUserPresets.json

# Visual Studio project files
*.suo
*.user
Expand Down
24 changes: 22 additions & 2 deletions CMake/BackendsAutoSelection.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
function(backends_auto_selection_error)
message(FATAL_ERROR
"RmlUi ${RMLUI_SAMPLES_BACKEND} backend for ${CMAKE_SYSTEM_NAME} is not available. "
"Please select a backend that is available on the system. "
"Valid options for RMLUI_SAMPLES_BACKEND are: ${RMLUI_AVAILABLE_SAMPLES_BACKENDS}"
)
endfunction()

if(RMLUI_SAMPLES_BACKEND STREQUAL "auto")
if(EMSCRIPTEN)
set(RMLUI_SAMPLES_BACKEND SDL_GL3)
elseif(WIN32)
set(RMLUI_SAMPLES_BACKEND GLFW_GL2)
set(RMLUI_SAMPLES_BACKEND GLFW_GL3)
elseif(APPLE)
set(RMLUI_SAMPLES_BACKEND SDL_SDLrenderer)
else()
elseif(UNIX)
set(RMLUI_SAMPLES_BACKEND X11_GL2)
else()
backends_auto_selection_error()
endif()
elseif(RMLUI_SAMPLES_BACKEND STREQUAL "native")
if(EMSCRIPTEN)
set(RMLUI_SAMPLES_BACKEND SDL_GL3)
elseif(WIN32)
set(RMLUI_SAMPLES_BACKEND WIN32_GL2)
elseif(UNIX AND NOT APPLE)
set(RMLUI_SAMPLES_BACKEND X11_GL2)
else()
backends_auto_selection_error()
endif()
endif()

Expand Down
1 change: 1 addition & 0 deletions CMake/OptionsLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set(RMLUI_AVAILABLE_SAMPLES_BACKENDS
"auto"
"native"
"Win32_GL2"
"Win32_VK"
"X11_GL2"
Expand Down
58 changes: 58 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": 3,
"configurePresets": [
{
"name": "samples",
"cacheVariables": {
"RMLUI_SAMPLES": true
}
},
{
"name": "samples-all",
"inherits": "samples",
"cacheVariables": {
"RMLUI_LOTTIE_PLUGIN": true,
"RMLUI_SVG_PLUGIN": true,
"RMLUI_LUA_BINDINGS": true
}
},
{
"name": "standalone",
"cacheVariables": {
"RMLUI_SAMPLES": true,
"RMLUI_FONT_ENGINE": "none",
"RMLUI_SAMPLES_BACKEND": "native"
}
},
{
"name": "dev",
"installDir": "Install",
"cacheVariables": {
"RMLUI_SAMPLES": true,
"BUILD_TESTING": true,
"BUILD_SHARED_LIBS": false
},
"warnings": {
"dev": true
},
"errors": {
"dev": true
}
},
{
"name": "dev-all",
"inherits": "dev",
"cacheVariables": {
"RMLUI_LOTTIE_PLUGIN": true,
"RMLUI_SVG_PLUGIN": true,
"RMLUI_LUA_BINDINGS": true
}
},
{
"name": "ci",
"cacheVariables": {
"RMLUI_WARNINGS_AS_ERRORS": true
}
}
]
}

0 comments on commit 27cf1df

Please sign in to comment.