Skip to content

Commit 77e2c21

Browse files
authored
Merge pull request #201 from steve-downey/pull-infra
Pull infra
2 parents 92c03b8 + 42e85b0 commit 77e2c21

10 files changed

Lines changed: 113 additions & 73 deletions

infra/.beman_submodule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[beman_submodule]
22
remote=https://github.com/bemanproject/infra.git
3-
commit_hash=63cb577f6484f13ce3349de49ad5ce27e20bf1da
3+
commit_hash=53a1500400203529bd6bc3c39119501a9f63ebea
44
allow_untracked_files=True

infra/README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,36 @@ Some options for the project and target will also be supported:
5353
(default: all packages)
5454
* `<BEMAN_NAME>_INSTALL_CONFIG_FILE_PACKAGE` - a per-project option to enable/disable config file installation (default: `ON` if the project is top-level, `OFF` otherwise). For instance for `beman.something`, the option would be `BEMAN_SOMETHING_INSTALL_CONFIG_FILE_PACKAGE`.
5555

56-
#### `beman_cmake_instrumentation`
56+
# BuildTelemetry
5757

58-
The cmake modules in this library are intended to provide access to CMake instrumentation data in Google Trace format which is visualizable with chrome://tracing and https://ui.perfetto.dev.
58+
The cmake modules in this library provide access to CMake instrumentation data in Google Trace format which is visualizable with chrome://tracing and https://ui.perfetto.dev.
5959

