diff --git a/CMake/Modules/FindTracy.cmake b/CMake/Modules/FindTracy.cmake deleted file mode 100644 index 81c22f785..000000000 --- a/CMake/Modules/FindTracy.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# - Try to find Tracy -# Once done, this will define -# -# TRACY_FOUND - system has Tracy -# TRACY_INCLUDE_DIR - the Tracy include directory - -set(TRACY_DIR "" CACHE PATH "Parent directory of Tracy library") - -find_path(TRACY_INCLUDE_DIR TracyClient.cpp PATHS ${TRACY_DIR} $ENV{TRACY_DIR} PATH_SUFFIXES tracy public tracy/public) - -set(TRACY_FOUND "NO") -if(TRACY_INCLUDE_DIR) - message(STATUS "Found Tracy ${TRACY_INCLUDE_DIR}...") - mark_as_advanced(TRACY_DIR TRACY_INCLUDE_DIR) - set(TRACY_FOUND "YES") -elseif(Tracy_FIND_REQUIRED) - message(FATAL_ERROR "Required library Tracy not found! Install the library and try again. If the library is already installed, set the missing variables manually in cmake.") -else() - message(STATUS "Library Tracy not found...") -endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 6468d0dfa..7d373b333 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,29 +254,64 @@ else() endif() endif() -option(ENABLE_TRACY_PROFILING "Enable profiling with Tracy. Source files can be placed in Dependencies/tracy." OFF) -if( ENABLE_TRACY_PROFILING ) - find_package(Tracy REQUIRED) +function(EnableConfigurationType name enable) + if(enable) + list(APPEND CMAKE_CONFIGURATION_TYPES "${name}") + list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES) + else() + list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES "${name}") + endif() + set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "List of configurations to enable" FORCE) +endfunction() - include_directories(${TRACY_INCLUDE_DIR}) +option(RMLUI_TRACY_PROFILING "Enable profiling with Tracy. Source files can 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) if( CMAKE_CONFIGURATION_TYPES ) - list(APPEND CMAKE_CONFIGURATION_TYPES Tracy) - list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES) - set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING - "Add the configurations that we need" - FORCE) - set(CMAKE_C_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE} -DRMLUI_ENABLE_PROFILING") - set(CMAKE_CXX_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE} -DRMLUI_ENABLE_PROFILING") - set(CMAKE_EXE_LINKER_FLAGS_TRACY "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") - set(CMAKE_SHARED_LINKER_FLAGS_TRACY "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") + 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) + + if( RMLUI_TRACY_CONFIGURATION ) + EnableConfigurationType(Tracy ON) + list(APPEND CMAKE_MAP_IMPORTED_CONFIG_TRACY Release) + set(CMAKE_C_FLAGS_TRACY "${CMAKE_C_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_EXE_LINKER_FLAGS_TRACY "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") + set(CMAKE_SHARED_LINKER_FLAGS_TRACY "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") + else() + EnableConfigurationType(Tracy OFF) + endif() + endif() + + if(NOT TARGET Tracy::TracyClient) + find_package(Tracy QUIET) + endif() + + if(NOT TARGET Tracy::TracyClient) + message("Trying to add Tracy from subdirectory 'Dependencies/tracy'.") + add_subdirectory("Dependencies/tracy") + endif() + + 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( CMAKE_CONFIGURATION_TYPES AND RMLUI_TRACY_CONFIGURATION ) message("-- Tracy profiling enabled in configuration 'Tracy'.") + set(RMLUI_TRACY_CONDITION "$") else() message("-- Tracy profiling enabled.") - list(APPEND CORE_PUBLIC_DEFS -DRMLUI_ENABLE_PROFILING) + set(RMLUI_TRACY_CONDITION "1") + endif() + + list(APPEND CORE_PUBLIC_LINK_LIBS "$<${RMLUI_TRACY_CONDITION}:Tracy::TracyClient>") + list(APPEND CORE_PUBLIC_DEFS "$<${RMLUI_TRACY_CONDITION}:RMLUI_TRACY_PROFILING>") + if(RMLUI_TRACY_MEMORY_PROFILING) + list(APPEND CORE_PRIVATE_DEFS "$<${RMLUI_TRACY_CONDITION}:RMLUI_TRACY_MEMORY_PROFILING>") endif() elseif( CMAKE_CONFIGURATION_TYPES ) - list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES Tracy) + EnableConfigurationType(Tracy OFF) endif() option(ENABLE_LOTTIE_PLUGIN "Enable plugin for Lottie animations. Requires the rlottie library." OFF) @@ -600,12 +635,14 @@ if(NOT BUILD_FRAMEWORK) target_include_directories(RmlCore PRIVATE ${CORE_INCLUDE_DIRS}) target_include_directories(RmlCore INTERFACE $ $) target_link_libraries(RmlCore PRIVATE ${CORE_LINK_LIBS}) + target_link_libraries(RmlCore PUBLIC ${CORE_PUBLIC_LINK_LIBS}) target_link_libraries(RmlDebugger RmlCore) target_compile_definitions(RmlCore PRIVATE ${CORE_PRIVATE_DEFS}) target_compile_definitions(RmlCore PUBLIC ${CORE_PUBLIC_DEFS}) else() target_include_directories(RmlUi PRIVATE ${CORE_INCLUDE_DIRS}) target_link_libraries(RmlUi PRIVATE ${CORE_LINK_LIBS}) + target_link_libraries(RmlUi PUBLIC ${CORE_PUBLIC_LINK_LIBS}) target_compile_definitions(RmlUi PRIVATE ${CORE_PRIVATE_DEFS}) target_compile_definitions(RmlUi PUBLIC ${CORE_PUBLIC_DEFS}) endif() diff --git a/Include/RmlUi/Core/Profiling.h b/Include/RmlUi/Core/Profiling.h index 94d733ead..d7caff058 100644 --- a/Include/RmlUi/Core/Profiling.h +++ b/Include/RmlUi/Core/Profiling.h @@ -29,9 +29,8 @@ #ifndef RMLUI_CORE_PROFILING_H #define RMLUI_CORE_PROFILING_H -#ifdef RMLUI_ENABLE_PROFILING +#ifdef RMLUI_TRACY_PROFILING - #define TRACY_ENABLE #include #define RMLUI_ZoneNamed(varname, active) ZoneNamed(varname, active) diff --git a/Source/Core/Element.cpp b/Source/Core/Element.cpp index aa6e8b474..568326525 100644 --- a/Source/Core/Element.cpp +++ b/Source/Core/Element.cpp @@ -153,7 +153,7 @@ Element::~Element() void Element::Update(float dp_ratio, Vector2f vp_dimensions) { -#ifdef RMLUI_ENABLE_PROFILING +#ifdef RMLUI_TRACY_PROFILING auto name = GetAddress(false, false); RMLUI_ZoneScoped; RMLUI_ZoneText(name.c_str(), name.size()); @@ -213,7 +213,7 @@ void Element::UpdateProperties(const float dp_ratio, const Vector2f vp_dimension void Element::Render() { -#ifdef RMLUI_ENABLE_PROFILING +#ifdef RMLUI_TRACY_PROFILING auto name = GetAddress(false, false); RMLUI_ZoneScoped; RMLUI_ZoneText(name.c_str(), name.size()); diff --git a/Source/Core/Layout/BlockFormattingContext.cpp b/Source/Core/Layout/BlockFormattingContext.cpp index b52b36dc9..40783976f 100644 --- a/Source/Core/Layout/BlockFormattingContext.cpp +++ b/Source/Core/Layout/BlockFormattingContext.cpp @@ -116,7 +116,7 @@ UniquePtr BlockFormattingContext::Format(ContainerBox* parent_contain { RMLUI_ASSERT(parent_container && element); -#ifdef RMLUI_ENABLE_PROFILING +#ifdef RMLUI_TRACY_PROFILING RMLUI_ZoneScopedC(0xB22222); auto name = CreateString(80, "%s %x", element->GetAddress(false, false).c_str(), element); RMLUI_ZoneName(name.c_str(), name.size()); @@ -212,7 +212,7 @@ bool BlockFormattingContext::FormatInlineBox(BlockContainer* parent_container, E bool BlockFormattingContext::FormatBlockContainerChild(BlockContainer* parent_container, Element* element) { -#ifdef RMLUI_ENABLE_PROFILING +#ifdef RMLUI_TRACY_PROFILING RMLUI_ZoneScoped; auto name = CreateString(80, ">%s %x", element->GetAddress(false, false).c_str(), element); RMLUI_ZoneName(name.c_str(), name.size()); diff --git a/Source/Core/Profiling.cpp b/Source/Core/Profiling.cpp index ed4933f7a..741cb080a 100644 --- a/Source/Core/Profiling.cpp +++ b/Source/Core/Profiling.cpp @@ -28,8 +28,7 @@ #include "../../Include/RmlUi/Core/Profiling.h" -#ifdef RMLUI_ENABLE_PROFILING - #include +#ifdef RMLUI_TRACY_MEMORY_PROFILING #include void* operator new(std::size_t n)