-
Notifications
You must be signed in to change notification settings - Fork 52
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
Check for std::format
support in CMake
#891
base: main
Are you sure you want to change the base?
Conversation
Today I tried building traccc with g++12 which broke as acts-project#845 introduced a dependency on `std::format` which is not universally available. In order to provide earlier and more readable errors, this commit adds a configuration-time check to ensure that the C++ compiler supports `std::format`.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's indeed add such code. Just in a slightly higher level way. 😉
message(STATUS "Checking for `std::format` support") | ||
file( WRITE | ||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/compile_test_format.cpp" | ||
"#include <format>\n" | ||
"int main() {\n" | ||
"std::format(\"Hello {}\\n\", \"world\");\n" | ||
"return 0; }\n" ) | ||
try_compile( TRACCCC_INTERNAL_STD_FORMAT_WORKS SOURCES | ||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/compile_test_format.cpp") | ||
|
||
if (NOT TRACCCC_INTERNAL_STD_FORMAT_WORKS) | ||
message(FATAL_ERROR "Examples are enabled, but `std::format` is not supported by the C++ compiler; upgrade to gcc 13 or clang 14 or higher.") | ||
endif() | ||
|
||
unset(TRACCCC_INTERNAL_STD_FORMAT_WORKS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to write such low level code. We have check_cxx_source_compiles(...) for this. Which is used extensively in vecmem for instance. (https://github.com/acts-project/vecmem/blob/main/core/CMakeLists.txt#L208)
I'd propose:
message(STATUS "Checking for `std::format` support") | |
file( WRITE | |
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/compile_test_format.cpp" | |
"#include <format>\n" | |
"int main() {\n" | |
"std::format(\"Hello {}\\n\", \"world\");\n" | |
"return 0; }\n" ) | |
try_compile( TRACCCC_INTERNAL_STD_FORMAT_WORKS SOURCES | |
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/compile_test_format.cpp") | |
if (NOT TRACCCC_INTERNAL_STD_FORMAT_WORKS) | |
message(FATAL_ERROR "Examples are enabled, but `std::format` is not supported by the C++ compiler; upgrade to gcc 13 or clang 14 or higher.") | |
endif() | |
unset(TRACCCC_INTERNAL_STD_FORMAT_WORKS) | |
include(CheckCxxSourceCompiles) | |
check_cxx_source_compiles( " | |
#include <format> | |
int main() { | |
std::format(\"Hello {}\\n\", \"world\"); | |
} | |
" TRACCC_STD_FORMAT_WORKS ) | |
if( NOT TRACCC_STD_FORMAT_WORKS ) | |
message(FATAL_ERROR "Examples are enabled, but `std::format` is not supported by the C++ compiler; upgrade to gcc 13 or clang 14 or higher.") | |
endif() |
Today I tried building traccc with g++12 which broke as #845 introduced a dependency on
std::format
which is not universally available. In order to provide earlier and more readable errors, this commit adds a configuration-time check to ensure that the C++ compiler supportsstd::format
.