Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracy.cmake #712

Merged
merged 8 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions tracy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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 <http://www.gnu.org/licenses/>.
jorisv marked this conversation as resolved.
Show resolved Hide resolved

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()
33 changes: 33 additions & 0 deletions tracy.hpp.in
jorisv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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 <tracy/Tracy.hpp>
#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)
jorisv marked this conversation as resolved.
Show resolved Hide resolved
#endif

#endif // @LIBRARY_NAME@_TRACY_HPP
Loading