diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/seastar/fmt/test/compile-test/CMakeLists.txt | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/seastar/fmt/test/compile-test/CMakeLists.txt')
-rw-r--r-- | src/seastar/fmt/test/compile-test/CMakeLists.txt | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/seastar/fmt/test/compile-test/CMakeLists.txt b/src/seastar/fmt/test/compile-test/CMakeLists.txt new file mode 100644 index 00000000..75a0c5a5 --- /dev/null +++ b/src/seastar/fmt/test/compile-test/CMakeLists.txt @@ -0,0 +1,79 @@ +# Test if compile errors are produced where necessary. + +cmake_minimum_required(VERSION 3.1.0) + +include(CheckCXXSourceCompiles) +include(CheckCXXCompilerFlag) + +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../../include) +set(CMAKE_REQUIRED_FLAGS ${CXX_STANDARD_FLAG} ${PEDANTIC_COMPILE_FLAGS}) + +function (generate_source result fragment) + set(${result} " + #define FMT_HEADER_ONLY 1 + #include \"fmt/format.h\" + int main() { + ${fragment} + } + " PARENT_SCOPE) +endfunction () + +function (expect_compile code) + generate_source(source "${code}") + check_cxx_source_compiles("${source}" compiles) + if (NOT compiles) + set(error_msg "Compile error for: ${code}") + endif () + # Unset the CMake cache variable compiles. Otherwise the compile test will + # just use cached information next time it runs. + unset(compiles CACHE) + if (error_msg) + message(FATAL_ERROR ${error_msg}) + endif () +endfunction () + +function (expect_compile_error code) + generate_source(source "${code}") + check_cxx_source_compiles("${source}" compiles) + if (compiles) + set(error_msg "No compile error for: ${code}") + endif () + # Unset the CMake cache variable compiles. Otherwise the compile test will + # just use cached information next time it runs. + unset(compiles CACHE) + if (error_msg) + message(FATAL_ERROR ${error_msg}) + endif () +endfunction () + +# check if the source file skeleton compiles +expect_compile("") + +# Formatting a wide character with a narrow format string is forbidden. +expect_compile_error("fmt::format(\"{}\", L'a');") + +# Formatting a wide string with a narrow format string is forbidden. +expect_compile_error("fmt::format(\"{}\", L\"foo\");") + +# Formatting a narrow string with a wide format string is forbidden because +# mixing UTF-8 with UTF-16/32 can result in an invalid output. +expect_compile_error("fmt::format(L\"{}\", \"foo\");") + +# Formatting a wide string with a narrow format string is forbidden. +expect_compile_error(" + struct S { + operator std::string() const { return std::string(); } + }; + fmt::format(\"{}\", S()); +") + +# Make sure that compiler features detected in the header +# match the features detected in CMake. +if (SUPPORTS_USER_DEFINED_LITERALS) + set(supports_udl 1) +else () + set(supports_udl 0) +endif () +expect_compile("#if FMT_USE_USER_DEFINED_LITERALS != ${supports_udl} + # error + #endif") |