Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# gersemi: on

cmake_minimum_required(VERSION 3.30...4.3)
cmake_minimum_required(VERSION 3.30...4.4)

include(./cmake/prelude.cmake)

Expand Down
22 changes: 11 additions & 11 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"BEMAN_USE_MODULES": true,
"BEMAN_USE_STD_MODULE": true,
"CMAKE_CXX_STANDARD": "23",
"CMAKE_CXX_EXTENSIONS": true,
"CMAKE_CXX_EXTENSIONS": false,
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_INSTALL_MESSAGE": "LAZY",
"CMAKE_SKIP_TEST_ALL_DEPENDENCY": false,
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "infra/cmake/use-fetch-content.cmake"
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "${sourceDir}/infra/cmake/use-fetch-content.cmake"
}
},
{
Expand Down Expand Up @@ -52,7 +52,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/gnu-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/gnu-toolchain.cmake"
}
},
{
Expand All @@ -63,7 +63,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/gnu-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/gnu-toolchain.cmake"
}
},
{
Expand All @@ -74,8 +74,8 @@
"_debug-base"
],
"cacheVariables": {
"BEMAN_USE_STD_MODULE": false,
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-libc++-toolchain.cmake"
"BEMAN_USE_STD_MODULE": true,
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/llvm-libc++-toolchain.cmake"
},
"environment": {
"CXX": "clang++",
Expand All @@ -91,7 +91,7 @@
],
"cacheVariables": {
"BEMAN_USE_STD_MODULE": false,
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-libc++-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/llvm-libc++-toolchain.cmake"
},
"environment": {
"CXX": "clang++",
Expand All @@ -109,7 +109,7 @@
"cacheVariables": {
"BEMAN_USE_STD_MODULE": false,
"BEMAN_USE_MODULES": false,
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/appleclang-toolchain.cmake"
}
},
{
Expand All @@ -123,7 +123,7 @@
"cacheVariables": {
"BEMAN_USE_STD_MODULE": false,
"BEMAN_USE_MODULES": false,
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/appleclang-toolchain.cmake"
}
},
{
Expand All @@ -134,7 +134,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/msvc-toolchain.cmake"
},
"condition": {
"type": "equals",
Expand All @@ -150,7 +150,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/infra/cmake/msvc-toolchain.cmake"
},
"condition": {
"type": "equals",
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ build build-interface:
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-D CMAKE_SKIP_INSTALL_RULES=ON \
-D CMAKE_CXX_STANDARD=23 \
-D CMAKE_CXX_EXTENSIONS=ON \
-D CMAKE_CXX_EXTENSIONS=OFF \
-D CMAKE_CXX_STANDARD_REQUIRED=ON \
-D BEMAN_USE_MODULES=OFF \
-D BEMAN_USE_STD_MODULE=OFF \
Expand All @@ -184,7 +184,7 @@ module build-module:
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-D CMAKE_SKIP_INSTALL_RULES=OFF \
-D CMAKE_CXX_STANDARD=23 \
-D CMAKE_CXX_EXTENSIONS=ON \
-D CMAKE_CXX_EXTENSIONS=OFF \
-D CMAKE_CXX_STANDARD_REQUIRED=ON \
-D BEMAN_USE_MODULES=ON \
-D BEMAN_USE_STD_MODULE=ON \
Expand All @@ -204,13 +204,13 @@ CMakeUserPresets.json:: cmake/CMakeUserPresets.json
ln -s $< $@

# ==========================================================
appleclang-release llvm-release release:
appleclang-release llvm-release gcc-release release:
cmake --preset $@ --log-level=TRACE # XXX --fresh
ln -fs $(BUILDROOT)/$@/compile_commands.json .
cmake --workflow --preset $@

# ==========================================================
appleclang-debug llvm-debug debug:
appleclang-debug llvm-debug gcc-debug debug:
cmake --preset $@ --log-level=TRACE # XXX --fresh
ln -fs $(BUILDROOT)build/$@/compile_commands.json .
cmake --workflow --preset $@
Expand Down
18 changes: 6 additions & 12 deletions cmake/prelude.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,19 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.2 AND CMAKE_VERSION VERSION_LESS 4.4)
)
endif()
endif()

# ---------------------------------------------------------------------------
# check if import std; is supported by CMAKE_CXX_COMPILER
# ---------------------------------------------------------------------------
if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.3 AND CMAKE_VERSION VERSION_LESS 4.4)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "451f2fe2-a8a2-47c3-bc32-94786d8fc91b")
elseif(CMAKE_VERSION VERSION_GREATER_EQUAL 4.2 AND CMAKE_VERSION VERSION_LESS 4.3)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")
endif()
# gersemi: on

# ---------------------------------------------------------------------------
# TODO(CK): Do we need this HACK still for linux too?
# ---------------------------------------------------------------------------
include(
${CMAKE_CURRENT_LIST_DIR}/../infra/cmake/enable-experimental-import-std.cmake
)

if(NOT APPLE)
return()
endif()

# ---------------------------------------------------------------------------
# FIXME: clang++ we still needs to export CXX=clang++
# ---------------------------------------------------------------------------
if("$ENV{CXX}" STREQUAL "" AND CMAKE_CXX_COMPILER)
message(WARNING "\$CXX is not set")
set(ENV{CXX} ${CMAKE_CXX_COMPILER})
Expand Down
2 changes: 1 addition & 1 deletion cmake/presets/CMakeGenericPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"BEMAN_USE_MODULES": true,
"BEMAN_USE_STD_MODULE": true,
"CMAKE_CXX_STANDARD": "23",
"CMAKE_CXX_EXTENSIONS": true,
"CMAKE_CXX_EXTENSIONS": false,
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_INSTALL_MESSAGE": "LAZY",
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# gersemi: on

