From 7f9961777c30160a69d145cdbedd6fbec5d5953a Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 14:02:45 +0200 Subject: [PATCH 1/8] tracy: Add tracy.cmake that will generate macro to easily build project with or without tracy --- tracy.cmake | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tracy.hpp.in | 33 +++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 tracy.cmake create mode 100644 tracy.hpp.in diff --git a/tracy.cmake b/tracy.cmake new file mode 100644 index 000000000..8619a3ac1 --- /dev/null +++ b/tracy.cmake @@ -0,0 +1,68 @@ +# Copyright (C) 2024 INRIA. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + + +function(_GENERATE_TRACY_HEADER) + set(options) + set(oneValueArgs INCLUDE_DIR HEADER_DIR FILENAME LIBRARY_NAME TRACY_ENABLE) + set(multiValueArgs) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN}) + + # Set variables for configure_file command + set(LIBRARY_NAME ${ARGS_LIBRARY_NAME}) + # Activate/Deactivate Tracy macro definition + if(ARGS_TRACY_ENABLE) + set(DEFINE_TRACY_ENABLE "#define ${LIBRARY_NAME}_TRACY_ENABLE") + else() + set(DEFINE_TRACY_ENABLE) + endif() + + configure_file(${PROJECT_JRL_CMAKE_MODULE_DIR}/tracy.hpp.in + ${ARGS_INCLUDE_DIR}/${ARGS_HEADER_DIR}/${ARGS_FILENAME} @ONLY) + + # Install it if requested. + if(INSTALL_GENERATED_HEADERS) + install( + FILES ${ARGS_INCLUDE_DIR}/${ARGS_HEADER_DIR}/${ARGS_FILENAME} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ARGS_HEADER_DIR} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE) + endif() +endfunction() + +function(_SETUP_TRACY_HEADER) + # Install project headers. + if(DEFINED PROJECT_CUSTOM_HEADER_DIR) + set(HEADER_DIR "${PROJECT_CUSTOM_HEADER_DIR}") + elseif(DEFINED CUSTOM_HEADER_DIR) + set(HEADER_DIR "${CUSTOM_HEADER_DIR}") + else() + string(REGEX REPLACE "[^a-zA-Z0-9]" "/" HEADER_DIR "${PROJECT_NAME}") + endif() + string(TOLOWER "${HEADER_DIR}" "HEADER_DIR") + + string(REGEX REPLACE "[^a-zA-Z0-9]" "_" PACKAGE_CPPNAME "${PROJECT_NAME}") + string(TOUPPER "${PACKAGE_CPPNAME}" PACKAGE_CPPNAME) + + _generate_tracy_header( + INCLUDE_DIR ${PROJECT_BINARY_DIR}/include + HEADER_DIR ${HEADER_DIR} + FILENAME tracy.hpp + LIBRARY_NAME ${PACKAGE_CPPNAME} + TRACY_ENABLE ${${PACKAGE_CPPNAME}_TRACY_ENABLE}) +endfunction() + +option(${PACKAGE_CPPNAME}_TRACY_ENABLE "Enable Tracy." OFF) +_setup_tracy_header() diff --git a/tracy.hpp.in b/tracy.hpp.in new file mode 100644 index 000000000..44f299661 --- /dev/null +++ b/tracy.hpp.in @@ -0,0 +1,33 @@ +/* + * This file has been automatically generated by the jrl-cmakemodules. + * Please see + * https://github.com/jrl-umi3218/jrl-cmakemodules/blob/master/tracy.hpp.in for + * details. + */ + +#ifndef @LIBRARY_NAME@_TRACY_HPP +#define @LIBRARY_NAME@_TRACY_HPP + +@DEFINE_TRACY_ENABLE@ + +#ifdef @LIBRARY_NAME@_TRACY_ENABLE +#if defined(__clang__) || defined(__GNUC__) +#define TracyFunction __PRETTY_FUNCTION__ +#elif defined(_MSC_VER) +#define TracyFunction __FUNCSIG__ +#endif +#include +#define @LIBRARY_NAME@_ZONE_SCOPED_N(name) ZoneScopedN(name) +#define @LIBRARY_NAME@_ZONE_SCOPED ZoneScoped +#define @LIBRARY_NAME@_ZONE_NAMED_N(varname, name, active) ZoneNamedN(varname, name, active) +#define @LIBRARY_NAME@_ZONE_NAMED(varname, active) ZoneNamed(varname, active) +#define @LIBRARY_NAME@_SET_THREAD_NAME(name) tracy::SetThreadName(name) +#else +#define @LIBRARY_NAME@_ZONE_SCOPED_N(x) +#define @LIBRARY_NAME@_ZONE_SCOPED +#define @LIBRARY_NAME@_ZONE_NAMED_N(x, y, z) +#define @LIBRARY_NAME@_ZONE_NAMED(x, y) +#define @LIBRARY_NAME@_SET_THREAD_NAME(x) +#endif + +#endif // @LIBRARY_NAME@_TRACY_HPP From 6dea6e69ab9d6a3282d838a67e61f3416d9290dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:05:43 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tracy.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tracy.cmake b/tracy.cmake index 8619a3ac1..b788c990c 100644 --- a/tracy.cmake +++ b/tracy.cmake @@ -13,7 +13,6 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see . - function(_GENERATE_TRACY_HEADER) set(options) set(oneValueArgs INCLUDE_DIR HEADER_DIR FILENAME LIBRARY_NAME TRACY_ENABLE) @@ -57,11 +56,16 @@ function(_SETUP_TRACY_HEADER) string(TOUPPER "${PACKAGE_CPPNAME}" PACKAGE_CPPNAME) _generate_tracy_header( - INCLUDE_DIR ${PROJECT_BINARY_DIR}/include - HEADER_DIR ${HEADER_DIR} - FILENAME tracy.hpp - LIBRARY_NAME ${PACKAGE_CPPNAME} - TRACY_ENABLE ${${PACKAGE_CPPNAME}_TRACY_ENABLE}) + INCLUDE_DIR + ${PROJECT_BINARY_DIR}/include + HEADER_DIR + ${HEADER_DIR} + FILENAME + tracy.hpp + LIBRARY_NAME + ${PACKAGE_CPPNAME} + TRACY_ENABLE + ${${PACKAGE_CPPNAME}_TRACY_ENABLE}) endfunction() option(${PACKAGE_CPPNAME}_TRACY_ENABLE "Enable Tracy." OFF) From d810d7fe37ed2fbbc0f10585af0377d57ae9a0d4 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 15:30:17 +0200 Subject: [PATCH 3/8] Update tracy.hpp.in Co-authored-by: Wilson --- tracy.hpp.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tracy.hpp.in b/tracy.hpp.in index 44f299661..249d460c3 100644 --- a/tracy.hpp.in +++ b/tracy.hpp.in @@ -17,17 +17,17 @@ #define TracyFunction __FUNCSIG__ #endif #include -#define @LIBRARY_NAME@_ZONE_SCOPED_N(name) ZoneScopedN(name) -#define @LIBRARY_NAME@_ZONE_SCOPED ZoneScoped -#define @LIBRARY_NAME@_ZONE_NAMED_N(varname, name, active) ZoneNamedN(varname, name, active) -#define @LIBRARY_NAME@_ZONE_NAMED(varname, active) ZoneNamed(varname, active) -#define @LIBRARY_NAME@_SET_THREAD_NAME(name) tracy::SetThreadName(name) +#define @LIBRARY_NAME@_TRACY_ZONE_SCOPED_N(name) ZoneScopedN(name) +#define @LIBRARY_NAME@_TRACY_ZONE_SCOPED ZoneScoped +#define @LIBRARY_NAME@_TRACY_ZONE_NAMED_N(varname, name, active) ZoneNamedN(varname, name, active) +#define @LIBRARY_NAME@_TRACY_ZONE_NAMED(varname, active) ZoneNamed(varname, active) +#define @LIBRARY_NAME@_TRACY_SET_THREAD_NAME(name) tracy::SetThreadName(name) #else -#define @LIBRARY_NAME@_ZONE_SCOPED_N(x) -#define @LIBRARY_NAME@_ZONE_SCOPED -#define @LIBRARY_NAME@_ZONE_NAMED_N(x, y, z) -#define @LIBRARY_NAME@_ZONE_NAMED(x, y) -#define @LIBRARY_NAME@_SET_THREAD_NAME(x) +#define @LIBRARY_NAME@_TRACY_ZONE_SCOPED_N(x) +#define @LIBRARY_NAME@_TRACY_ZONE_SCOPED +#define @LIBRARY_NAME@_TRACY_ZONE_NAMED_N(x, y, z) +#define @LIBRARY_NAME@_TRACY_ZONE_NAMED(x, y) +#define @LIBRARY_NAME@_TRACY_SET_THREAD_NAME(x) #endif #endif // @LIBRARY_NAME@_TRACY_HPP From bf1637eb5bd09d402bb2ae3a4f72e231e4a425d8 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 16:11:28 +0200 Subject: [PATCH 4/8] tracy: Use right filename --- tracy.cmake | 2 +- tracy.hpp.in => tracy.hh.cmake | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tracy.hpp.in => tracy.hh.cmake (100%) diff --git a/tracy.cmake b/tracy.cmake index b788c990c..8c8d57f5e 100644 --- a/tracy.cmake +++ b/tracy.cmake @@ -29,7 +29,7 @@ function(_GENERATE_TRACY_HEADER) set(DEFINE_TRACY_ENABLE) endif() - configure_file(${PROJECT_JRL_CMAKE_MODULE_DIR}/tracy.hpp.in + configure_file(${PROJECT_JRL_CMAKE_MODULE_DIR}/tracy.hh.cmake ${ARGS_INCLUDE_DIR}/${ARGS_HEADER_DIR}/${ARGS_FILENAME} @ONLY) # Install it if requested. diff --git a/tracy.hpp.in b/tracy.hh.cmake similarity index 100% rename from tracy.hpp.in rename to tracy.hh.cmake From 85fb98ffc7b8844137ea7e2c92643b952cd1ef9a Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 16:11:46 +0200 Subject: [PATCH 5/8] tracy: Manage generated header extension --- tracy.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tracy.cmake b/tracy.cmake index 8c8d57f5e..e5b2cb004 100644 --- a/tracy.cmake +++ b/tracy.cmake @@ -52,6 +52,12 @@ function(_SETUP_TRACY_HEADER) endif() string(TOLOWER "${HEADER_DIR}" "HEADER_DIR") + if(NOT DEFINED PROJECT_CUSTOM_HEADER_EXTENSION) + set(HEADER_EXTENSION "hh") + else() + set(HEADER_EXTENSION ${PROJECT_CUSTOM_HEADER_EXTENSION}) + endif() + string(REGEX REPLACE "[^a-zA-Z0-9]" "_" PACKAGE_CPPNAME "${PROJECT_NAME}") string(TOUPPER "${PACKAGE_CPPNAME}" PACKAGE_CPPNAME) @@ -61,7 +67,7 @@ function(_SETUP_TRACY_HEADER) HEADER_DIR ${HEADER_DIR} FILENAME - tracy.hpp + tracy.${HEADER_EXTENSION} LIBRARY_NAME ${PACKAGE_CPPNAME} TRACY_ENABLE From 0730259651d9721b19d5700e65bfbe68eece5e82 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 16:11:59 +0200 Subject: [PATCH 6/8] tracy: Set file under LGPL --- tracy.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tracy.cmake b/tracy.cmake index e5b2cb004..1100d8efc 100644 --- a/tracy.cmake +++ b/tracy.cmake @@ -1,17 +1,17 @@ # Copyright (C) 2024 INRIA. # # This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # -# You should have received a copy of the GNU General Public License along with -# this program. If not, see . +# You should have received a copy of the GNU Lesser General Public License along +# with this program. If not, see . function(_GENERATE_TRACY_HEADER) set(options) From a17aef15fceafd8895eda41489d7a7b894c56381 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 16:17:33 +0200 Subject: [PATCH 7/8] tracy: Add documentation --- tracy.cmake | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tracy.cmake b/tracy.cmake index 1100d8efc..d1f52df42 100644 --- a/tracy.cmake +++ b/tracy.cmake @@ -13,6 +13,32 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . +# .rst: +# ~~~ +# .. command:: GENERATE_TRACY_HEADER ( +# INCLUDE_DIR +# HEADER_DIR +# FILENAME +# LIBRARY_NAME +# TRACY_ENABLE ) +# ~~~ +# +# This function generates a tracy wrapper header at +# ``//``. +# +# If INSTALL_GENERATED_HEADERS is ON, the configuration header will be installed +# in +# ``${CMAKE_INSTALL_INCLUDEDIR}/``. +# +# :param INCLUDE_DIR: Include root directory (absolute). +# +# :param HEADER_DIR: Include sub directory. +# +# :param FILENAME: Configuration header name. +# +# :param LIBRARY_NAME: Define prefix, should match the compiled library name. +# +# :param TRACY_ENABLE: Controls if tracy macro are empty or call tracy. function(_GENERATE_TRACY_HEADER) set(options) set(oneValueArgs INCLUDE_DIR HEADER_DIR FILENAME LIBRARY_NAME TRACY_ENABLE) @@ -41,6 +67,9 @@ function(_GENERATE_TRACY_HEADER) endif() endfunction() +# .rst: +# +# Read project parameters to generate tracy header function(_SETUP_TRACY_HEADER) # Install project headers. if(DEFINED PROJECT_CUSTOM_HEADER_DIR) From dfd7f7b2b933c24e2260253ec06865363816586b Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 11 Sep 2024 16:36:57 +0200 Subject: [PATCH 8/8] tracy: Fix header comment --- tracy.hh.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracy.hh.cmake b/tracy.hh.cmake index 249d460c3..1e5527bfd 100644 --- a/tracy.hh.cmake +++ b/tracy.hh.cmake @@ -1,7 +1,7 @@ /* * This file has been automatically generated by the jrl-cmakemodules. * Please see - * https://github.com/jrl-umi3218/jrl-cmakemodules/blob/master/tracy.hpp.in for + * https://github.com/jrl-umi3218/jrl-cmakemodules/blob/master/tracy.hh.cmake for * details. */