Skip to content

Commit

Permalink
Implement Tracy profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Mar 3, 2024
1 parent 111dcf2 commit 42e5646
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
39 changes: 38 additions & 1 deletion CMake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*_NOTFOUND variables, we check directly for the existence of the target.
]]

if(NOT "${RMLUI_IS_CONFIG_FILE}")
if(NOT RMLUI_IS_CONFIG_FILE)
include("${CMAKE_CURRENT_LIST_DIR}/Utils.cmake")
endif()

Expand Down Expand Up @@ -64,3 +64,40 @@ if(RMLUI_LUA_BINDINGS AND RMLUI_LUA_BINDINGS_LIBRARY STREQUAL "luajit")
endif()
add_library(RmlUi::External::Lua ALIAS LuaJIT::LuaJIT)
endif()

if(NOT RMLUI_IS_CONFIG_FILE)
if(RMLUI_TRACY_PROFILING AND RMLUI_TRACY_CONFIGURATION)
enable_configuration_type(Tracy Release ON)
else()
enable_configuration_type(Tracy Release OFF)
endif()
endif()

if(RMLUI_TRACY_PROFILING)
find_package(Tracy CONFIG QUIET)

if(NOT TARGET Tracy::TracyClient)
if(RMLUI_IS_CONFIG_FILE)
report_not_found_dependency("Tracy" Tracy::TracyClient)
endif()

message(STATUS "Trying to add Tracy from subdirectory 'Dependencies/tracy'.")
add_subdirectory("Dependencies/tracy")

if(NOT TARGET Tracy::TracyClient)
message(FATAL_ERROR "Tracy client not found. Either "
"(a) make sure target Tracy::TracyClient is available from parent project, "
"(b) Tracy can be found as a config package, or "
"(c) Tracy source files are located in 'Dependencies/Tracy'.")
endif()

if(RMLUI_IS_ROOT_PROJECT)
# Tracy does not export its targets to the build tree. Do that for it here, otherwise CMake will emit an
# error about target `TracyClient` not being located in any export set.
export(EXPORT TracyConfig
NAMESPACE Tracy::
FILE TracyTargets.cmake
)
endif()
endif()
endif()
1 change: 1 addition & 0 deletions CMake/RmlUiConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(RMLUI_LOTTIE_PLUGIN @RMLUI_LOTTIE_PLUGIN@)
set(RMLUI_FONT_ENGINE "@RMLUI_FONT_ENGINE@")
set(RMLUI_LUA_BINDINGS @RMLUI_LUA_BINDINGS@)
set(RMLUI_LUA_BINDINGS_LIBRARY "@RMLUI_LUA_BINDINGS_LIBRARY@")
set(RMLUI_TRACY_PROFILING "@RMLUI_TRACY_PROFILING@")

macro(report_not_found_dependency friendly_name target_name)
message(FATAL_ERROR
Expand Down
26 changes: 26 additions & 0 deletions CMake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,29 @@ function(report_not_found_native_library library_name)
"\n${SDK_NOTICE}"
)
endfunction()