cmake_minimum_required(VERSION 3.30...4.3)
cmake_minimum_required(VERSION 3.30...4.4)

include(../cmake/prelude.cmake)

Expand Down
2 changes: 1 addition & 1 deletion infra/.beman_submodule
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[beman_submodule]
remote=https://github.com/bemanproject/infra.git
commit_hash=63cb577f6484f13ce3349de49ad5ce27e20bf1da
commit_hash=7b66b858d7f48428fca936184aef2bd246ccc81a
2 changes: 1 addition & 1 deletion infra/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ednolan @neatudarius @rishyak @wusatosi @JeffGarland
* @ednolan @rishyak @wusatosi @JeffGarland
1 change: 1 addition & 0 deletions infra/.github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
name: Lint Check (pre-commit)

on:
Expand Down
7 changes: 4 additions & 3 deletions infra/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand All @@ -8,13 +9,13 @@ repos:
- id: check-added-large-files

- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
rev: v2.4.2
hooks:
- id: codespell

# CMake linting and formatting
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.22.3
- repo: https://github.com/BlankSpruce/gersemi-pre-commit
rev: 0.27.2
hooks:
- id: gersemi
name: CMake linting
Expand Down
38 changes: 36 additions & 2 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This repository is intended to be used as a beman-submodule in other Beman repos
#### `beman_install_library`

The CMake modules in this repository are intended to be used by Beman libraries. Use the
`beman_add_install_library_config()` function to install your library, along with header
`beman_install_library()` function to install your library, along with header
files, any metadata files, and a CMake config file for `find_package()` support.

```cmake
Expand All @@ -31,7 +31,7 @@ add_library(beman::something ALIAS beman.something)

# ... configure your target as needed ...

find_package(beman-install-library REQUIRED)
include(infra/cmake/beman-install-library.cmake)
beman_install_library(beman.something)
```

Expand All @@ -52,3 +52,37 @@ Some options for the project and target will also be supported:
* `BEMAN_INSTALL_CONFIG_FILE_PACKAGES` - a list of package names (e.g., `beman.something`) for which to install the config file
(default: all packages)
* `<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`.

# BuildTelemetry

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.

Telemetry may be enabled in several ways:

## `include`

```cmake
include (infra/cmake/BuildTelemetry.cmake)
configure_build_telemetry()
```

## `find_package`

```cmake
find_package(BuildTelemetry)
configure_build_telemetry()
```

as long as [BuildTelemetryConfig.cmake](./cmake/BuildTelemetryConfig.cmake) is in your module path.

## `CMAKE_PROJECT_TOP_LEVEL_INCLUDES`
A non-invasive way to inject this telemetry into a CMake build you do not want to modify.
Add:
```sh
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=infra/cmake/BuildTelemetry.cmake
```
To the cmake invocation.

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.

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.
5 changes: 5 additions & 0 deletions infra/cmake/BuildTelemetry.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
include_guard(GLOBAL)

include(${CMAKE_CURRENT_LIST_DIR}/BuildTelemetryConfig.cmake)
configure_build_telemetry()
59 changes: 59 additions & 0 deletions infra/cmake/BuildTelemetryConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
include_guard(GLOBAL)

set(BUILD_TELEMETRY_DIR ${CMAKE_CURRENT_LIST_DIR})

function(configure_build_telemetry)
if(NOT BUILD_TELEMETRY_CONFIGURATION)
# Check if the CMake version is at least 4.3
if(CMAKE_VERSION VERSION_LESS "4.3")
message(
STATUS
"CMake version is less than 4.3, configuring cmake_instrumentation is unavailable."
)
return()
else()
message(STATUS "Configuring Build Telemetry")
endif()

# Find bash and jq for the telemetry callback script.
# On Windows, Git for Windows provides bash if available.
find_program(BEMAN_BASH bash)
find_program(BEMAN_JQ jq)
if(NOT BEMAN_BASH OR NOT BEMAN_JQ)
message(
STATUS
"bash or jq not found, build telemetry disabled on this platform."
)
return()
endif()

# Telemetry query
cmake_instrumentation(
API_VERSION 1
DATA_VERSION 1
OPTIONS staticSystemInformation dynamicSystemInformation trace
HOOKS
postGenerate
preBuild
postBuild
preCMakeBuild
postCMakeBuild
postCMakeInstall
postCTest
CALLBACK ${BEMAN_BASH}
${BUILD_TELEMETRY_DIR}/telemetry.sh
)
message(
DEBUG
"using callback script ${BUILD_TELEMETRY_DIR}/telemetry.sh via ${BEMAN_BASH}"
)

# Mark configuration as done in cache
set(BUILD_TELEMETRY_CONFIGURATION
TRUE
CACHE INTERNAL
"Flag to ensure Build Telemetry configured only once"
)
endif()
endfunction(configure_build_telemetry)
8 changes: 4 additions & 4 deletions infra/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# cmake/Config.cmake.in -*-makefile-*-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# cmake/Config.cmake.in -*-makefile-*-

include(CMakeFindDependencyMacro)

@BEMAN_FIND_DEPENDENCIES@
@BEMAN_INSTALL_FIND_DEPENDENCIES@

@PACKAGE_INIT@

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

check_required_components(@PROJECT_NAME@)
check_required_components(@BEMAN_INSTALL_BASE_PKG_NAME@)
Loading
Loading