-
Notifications
You must be signed in to change notification settings - Fork 47
/
tracy.cmake
124 lines (115 loc) · 3.44 KB
/
tracy.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright (C) 2024 INRIA.
#
# This program is free software: you can redistribute it and/or modify it under
# 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 Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
# .rst:
# ~~~
# .. command:: GENERATE_TRACY_HEADER (
# INCLUDE_DIR <include_dir>
# HEADER_DIR <header_dir>
# FILENAME <filename>
# LIBRARY_NAME <library_name>
# TRACY_ENABLE <tracy_enable>)
# ~~~
#
# This function generates a tracy wrapper header at
# ``<include_dir>/<header_dir>/<filename>``.
#
# If INSTALL_GENERATED_HEADERS is ON, the configuration header will be installed
# in
# ``${CMAKE_INSTALL_INCLUDEDIR}/<header_dir>``.
#
# :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
)
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.hh.cmake
${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()
# .rst:
#
# Read project parameters to generate tracy header
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")
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)
_generate_tracy_header(
INCLUDE_DIR
${PROJECT_BINARY_DIR}/include
HEADER_DIR
${HEADER_DIR}
FILENAME
tracy.${HEADER_EXTENSION}
LIBRARY_NAME
${PACKAGE_CPPNAME}
TRACY_ENABLE
${${PACKAGE_CPPNAME}_TRACY_ENABLE}
)
endfunction()
option(${PACKAGE_CPPNAME}_TRACY_ENABLE "Enable Tracy." OFF)
_setup_tracy_header()