#[[
Enable or disable a given configuration type for multi-configuration generators.
Arguments:
- name: The name of the new configuration
- clone_config: The name of the configuration to clone compile flags from
- enable: Enable or disable configuration
]]
function(enable_configuration_type name clone_config enable)
if(CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${name}" name_upper)
string(TOUPPER "${clone_config}" clone_config_upper)
if(enable)
list(APPEND CMAKE_CONFIGURATION_TYPES "${name}")
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
set("CMAKE_MAP_IMPORTED_CONFIG_${name_upper}" "${name};${clone_config}" CACHE INTERNAL "" FORCE)
set("CMAKE_C_FLAGS_${name_upper}" "${CMAKE_C_FLAGS_${clone_config_upper}}" CACHE INTERNAL "" FORCE)
set("CMAKE_CXX_FLAGS_${name_upper}" "${CMAKE_CXX_FLAGS_${clone_config_upper}}" CACHE INTERNAL "" FORCE)
set("CMAKE_EXE_LINKER_FLAGS_${name_upper}" "${CMAKE_EXE_LINKER_FLAGS_${clone_config_upper}}" CACHE INTERNAL "" FORCE)
set("CMAKE_SHARED_LINKER_FLAGS_${name_upper}" "${CMAKE_SHARED_LINKER_FLAGS_${clone_config_upper}}" CACHE INTERNAL "" FORCE)
else()
list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES "${name}")
endif()
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "List of configurations to enable" FORCE)
endif()
endfunction()
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ option(RMLUI_CUSTOM_RTTI "Build RmlUi with a custom implementation of run-time t

option(RMLUI_PRECOMPILED_HEADERS "Enable precompiled headers for RmlUi." ON)

option(RMLUI_TRACY_PROFILING "Enable profiling with Tracy. Source files can optionally be placed in `Dependencies/tracy`." OFF)
if(RMLUI_TRACY_PROFILING)
option(RMLUI_TRACY_MEMORY_PROFILING "Overload global operator new/delete to track memory allocations in Tracy." ON)
endif()
if(RMLUI_TRACY_PROFILING AND CMAKE_CONFIGURATION_TYPES)
option(RMLUI_TRACY_CONFIGURATION "Enable a separate Tracy configuration type for multi-config generators such as Visual Studio, otherwise enable Tracy in all configurations." ON)
endif()

option(RMLUI_CUSTOM_CONFIGURATION "Customize the RmlUi configuration file to override the default configuration and types." OFF)
set(RMLUI_CUSTOM_CONFIGURATION_FILE "" CACHE STRING "Custom configuration file to be included in place of <RmlUi/Config/Config.h>.")
set(RMLUI_CUSTOM_INCLUDE_DIRS "" CACHE STRING "Extra include directories (use with RMLUI_CUSTOM_CONFIGURATION_FILE).")
Expand Down Expand Up @@ -168,7 +176,6 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/CMake/Modules"
if(RMLUI_IS_ROOT_PROJECT)
# Export build targets, except if RmlUi is included from a parent project using `add_subdirectory`.
export(EXPORT RmlUiTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/RmlUiTargets.cmake"
NAMESPACE RmlUi::
FILE RmlUiTargets.cmake
)
Expand Down
18 changes: 18 additions & 0 deletions Source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,24 @@ if(RMLUI_SVG_PLUGIN)
target_link_libraries(rmlui_core PRIVATE lunasvg::lunasvg)
endif()

if(RMLUI_TRACY_PROFILING)
if(CMAKE_CONFIGURATION_TYPES AND RMLUI_TRACY_CONFIGURATION)
target_link_libraries(rmlui_core PUBLIC "$<$<CONFIG:Tracy>:Tracy::TracyClient>")
target_compile_definitions(rmlui_core PUBLIC "$<$<CONFIG:Tracy>:RMLUI_TRACY_PROFILING>")
if(RMLUI_TRACY_MEMORY_PROFILING)
target_compile_definitions(rmlui_core PRIVATE "$<$<CONFIG:Tracy>:RMLUI_TRACY_MEMORY_PROFILING>")
endif()
message(STATUS "Tracy profiling enabled in configuration `Tracy`.")
else()
target_link_libraries(rmlui_core PUBLIC Tracy::TracyClient)
target_compile_definitions(rmlui_core PUBLIC "RMLUI_TRACY_PROFILING")
if(RMLUI_TRACY_MEMORY_PROFILING)
target_compile_definitions(rmlui_core PRIVATE "RMLUI_TRACY_MEMORY_PROFILING")
endif()
message(STATUS "Tracy profiling enabled.")
endif()
endif()

if(NOT RMLUI_THIRDPARTY_CONTAINERS)
target_compile_definitions(rmlui_core PUBLIC "RMLUI_NO_THIRDPARTY_CONTAINERS")
message(STATUS "Disabling third-party containers for RmlUi.")
Expand Down

0 comments on commit 42e5646

Please sign in to comment.