Skip to content

Commit da8cfe5

Browse files
committed
Add toolchain files from exemplar, preserving history
This merge commit adds all the CMake toolchain files developed as part of beman.exemplar, and preserves rewritten copies of all the commits that updated the toolchain files by applying a git filter-repo command.
2 parents a3841f4 + 22c4122 commit da8cfe5

File tree

5 files changed

+330
-0
lines changed

5 files changed

+330
-0
lines changed

cmake/appleclang-toolchain.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
# This toolchain file is not meant to be used directly,
4+
# but to be invoked by CMake preset and GitHub CI.
5+
#
6+
# This toolchain file configures for apple clang family of compiler.
7+
# Note this is different from LLVM toolchain.
8+
#
9+
# BEMAN_BUILDSYS_SANITIZER:
10+
# This optional CMake parameter is not meant for public use and is subject to
11+
# change.
12+
# Possible values:
13+
# - MaxSan: configures clang and clang++ to use all available non-conflicting
14+
# sanitizers. Note that apple clang does not support leak sanitizer.
15+
# - TSan: configures clang and clang++ to enable the use of thread sanitizer.
16+
17+
include_guard(GLOBAL)
18+
19+
# Prevent PATH collision with an LLVM clang installation by using the system
20+
# compiler shims
21+
set(CMAKE_C_COMPILER cc)
22+
set(CMAKE_CXX_COMPILER c++)
23+
24+
if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
25+
set(SANITIZER_FLAGS
26+
"-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
27+
)
28+
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
29+
set(SANITIZER_FLAGS "-fsanitize=thread")
30+
endif()
31+
32+
set(CMAKE_C_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
33+
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
34+
35+
set(RELEASE_FLAGS "-O3 ${SANITIZER_FLAGS}")
36+
37+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
38+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
39+
40+
set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")
41+
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")

cmake/gnu-toolchain.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
# This toolchain file is not meant to be used directly,
4+
# but to be invoked by CMake preset and GitHub CI.
5+
#
6+
# This toolchain file configures for GNU family of compiler.
7+
#
8+
# BEMAN_BUILDSYS_SANITIZER:
9+
# This optional CMake parameter is not meant for public use and is subject to
10+
# change.
11+
# Possible values:
12+
# - MaxSan: configures gcc and g++ to use all available non-conflicting
13+
# sanitizers.
14+
# - TSan: configures gcc and g++ to enable the use of thread sanitizer
15+
16+
include_guard(GLOBAL)
17+
18+
set(CMAKE_C_COMPILER gcc)
19+
set(CMAKE_CXX_COMPILER g++)
20+
21+
if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
22+
set(SANITIZER_FLAGS
23+
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined -fsanitize-undefined-trap-on-error"
24+
)
25+
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
26+
set(SANITIZER_FLAGS "-fsanitize=thread")
27+
endif()
28+
29+
set(CMAKE_C_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
30+
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
31+
32+
set(RELEASE_FLAGS "-O3 ${SANITIZER_FLAGS}")
33+
34+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
35+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
36+
37+
set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")
38+
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")

cmake/llvm-toolchain.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
# This toolchain file is not meant to be used directly,
4+
# but to be invoked by CMake preset and GitHub CI.
5+
#
6+
# This toolchain file configures for LLVM family of compiler.
7+
#
8+
# BEMAN_BUILDSYS_SANITIZER:
9+
# This optional CMake parameter is not meant for public use and is subject to
10+
# change.
11+
# Possible values:
12+
# - MaxSan: configures clang and clang++ to use all available non-conflicting
13+
# sanitizers.
14+
# - TSan: configures clang and clang++ to enable the use of thread sanitizer.
15+
16+
include_guard(GLOBAL)
17+
18+
set(CMAKE_C_COMPILER clang)
19+
set(CMAKE_CXX_COMPILER clang++)
20+
21+
if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
22+
set(SANITIZER_FLAGS
23+
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined -fsanitize-undefined-trap-on-error"
24+
)
25+
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
26+
set(SANITIZER_FLAGS "-fsanitize=thread")
27+
endif()
28+
29+
set(CMAKE_C_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
30+
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
31+
32+
set(RELEASE_FLAGS "-O3 ${SANITIZER_FLAGS}")
33+
34+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
35+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
36+
37+
set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")
38+
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")

cmake/msvc-toolchain.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
# This toolchain file is not meant to be used directly,
4+
# but to be invoked by CMake preset and GitHub CI.
5+
#
6+
# This toolchain file configures for MSVC family of compiler.
7+
#
8+
# BEMAN_BUILDSYS_SANITIZER:
9+
# This optional CMake parameter is not meant for public use and is subject to
10+
# change.
11+
# Possible values:
12+
# - MaxSan: configures cl to use all available non-conflicting sanitizers.
13+
#
14+
# Note that in other toolchain files, TSan is also a possible value for
15+
# BEMAN_BUILDSYS_SANITIZER, however, MSVC does not support thread sanitizer,
16+
# thus this value is omitted.
17+
18+
include_guard(GLOBAL)
19+
20+
set(CMAKE_C_COMPILER cl)
21+
set(CMAKE_CXX_COMPILER cl)
22+
23+
if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
24+
# /Zi flag (add debug symbol) is needed when using address sanitizer
25+
# See C5072: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-c5072
26+
set(SANITIZER_FLAGS "/fsanitize=address /Zi")
27+
endif()
28+
29+
set(CMAKE_CXX_FLAGS_DEBUG_INIT "/EHsc /permissive- ${SANITIZER_FLAGS}")
30+
set(CMAKE_C_FLAGS_DEBUG_INIT "/EHsc /permissive- ${SANITIZER_FLAGS}")
31+
32+
set(RELEASE_FLAGS "/EHsc /permissive- /O2 ${SANITIZER_FLAGS}")
33+
34+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
35+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAGS}")
36+
37+
set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")
38+
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAGS}")

cmake/use-fetch-content.cmake

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
include(FetchContent)
4+
5+
if(NOT BEMAN_EXEMPLAR_LOCKFILE)
6+
set(BEMAN_EXEMPLAR_LOCKFILE
7+
"lockfile.json"
8+
CACHE FILEPATH
9+
"Path to the dependency lockfile for the Beman Exemplar."
10+
)
11+
endif()
12+
13+
set(BemanExemplar_projectDir "${CMAKE_CURRENT_LIST_DIR}/..")
14+
message(TRACE "BemanExemplar_projectDir=\"${BemanExemplar_projectDir}\"")
15+
16+
message(TRACE "BEMAN_EXEMPLAR_LOCKFILE=\"${BEMAN_EXEMPLAR_LOCKFILE}\"")
17+
file(
18+
REAL_PATH
19+
"${BEMAN_EXEMPLAR_LOCKFILE}"
20+
BemanExemplar_lockfile
21+
BASE_DIRECTORY "${BemanExemplar_projectDir}"
22+
EXPAND_TILDE
23+
)
24+
message(DEBUG "Using lockfile: \"${BemanExemplar_lockfile}\"")
25+
26+
# Force CMake to reconfigure the project if the lockfile changes
27+
set_property(
28+
DIRECTORY "${BemanExemplar_projectDir}"
29+
APPEND
30+
PROPERTY CMAKE_CONFIGURE_DEPENDS "${BemanExemplar_lockfile}"
31+
)
32+
33+
# For more on the protocol for this function, see:
34+
# https://cmake.org/cmake/help/latest/command/cmake_language.html#provider-commands
35+
function(BemanExemplar_provideDependency method package_name)
36+
# Read the lockfile
37+
file(READ "${BemanExemplar_lockfile}" BemanExemplar_rootObj)
38+
39+
# Get the "dependencies" field and store it in BemanExemplar_dependenciesObj
40+
string(
41+
JSON
42+
BemanExemplar_dependenciesObj
43+
ERROR_VARIABLE BemanExemplar_error
44+
GET "${BemanExemplar_rootObj}"
45+
"dependencies"
46+
)
47+
if(BemanExemplar_error)
48+
message(FATAL_ERROR "${BemanExemplar_lockfile}: ${BemanExemplar_error}")
49+
endif()
50+
51+
# Get the length of the libraries array and store it in BemanExemplar_dependenciesObj
52+
string(
53+
JSON
54+
BemanExemplar_numDependencies
55+
ERROR_VARIABLE BemanExemplar_error
56+
LENGTH "${BemanExemplar_dependenciesObj}"
57+
)
58+
if(BemanExemplar_error)
59+
message(FATAL_ERROR "${BemanExemplar_lockfile}: ${BemanExemplar_error}")
60+
endif()
61+
62+
# Loop over each dependency object
63+
math(EXPR BemanExemplar_maxIndex "${BemanExemplar_numDependencies} - 1")
64+
foreach(BemanExemplar_index RANGE "${BemanExemplar_maxIndex}")
65+
set(BemanExemplar_errorPrefix
66+
"${BemanExemplar_lockfile}, dependency ${BemanExemplar_index}"
67+
)
68+
69+
# Get the dependency object at BemanExemplar_index
70+
# and store it in BemanExemplar_depObj
71+
string(
72+
JSON
73+
BemanExemplar_depObj
74+
ERROR_VARIABLE BemanExemplar_error
75+
GET "${BemanExemplar_dependenciesObj}"
76+
"${BemanExemplar_index}"
77+
)
78+
if(BemanExemplar_error)
79+
message(
80+
FATAL_ERROR
81+
"${BemanExemplar_errorPrefix}: ${BemanExemplar_error}"
82+
)
83+
endif()
84+
85+
# Get the "name" field and store it in BemanExemplar_name
86+
string(
87+
JSON
88+
BemanExemplar_name
89+
ERROR_VARIABLE BemanExemplar_error
90+
GET "${BemanExemplar_depObj}"
91+
"name"
92+
)
93+
if(BemanExemplar_error)
94+
message(
95+
FATAL_ERROR
96+
"${BemanExemplar_errorPrefix}: ${BemanExemplar_error}"
97+
)
98+
endif()
99+
100+
# Get the "package_name" field and store it in BemanExemplar_pkgName
101+
string(
102+
JSON
103+
BemanExemplar_pkgName
104+
ERROR_VARIABLE BemanExemplar_error
105+
GET "${BemanExemplar_depObj}"
106+
"package_name"
107+
)
108+
if(BemanExemplar_error)
109+
message(
110+
FATAL_ERROR
111+
"${BemanExemplar_errorPrefix}: ${BemanExemplar_error}"
112+
)
113+
endif()
114+
115+
# Get the "git_repository" field and store it in BemanExemplar_repo
116+
string(
117+
JSON
118+
BemanExemplar_repo
119+
ERROR_VARIABLE BemanExemplar_error
120+
GET "${BemanExemplar_depObj}"
121+
"git_repository"
122+
)
123+
if(BemanExemplar_error)
124+
message(
125+
FATAL_ERROR
126+
"${BemanExemplar_errorPrefix}: ${BemanExemplar_error}"
127+
)
128+
endif()
129+
130+
# Get the "git_tag" field and store it in BemanExemplar_tag
131+
string(
132+
JSON
133+
BemanExemplar_tag
134+
ERROR_VARIABLE BemanExemplar_error
135+
GET "${BemanExemplar_depObj}"
136+
"git_tag"
137+
)
138+
if(BemanExemplar_error)
139+
message(
140+
FATAL_ERROR
141+
"${BemanExemplar_errorPrefix}: ${BemanExemplar_error}"
142+
)
143+
endif()
144+
145+
if(method STREQUAL "FIND_PACKAGE")
146+
if(package_name STREQUAL BemanExemplar_pkgName)
147+
string(
148+
APPEND
149+
BemanExemplar_debug
150+
"Redirecting find_package calls for ${BemanExemplar_pkgName} "
151+
"to FetchContent logic fetching ${BemanExemplar_repo} at "
152+
"${BemanExemplar_tag} according to ${BemanExemplar_lockfile}."
153+
)
154+
message(DEBUG "${BemanExemplar_debug}")
155+
FetchContent_Declare(
156+
"${BemanExemplar_name}"
157+
GIT_REPOSITORY "${BemanExemplar_repo}"
158+
GIT_TAG "${BemanExemplar_tag}"
159+
EXCLUDE_FROM_ALL
160+
)
161+
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
162+
FetchContent_MakeAvailable("${BemanExemplar_name}")
163+
164+
# Important! <PackageName>_FOUND tells CMake that `find_package` is
165+
# not needed for this package anymore
166+
set("${BemanExemplar_pkgName}_FOUND" TRUE PARENT_SCOPE)
167+
endif()
168+
endif()
169+
endforeach()
170+
endfunction()
171+
172+
cmake_language(
173+
SET_DEPENDENCY_PROVIDER BemanExemplar_provideDependency
174+
SUPPORTED_METHODS FIND_PACKAGE
175+
)

0 commit comments

Comments
 (0)