60-
Instrumentation may be enabled either by adding to the CMAKE_PROJECT_TOP_LEVEL_INCLUDES
61-
```sh
62-
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=infra/cmake/bemancmakeinstrumentation.cmake
60+
Telemetry may be enabled in several ways:
61+
62+
## `include`
63+
64+
```cmake
65+
include (infra/cmake/BuildTelemetry.cmake)
66+
configure_build_telemetry()
6367
```
64-
or by calling explicitly within the CMakeList.txt file.
68+
69+
## `find_package`
70+
6571
```cmake
66-
find_package(BemanCMakeInstrumentation)
67-
configure_beman_cmake_instrumentation()
72+
find_package(BuildTelemetry)
73+
configure_build_telemetry()
74+
```
75+
76+
as long as [BuildTelemetryConfig.cmake](./cmake/BuildTelemetryConfig.cmake) is in your module path.
77+
78+
## `CMAKE_PROJECT_TOP_LEVEL_INCLUDES`
79+
A non-invasive way to inject this telemetry into a CMake build you do not want to modify.
80+
Add:
81+
```sh
82+
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=infra/cmake/BuildTelemetry.cmake
6883
```
84+
To the cmake invocation.
6985

70-
In either form, CMake will call `instrumentation.sh` which will copy the trace data in json format into a `.trace` subdirectory within the build directory.
86+
In any form, CMake will call `telemetry.sh` which will copy the trace data in json format into a `.trace` subdirectory within the build directory.
7187

72-
Multiple calls to `configure_beman_cmake_instrumentation` will only configure the callback hooks once, so it is safe to include multiple times, including by TOP_LEVEL_INCLUDE.
88+
Multiple calls to `configure_build_telemetry` will only configure the callback hooks once, so it is safe to enable multiple times, including by TOP_LEVEL_INCLUDE.

infra/cmake/BuildTelemetry.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include_guard(GLOBAL)
2+
3+
include(${CMAKE_CURRENT_LIST_DIR}/BuildTelemetryConfig.cmake)
4+
configure_build_telemetry()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
include_guard(GLOBAL)
2+
3+
set(BUILD_TELEMETRY_DIR ${CMAKE_CURRENT_LIST_DIR})
4+
5+
function(configure_build_telemetry)
6+
if(NOT BUILD_TELEMETRY_CONFIGURATION)
7+
# Check if the CMake version is at least 4.3
8+
if(CMAKE_VERSION VERSION_LESS "4.3")
9+
message(
10+
STATUS
11+
"CMake version is less than 4.3, configuring cmake_instrumentation is unavailable."
12+
)
13+
return()
14+
else()
15+
message(STATUS "Configuring Build Telemetry")
16+
endif()
17+
18+
# Telemetry query
19+
cmake_instrumentation(
20+
API_VERSION 1
21+
DATA_VERSION 1
22+
23+
OPTIONS staticSystemInformation dynamicSystemInformation trace
24+
HOOKS postGenerate preBuild postBuild preCMakeBuild postCMakeBuild postCMakeInstall postCTest
25+
CALLBACK ${BUILD_TELEMETRY_DIR}/telemetry.sh
26+
)
27+
message(
28+
DEBUG
29+
"using callback script ${BUILD_TELEMETRY_DIR}/telemetry.sh"
30+
)
31+
32+
# Mark configuration as done in cache
33+
set(BUILD_TELEMETRY_CONFIGURATION
34+
TRUE
35+
CACHE INTERNAL
36+
"Flag to ensure Build Telemetry configured only once"
37+
)
38+
endif()
39+
endfunction(configure_build_telemetry)

infra/cmake/Config.cmake.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
include(CMakeFindDependencyMacro)
55

6-
@BEMAN_FIND_DEPENDENCIES@
6+
@BEMAN_INSTALL_FIND_DEPENDENCIES@
77

88
@PACKAGE_INIT@
99

10-
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)
10+
include(${CMAKE_CURRENT_LIST_DIR}/@BEMAN_INSTALL_BASE_PKG_NAME@-targets.cmake)
1111

12-
check_required_components(@PROJECT_NAME@)
12+
check_required_components(@BEMAN_INSTALL_BASE_PKG_NAME@)

infra/cmake/beman-install-library.cmake

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ include(GNUInstallDirs)
5656
# HEADERS to the default CMAKE install destination.
5757
#
5858
# It also handles the installation of the CMake config package files if
59-
# needed. If the given targets has FILE_SET CXX_MODULE, it will also
59+
# needed. If the given targets has a PUBLIC FILE_SET CXX_MODULE, it will also
6060
# installed to the given DESTINATION
6161
#
6262
# Cache variables:
@@ -72,7 +72,7 @@ include(GNUInstallDirs)
7272
# Caveats
7373
# -------
7474
#
75-
# **Only one `FILE_SET CXX_MODULES` is yet supported to install with this
75+
# **Only one `PUBLIC FILE_SET CXX_MODULES` is yet supported to install with this
7676
# function!**
7777
#
7878
# **Only header files contained in a `PUBLIC FILE_SET TYPE HEADERS` will be
@@ -86,14 +86,14 @@ function(beman_install_library name)
8686
set(multiValueArgs TARGETS DEPENDENCIES)
8787

8888
cmake_parse_arguments(
89-
BEMAN
89+
BEMAN_INSTALL
9090
"${options}"
9191
"${oneValueArgs}"
9292
"${multiValueArgs}"
9393
${ARGN}
9494
)
9595

96-
if(NOT BEMAN_TARGETS)
96+
if(NOT BEMAN_INSTALL_TARGETS)
9797
message(
9898
FATAL_ERROR
9999
"beman_install_library(${name}): TARGETS must be specified"
@@ -103,7 +103,7 @@ function(beman_install_library name)
103103
if(CMAKE_SKIP_INSTALL_RULES)
104104
message(
105105
WARNING
106-
"beman_install_library(${name}): not installing targets '${BEMAN_TARGETS}' due to CMAKE_SKIP_INSTALL_RULES"
106+
"beman_install_library(${name}): not installing targets '${BEMAN_INSTALL_TARGETS}' due to CMAKE_SKIP_INSTALL_RULES"
107107
)
108108
return()
109109
endif()
@@ -113,16 +113,16 @@ function(beman_install_library name)
113113
# ----------------------------
114114
# Defaults
115115
# ----------------------------
116-
if(NOT BEMAN_NAMESPACE)
117-
set(BEMAN_NAMESPACE "beman::")
116+
if(NOT BEMAN_INSTALL_NAMESPACE)
117+
set(BEMAN_INSTALL_NAMESPACE "beman::")
118118
endif()
119119

120-
if(NOT BEMAN_EXPORT_NAME)
121-
set(BEMAN_EXPORT_NAME "${name}-targets")
120+
if(NOT BEMAN_INSTALL_EXPORT_NAME)
121+
set(BEMAN_INSTALL_EXPORT_NAME "${name}-targets")
122122
endif()
123123

124-
if(NOT BEMAN_DESTINATION)
125-
set(BEMAN_DESTINATION "${_config_install_dir}/modules")
124+
if(NOT BEMAN_INSTALL_DESTINATION)
125+
set(BEMAN_INSTALL_DESTINATION "${_config_install_dir}/modules")
126126
endif()
127127

128128
string(REPLACE "beman." "" install_component_name "${name}")
@@ -134,7 +134,7 @@ function(beman_install_library name)
134134
# --------------------------------------------------
135135
# Install each target with all of its file sets
136136
# --------------------------------------------------
137-
foreach(_tgt IN LISTS BEMAN_TARGETS)
137+
foreach(_tgt IN LISTS BEMAN_INSTALL_TARGETS)
138138
if(NOT TARGET "${_tgt}")
139139
message(
140140
WARNING
@@ -189,24 +189,24 @@ function(beman_install_library name)
189189
set(_install_header_set_args FILE_SET HEADERS) # Note: empty FILE_SET in this case! CK
190190
endif()
191191

192-
# Detect presence of C++ module file sets, exact one expected!
193-
get_target_property(_module_sets "${_tgt}" CXX_MODULE_SETS)
192+
# Detect presence of PUBLIC C++ module file sets. Note: exact one is expected!
193+
get_target_property(_module_sets "${_tgt}" INTERFACE_CXX_MODULE_SETS)
194194
if(_module_sets)
195195
message(
196196
VERBOSE
197-
"beman-install-library(${name}): '${_tgt}' has CXX_MODULE_SETS=${_module_sets}"
197+
"beman-install-library(${name}): '${_tgt}' has INTERFACE_CXX_MODULE_SETS=${_module_sets}"
198198
)
199199
install(
200200
TARGETS "${_tgt}"
201-
EXPORT ${BEMAN_EXPORT_NAME}
201+
EXPORT ${BEMAN_INSTALL_EXPORT_NAME}
202202
ARCHIVE COMPONENT "${install_component_name}_Development"
203203
LIBRARY
204204
COMPONENT "${install_component_name}_Runtime"
205205
NAMELINK_COMPONENT "${install_component_name}_Development"
206206
RUNTIME COMPONENT "${install_component_name}_Runtime"
207207
${_install_header_set_args}
208208
FILE_SET ${_module_sets}
209-
DESTINATION "${BEMAN_DESTINATION}"
209+
DESTINATION "${BEMAN_INSTALL_DESTINATION}"
210210
COMPONENT "${install_component_name}_Development"
211211
# NOTE: There's currently no convention for this location! CK
212212
CXX_MODULES_BMI
@@ -217,7 +217,7 @@ function(beman_install_library name)
217217
else()
218218
install(
219219
TARGETS "${_tgt}"
220-
EXPORT ${BEMAN_EXPORT_NAME}
220+
EXPORT ${BEMAN_INSTALL_EXPORT_NAME}
221221
ARCHIVE COMPONENT "${install_component_name}_Development"
222222
LIBRARY
223223
COMPONENT "${install_component_name}_Runtime"
@@ -233,8 +233,8 @@ function(beman_install_library name)
233233
# --------------------------------------------------
234234
# gersemi: off
235235
install(
236-
EXPORT ${BEMAN_EXPORT_NAME}
237-
NAMESPACE ${BEMAN_NAMESPACE}
236+
EXPORT ${BEMAN_INSTALL_EXPORT_NAME}
237+
NAMESPACE ${BEMAN_INSTALL_NAMESPACE}
238238
CXX_MODULES_DIRECTORY cxx-modules
239239
DESTINATION ${_config_install_dir}
240240
COMPONENT "${install_component_name}_Development"
@@ -279,19 +279,20 @@ function(beman_install_library name)
279279
# expand dependencies
280280
# ----------------------------------------
281281
set(_beman_find_deps "")
282-
foreach(dep IN LISTS BEMAN_DEPENDENCIES)
282+
foreach(dep IN LISTS BEMAN_INSTALL_DEPENDENCIES)
283283
message(
284284
VERBOSE
285285
"beman-install-library(${name}): Add find_dependency(${dep})"
286286
)
287287
string(APPEND _beman_find_deps "find_dependency(${dep})\n")
288288
endforeach()
289-
set(BEMAN_FIND_DEPENDENCIES "${_beman_find_deps}")
289+
set(BEMAN_INSTALL_FIND_DEPENDENCIES "${_beman_find_deps}")
290290

291291
# ----------------------------------------
292292
# Generate + install config files
293293
# ----------------------------------------
294294
if(_install_config)
295+
set(BEMAN_INSTALL_BASE_PKG_NAME ${name})
295296
configure_package_config_file(
296297
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Config.cmake.in"
297298
"${CMAKE_CURRENT_BINARY_DIR}/${name}-config.cmake"

infra/cmake/bemancmakeinstrumentation-config.cmake

Lines changed: 0 additions & 29 deletions
This file was deleted.

infra/cmake/bemancmakeinstrumentation.cmake

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ _ME="$(basename "${0}")"
2929
_print_help() {
3030
cat <<HEREDOC
3131
32-
Callback script to process CMake Instrumentation data
32+
Callback script to process CMake Insrumentation data
3333
https://cmake.org/cmake/help/latest/command/cmake_instrumentation.html
3434
3535
Usage:
@@ -38,14 +38,17 @@ Usage:
3838
3939
Options:
4040
-h --help Show this screen.
41+
42+
Environment:
43+
Setting DEBUG_TELEMETRY in the environment will enable DEBUG logging
4144
HEREDOC
4245
}
4346

4447
###############################################################################
4548
# Program Functions
4649
###############################################################################
4750
_debug_print() {
48-
if [[ -n "${DEBUG:-}" ]]; then
51+
if [[ -n "${DEBUG_TELEMETRY:-}" ]]; then
4952
printf "[DEBUG] $(date +'%H:%M:%S'): %s \n" "$1" >&2
5053
fi
5154
}

infra/cmake/use-fetch-content.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ function(BemanExemplar_provideDependency method package_name)
170170
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
171171
FetchContent_MakeAvailable("${BemanExemplar_name}")
172172

173+
# Catch2's CTest integration module isn't on CMAKE_MODULE_PATH
174+
# when brought in via FetchContent. Add it so that
175+
# `include(Catch)` works.
176+
if(BemanExemplar_pkgName STREQUAL "Catch2")
177+
list(
178+
APPEND
179+
CMAKE_MODULE_PATH
180+
"${${BemanExemplar_name}_SOURCE_DIR}/extras"
181+
)
182+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
183+
endif()
184+
173185
# Important! <PackageName>_FOUND tells CMake that `find_package` is
174186
# not needed for this package anymore
175187
set("${BemanExemplar_pkgName}_FOUND" TRUE PARENT_SCOPE)

0 commit comments

Comments
 (0)