Apply cmake-format
This commit is contained in:
+66
-47
@@ -2,13 +2,13 @@ add_subdirectory(gtest)
|
||||
|
||||
set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc)
|
||||
add_library(test-main STATIC ${TEST_MAIN_SRC})
|
||||
target_include_directories(test-main PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
target_include_directories(
|
||||
test-main PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
target_link_libraries(test-main gtest fmt)
|
||||
|
||||
# Adds a test.
|
||||
# Usage: add_fmt_test(name srcs...)
|
||||
function(add_fmt_test name)
|
||||
function (add_fmt_test name)
|
||||
cmake_parse_arguments(ADD_FMT_TEST "HEADER_ONLY;MODULE" "" "" ${ARGN})
|
||||
|
||||
set(sources ${name}.cc ${ADD_FMT_TEST_UNPARSED_ARGUMENTS})
|
||||
@@ -38,7 +38,7 @@ function(add_fmt_test name)
|
||||
target_compile_options(${name} PRIVATE ${WERROR_FLAG})
|
||||
endif ()
|
||||
add_test(NAME ${name} COMMAND ${name})
|
||||
endfunction()
|
||||
endfunction ()
|
||||
|
||||
add_fmt_test(args-test)
|
||||
add_fmt_test(base-test)
|
||||
@@ -60,10 +60,10 @@ add_fmt_test(ranges-test ranges-odr-test.cc)
|
||||
add_fmt_test(no-builtin-types-test HEADER_ONLY)
|
||||
add_fmt_test(scan-test HEADER_ONLY)
|
||||
add_fmt_test(std-test)
|
||||
try_compile(compile_result_unused
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
SOURCES ${CMAKE_CURRENT_LIST_DIR}/detect-stdfs.cc
|
||||
OUTPUT_VARIABLE RAWOUTPUT)
|
||||
try_compile(
|
||||
compile_result_unused ${CMAKE_CURRENT_BINARY_DIR}
|
||||
SOURCES ${CMAKE_CURRENT_LIST_DIR}/detect-stdfs.cc
|
||||
OUTPUT_VARIABLE RAWOUTPUT)
|
||||
string(REGEX REPLACE ".*libfound \"([^\"]*)\".*" "\\1" STDLIBFS "${RAWOUTPUT}")
|
||||
if (STDLIBFS)
|
||||
target_link_libraries(std-test ${STDLIBFS})
|
||||
@@ -74,8 +74,8 @@ if (MSVC)
|
||||
endif ()
|
||||
add_fmt_test(xchar-test)
|
||||
add_fmt_test(enforce-checks-test)
|
||||
target_compile_definitions(enforce-checks-test PRIVATE
|
||||
-DFMT_ENFORCE_COMPILE_STRING)
|
||||
target_compile_definitions(enforce-checks-test
|
||||
PRIVATE -DFMT_ENFORCE_COMPILE_STRING)
|
||||
|
||||
add_executable(perf-sanity perf-sanity.cc)
|
||||
target_link_libraries(perf-sanity fmt::fmt)
|
||||
@@ -88,20 +88,20 @@ endif ()
|
||||
|
||||
if (NOT DEFINED MSVC_STATIC_RUNTIME AND MSVC)
|
||||
foreach (flag_var
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if (${flag_var} MATCHES "^(/|-)(MT|MTd)")
|
||||
set(MSVC_STATIC_RUNTIME ON)
|
||||
break()
|
||||
endif ()
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if (${flag_var} MATCHES "^(/|-)(MT|MTd)")
|
||||
set(MSVC_STATIC_RUNTIME ON)
|
||||
break()
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
|
||||
if (NOT MSVC_STATIC_RUNTIME)
|
||||
add_executable(posix-mock-test
|
||||
posix-mock-test.cc ../src/format.cc ${TEST_MAIN_SRC})
|
||||
target_include_directories(
|
||||
posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
add_executable(posix-mock-test posix-mock-test.cc ../src/format.cc
|
||||
${TEST_MAIN_SRC})
|
||||
target_include_directories(posix-mock-test
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_link_libraries(posix-mock-test gtest)
|
||||
if (FMT_PEDANTIC)
|
||||
target_compile_options(posix-mock-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||
@@ -123,34 +123,38 @@ if (FMT_PEDANTIC)
|
||||
endif ()
|
||||
if (HAVE_FNO_EXCEPTIONS_FLAG)
|
||||
add_library(noexception-test ../src/format.cc noexception-test.cc)
|
||||
target_include_directories(
|
||||
noexception-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_include_directories(noexception-test
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_compile_options(noexception-test PRIVATE -fno-exceptions)
|
||||
target_compile_options(noexception-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||
endif ()
|
||||
|
||||
# Test that the library compiles without locale.
|
||||
add_library(nolocale-test ../src/format.cc)
|
||||
target_include_directories(
|
||||
nolocale-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_compile_definitions(
|
||||
nolocale-test PRIVATE FMT_STATIC_THOUSANDS_SEPARATOR=1)
|
||||
target_include_directories(nolocale-test
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_compile_definitions(nolocale-test
|
||||
PRIVATE FMT_STATIC_THOUSANDS_SEPARATOR=1)
|
||||
endif ()
|
||||
|
||||
# These tests are disabled on Windows because they take too long.
|
||||
# They are disabled on GCC < 4.9 because it can not parse UDLs without
|
||||
# a space after `operator""` but that is an incorrect syntax for any more
|
||||
# modern compiler.
|
||||
if (FMT_PEDANTIC AND NOT WIN32 AND NOT (
|
||||
CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
|
||||
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
|
||||
# They are disabled on GCC < 4.9 because it can't parse UDLs without a space
|
||||
# after operator"" but that is an incorrect syntax for any more modern compiler.
|
||||
if (FMT_PEDANTIC
|
||||
AND NOT WIN32
|
||||
AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION
|
||||
VERSION_LESS 4.9))
|
||||
# Test if incorrect API usages produce compilation error.
|
||||
add_test(compile-error-test ${CMAKE_CTEST_COMMAND}
|
||||
add_test(
|
||||
compile-error-test
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/compile-error-test"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/compile-error-test"
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-generator
|
||||
${CMAKE_GENERATOR}
|
||||
--build-makeprogram
|
||||
${CMAKE_MAKE_PROGRAM}
|
||||
--build-options
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
|
||||
@@ -159,13 +163,18 @@ if (FMT_PEDANTIC AND NOT WIN32 AND NOT (
|
||||
"-DFMT_DIR=${CMAKE_SOURCE_DIR}")
|
||||
|
||||
# Test if the targets are found from the build directory.
|
||||
add_test(find-package-test ${CMAKE_CTEST_COMMAND}
|
||||
-C ${CMAKE_BUILD_TYPE}
|
||||
add_test(
|
||||
find-package-test
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
-C
|
||||
${CMAKE_BUILD_TYPE}
|
||||
--build-and-test
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/find-package-test"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-generator
|
||||
${CMAKE_GENERATOR}
|
||||
--build-makeprogram
|
||||
${CMAKE_MAKE_PROGRAM}
|
||||
--build-options
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
|
||||
@@ -175,13 +184,18 @@ if (FMT_PEDANTIC AND NOT WIN32 AND NOT (
|
||||
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
||||
|
||||
# Test if the targets are found when add_subdirectory is used.
|
||||
add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND}
|
||||
-C ${CMAKE_BUILD_TYPE}
|
||||
add_test(
|
||||
add-subdirectory-test
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
-C
|
||||
${CMAKE_BUILD_TYPE}
|
||||
--build-and-test
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/add-subdirectory-test"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test"
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-generator
|
||||
${CMAKE_GENERATOR}
|
||||
--build-makeprogram
|
||||
${CMAKE_MAKE_PROGRAM}
|
||||
--build-options
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
||||
@@ -191,13 +205,18 @@ endif ()
|
||||
|
||||
# This test is disabled on Windows because it is POSIX-specific.
|
||||
if (FMT_PEDANTIC AND NOT WIN32)
|
||||
add_test(static-export-test ${CMAKE_CTEST_COMMAND}
|
||||
-C ${CMAKE_BUILD_TYPE}
|
||||
add_test(
|
||||
static-export-test
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
-C
|
||||
${CMAKE_BUILD_TYPE}
|
||||
--build-and-test
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/static-export-test"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/static-export-test"
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-generator
|
||||
${CMAKE_GENERATOR}
|
||||
--build-makeprogram
|
||||
${CMAKE_MAKE_PROGRAM}
|
||||
--build-options
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
cmake_minimum_required(VERSION 3.8...3.25)
|
||||
project(compile-error-test CXX)
|
||||
|
||||
set(fmt_headers "
|
||||
set(fmt_headers
|
||||
"
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/xchar.h>
|
||||
#include <fmt/ostream.h>
|
||||
@@ -13,7 +14,7 @@ set(fmt_headers "
|
||||
set(error_test_names "")
|
||||
set(non_error_test_content "")
|
||||
|
||||
# For error tests (we expect them to produce compilation error):
|
||||
# For error tests (we expect them to produce compilation error)
|
||||
# * adds a name of test into `error_test_names` list
|
||||
# * generates a single source file (with the same name) for each test
|
||||
# For non-error tests (we expect them to compile successfully):
|
||||
@@ -23,64 +24,74 @@ function (expect_compile name code_fragment)
|
||||
string(MAKE_C_IDENTIFIER "${name}" test_name)
|
||||
|
||||
if (EXPECT_COMPILE_ERROR)
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/${test_name}.cc" "
|
||||
file(
|
||||
WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/${test_name}.cc"
|
||||
"
|
||||
${fmt_headers}
|
||||
void ${test_name}() {
|
||||
${code_fragment}
|
||||
}
|
||||
")
|
||||
")
|
||||
set(error_test_names_copy "${error_test_names}")
|
||||
list(APPEND error_test_names_copy "${test_name}")
|
||||
set(error_test_names "${error_test_names_copy}" PARENT_SCOPE)
|
||||
else()
|
||||
set(non_error_test_content "
|
||||
${non_error_test_content}
|
||||
void ${test_name}() {
|
||||
${code_fragment}
|
||||
}" PARENT_SCOPE)
|
||||
endif()
|
||||
set(error_test_names
|
||||
"${error_test_names_copy}"
|
||||
PARENT_SCOPE)
|
||||
else ()
|
||||
set(non_error_test_content
|
||||
"
|
||||
${non_error_test_content}
|
||||
void ${test_name}() {
|
||||
${code_fragment}
|
||||
}"
|
||||
PARENT_SCOPE)
|
||||
endif ()
|
||||
endfunction ()
|
||||
|
||||
# Generates a source file for non-error test with `non_error_test_content` and
|
||||
# CMake project file with all error and single non-error test targets.
|
||||
function (run_tests)
|
||||
set(cmake_targets "")
|
||||
foreach(test_name IN LISTS error_test_names)
|
||||
set(cmake_targets "
|
||||
${cmake_targets}
|
||||
add_library(test-${test_name} ${test_name}.cc)
|
||||
target_link_libraries(test-${test_name} PRIVATE fmt::fmt)
|
||||
")
|
||||
endforeach()
|
||||
foreach (test_name IN LISTS error_test_names)
|
||||
set(cmake_targets
|
||||
"
|
||||
${cmake_targets}
|
||||
add_library(test-${test_name} ${test_name}.cc)
|
||||
target_link_libraries(test-${test_name} PRIVATE fmt::fmt)
|
||||
")
|
||||
endforeach ()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/non_error_test.cc" "
|
||||
file(
|
||||
WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/non_error_test.cc"
|
||||
"
|
||||
${fmt_headers}
|
||||
${non_error_test_content}
|
||||
")
|
||||
set(cmake_targets "
|
||||
${cmake_targets}
|
||||
add_library(non-error-test non_error_test.cc)
|
||||
target_link_libraries(non-error-test PRIVATE fmt::fmt)
|
||||
")
|
||||
")
|
||||
set(cmake_targets
|
||||
"
|
||||
${cmake_targets}
|
||||
add_library(non-error-test non_error_test.cc)
|
||||
target_link_libraries(non-error-test PRIVATE fmt::fmt)
|
||||
")
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/CMakeLists.txt" "
|
||||
file(
|
||||
WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/CMakeLists.txt"
|
||||
"
|
||||
cmake_minimum_required(VERSION 3.8...3.25)
|
||||
project(tests CXX)
|
||||
add_subdirectory(${FMT_DIR} fmt)
|
||||
${cmake_targets}
|
||||
")
|
||||
")
|
||||
|
||||
set(build_directory "${CMAKE_CURRENT_BINARY_DIR}/test/build")
|
||||
file(MAKE_DIRECTORY "${build_directory}")
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}"
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"${CMAKE_COMMAND}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
|
||||
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
||||
"-DCMAKE_GENERATOR=${CMAKE_GENERATOR}"
|
||||
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
|
||||
"-DFMT_DIR=${FMT_DIR}"
|
||||
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}" "-DFMT_DIR=${FMT_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test"
|
||||
WORKING_DIRECTORY "${build_directory}"
|
||||
RESULT_VARIABLE result_var
|
||||
@@ -88,30 +99,32 @@ function (run_tests)
|
||||
ERROR_VARIABLE output_var)
|
||||
if (NOT result_var EQUAL 0)
|
||||
message(FATAL_ERROR "Unable to configure:\n${output_var}")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
foreach(test_name IN LISTS error_test_names)
|
||||
foreach (test_name IN LISTS error_test_names)
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}" --build "${build_directory}" --target "test-${test_name}"
|
||||
COMMAND "${CMAKE_COMMAND}" --build "${build_directory}" --target
|
||||
"test-${test_name}"
|
||||
WORKING_DIRECTORY "${build_directory}"
|
||||
RESULT_VARIABLE result_var
|
||||
OUTPUT_VARIABLE output_var
|
||||
ERROR_QUIET)
|
||||
if (result_var EQUAL 0)
|
||||
message(SEND_ERROR "No compile error for \"${test_name}\":\n${output_var}")
|
||||
message(
|
||||
SEND_ERROR "No compile error for \"${test_name}\":\n${output_var}")
|
||||
endif ()
|
||||
endforeach()
|
||||
endforeach ()
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}" --build "${build_directory}" --target "non-error-test"
|
||||
COMMAND "${CMAKE_COMMAND}" --build "${build_directory}" --target
|
||||
"non-error-test"
|
||||
WORKING_DIRECTORY "${build_directory}"
|
||||
RESULT_VARIABLE result_var
|
||||
OUTPUT_VARIABLE output_var
|
||||
ERROR_VARIABLE output_var)
|
||||
if (NOT result_var EQUAL 0)
|
||||
message(SEND_ERROR "Compile error for combined non-error test:\n${output_var}")
|
||||
message(
|
||||
SEND_ERROR "Compile error for combined non-error test:\n${output_var}")
|
||||
endif ()
|
||||
endfunction ()
|
||||
|
||||
@@ -120,95 +133,133 @@ expect_compile(check "")
|
||||
expect_compile(check-error "compilation_error" ERROR)
|
||||
|
||||
# Formatting a wide character with a narrow format string is forbidden.
|
||||
expect_compile(wide-character-narrow-format-string "fmt::format(L\"{}\", L'a');")
|
||||
expect_compile(wide-character-narrow-format-string-error "fmt::format(\"{}\", L'a');" ERROR)
|
||||
expect_compile(wide-character-narrow-format-string
|
||||
"fmt::format(L\"{}\", L'a');")
|
||||
expect_compile(wide-character-narrow-format-string-error
|
||||
"fmt::format(\"{}\", L'a');" ERROR)
|
||||
|
||||
# Formatting a wide string with a narrow format string is forbidden.
|
||||
expect_compile(wide-string-narrow-format-string "fmt::format(L\"{}\", L\"foo\");")
|
||||
expect_compile(wide-string-narrow-format-string-error "fmt::format(\"{}\", L\"foo\");" ERROR)
|
||||
expect_compile(wide-string-narrow-format-string
|
||||
"fmt::format(L\"{}\", L\"foo\");")
|
||||
expect_compile(wide-string-narrow-format-string-error
|
||||
"fmt::format(\"{}\", L\"foo\");" ERROR)
|
||||
|
||||
# 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(narrow-string-wide-format-string "fmt::format(L\"{}\", L\"foo\");")
|
||||
expect_compile(narrow-string-wide-format-string-error "fmt::format(L\"{}\", \"foo\");" ERROR)
|
||||
expect_compile(narrow-string-wide-format-string
|
||||
"fmt::format(L\"{}\", L\"foo\");")
|
||||
expect_compile(narrow-string-wide-format-string-error
|
||||
"fmt::format(L\"{}\", \"foo\");" ERROR)
|
||||
|
||||
expect_compile(cast-to-string "
|
||||
expect_compile(
|
||||
cast-to-string
|
||||
"
|
||||
struct S {
|
||||
operator std::string() const { return std::string(); }
|
||||
};
|
||||
fmt::format(\"{}\", std::string(S()));
|
||||
")
|
||||
expect_compile(cast-to-string-error "
|
||||
")
|
||||
expect_compile(
|
||||
cast-to-string-error
|
||||
"
|
||||
struct S {
|
||||
operator std::string() const { return std::string(); }
|
||||
};
|
||||
fmt::format(\"{}\", S());
|
||||
" ERROR)
|
||||
"
|
||||
ERROR)
|
||||
|
||||
# Formatting a function
|
||||
expect_compile(format-function "
|
||||
expect_compile(
|
||||
format-function
|
||||
"
|
||||
void (*f)();
|
||||
fmt::format(\"{}\", fmt::ptr(f));
|
||||
")
|
||||
expect_compile(format-function-error "
|
||||
")
|
||||
expect_compile(
|
||||
format-function-error
|
||||
"
|
||||
void (*f)();
|
||||
fmt::format(\"{}\", f);
|
||||
" ERROR)
|
||||
"
|
||||
ERROR)
|
||||
|
||||
# Formatting an unformattable argument should always be a compile time error
|
||||
expect_compile(format-lots-of-arguments-with-unformattable "
|
||||
expect_compile(
|
||||
format-lots-of-arguments-with-unformattable
|
||||
"
|
||||
struct E {};
|
||||
fmt::format(\"\", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, E());
|
||||
" ERROR)
|
||||
expect_compile(format-lots-of-arguments-with-function "
|
||||
"
|
||||
ERROR)
|
||||
expect_compile(
|
||||
format-lots-of-arguments-with-function
|
||||
"
|
||||
void (*f)();
|
||||
fmt::format(\"\", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, f);
|
||||
" ERROR)
|
||||
"
|
||||
ERROR)
|
||||
|
||||
if (CMAKE_CXX_STANDARD GREATER_EQUAL 20)
|
||||
# Compile-time argument type check
|
||||
expect_compile(format-string-number-spec "
|
||||
expect_compile(
|
||||
format-string-number-spec
|
||||
"
|
||||
#ifdef FMT_HAS_CONSTEVAL
|
||||
fmt::format(\"{:d}\", 42);
|
||||
#endif
|
||||
")
|
||||
expect_compile(format-string-number-spec-error "
|
||||
")
|
||||
expect_compile(
|
||||
format-string-number-spec-error
|
||||
"
|
||||
#ifdef FMT_HAS_CONSTEVAL
|
||||
fmt::format(\"{:d}\", \"I am not a number\");
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
" ERROR)
|
||||
expect_compile(print-string-number-spec-error "
|
||||
"
|
||||
ERROR)
|
||||
expect_compile(
|
||||
print-string-number-spec-error
|
||||
"
|
||||
#ifdef FMT_HAS_CONSTEVAL
|
||||
fmt::print(\"{:d}\", \"I am not a number\");
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
" ERROR)
|
||||
expect_compile(print-stream-string-number-spec-error "
|
||||
"
|
||||
ERROR)
|
||||
expect_compile(
|
||||
print-stream-string-number-spec-error
|
||||
"
|
||||
#ifdef FMT_HAS_CONSTEVAL
|
||||
fmt::print(std::cout, \"{:d}\", \"I am not a number\");
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
" ERROR)
|
||||
"
|
||||
ERROR)
|
||||
|
||||
# Compile-time argument name check
|
||||
expect_compile(format-string-name "
|
||||
expect_compile(
|
||||
format-string-name
|
||||
"
|
||||
#if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
using namespace fmt::literals;
|
||||
fmt::print(\"{foo}\", \"foo\"_a=42);
|
||||
#endif
|
||||
")
|
||||
expect_compile(format-string-name-error "
|
||||
")
|
||||
expect_compile(
|
||||
format-string-name-error
|
||||
"
|
||||
#if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
using namespace fmt::literals;
|
||||
fmt::print(\"{foo}\", \"bar\"_a=42);
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
" ERROR)
|
||||
"
|
||||
ERROR)
|
||||
endif ()
|
||||
|
||||
# Run all tests
|
||||
|
||||
@@ -17,8 +17,8 @@ set(CMAKE_CUDA_STANDARD_REQUIRED 14)
|
||||
# In this test, we assume that the user is going to compile CUDA source code
|
||||
# with some libraries (fmt in this case).
|
||||
#
|
||||
# In addition to that, this test invokes both the C++ host compiler and NVCC
|
||||
# by providing another (non-CUDA) C++ source code.
|
||||
# In addition to that, this test invokes both the C++ host compiler and NVCC by
|
||||
# providing another (non-CUDA) C++ source code.
|
||||
if (${CMAKE_VERSION} VERSION_LESS 3.15)
|
||||
# https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html
|
||||
list(APPEND CUDA_NVCC_FLAGS "-std=c++14")
|
||||
@@ -33,41 +33,45 @@ if (${CMAKE_VERSION} VERSION_LESS 3.15)
|
||||
target_compile_features(fmt-in-cuda-test PRIVATE cxx_std_14)
|
||||
if (MSVC)
|
||||
# This part is for (non-CUDA) C++ code. MSVC can define incorrect
|
||||
# `__cplusplus` macro. Fix for the issue is to use additional compiler flag.
|
||||
# `__cplusplus` macro. Fix for the issue is to use additional compiler flag.
|
||||
#
|
||||
# See Also:
|
||||
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
# https://github.com/Microsoft/vscode-cpptools/issues/2595
|
||||
target_compile_options(fmt-in-cuda-test PRIVATE /Zc:__cplusplus /permissive-)
|
||||
target_compile_options(fmt-in-cuda-test PRIVATE /Zc:__cplusplus
|
||||
/permissive-)
|
||||
endif ()
|
||||
else()
|
||||
else ()
|
||||
# now using a "new" way of handling CUDA
|
||||
add_executable(fmt-in-cuda-test cuda-cpp14.cu cpp14.cc)
|
||||
set_target_properties(fmt-in-cuda-test PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||
set_target_properties(fmt-in-cuda-test PROPERTIES CUDA_SEPARABLE_COMPILATION
|
||||
ON)
|
||||
target_compile_features(fmt-in-cuda-test PRIVATE cxx_std_14)
|
||||
if (MSVC)
|
||||
# with MSVC, 'cxx_std_14' will only propagate to the host code (MSVC), but will
|
||||
# not set __cplusplus correctly anyway, while nvcc will ignore it.
|
||||
# If specified for nvcc on the command line as '-std=c++14' nvcc will emit this
|
||||
# message instead:
|
||||
# nvcc warning : The -std=c++14 flag is not supported with the configured host
|
||||
# compiler. Flag will be ignored.
|
||||
set_property(SOURCE cuda-cpp14.cu APPEND PROPERTY
|
||||
COMPILE_OPTIONS -Xcompiler /std:c++14 -Xcompiler /Zc:__cplusplus)
|
||||
set_property(SOURCE cpp14.cc APPEND PROPERTY
|
||||
COMPILE_OPTIONS /std:c++14 /Zc:__cplusplus)
|
||||
endif()
|
||||
endif()
|
||||
# with MSVC, 'cxx_std_14' will only propagate to the host code (MSVC), but
|
||||
# will not set __cplusplus correctly anyway, while nvcc will ignore it. If
|
||||
# specified for nvcc on the command line as '-std=c++14' nvcc will emit this
|
||||
# message instead: nvcc warning : The -std=c++14 flag is not supported with
|
||||
# the configured host compiler. Flag will be ignored.
|
||||
set_property(
|
||||
SOURCE cuda-cpp14.cu
|
||||
APPEND
|
||||
PROPERTY COMPILE_OPTIONS -Xcompiler /std:c++14 -Xcompiler /Zc:__cplusplus)
|
||||
set_property(
|
||||
SOURCE cpp14.cc
|
||||
APPEND
|
||||
PROPERTY COMPILE_OPTIONS /std:c++14 /Zc:__cplusplus)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_target_property(IN_USE_CUDA_STANDARD fmt-in-cuda-test CUDA_STANDARD)
|
||||
message(STATUS "cuda_standard: ${IN_USE_CUDA_STANDARD}")
|
||||
|
||||
get_target_property(IN_USE_CUDA_STANDARD_REQUIRED
|
||||
fmt-in-cuda-test CUDA_STANDARD_REQUIRED)
|
||||
get_target_property(IN_USE_CUDA_STANDARD_REQUIRED fmt-in-cuda-test
|
||||
CUDA_STANDARD_REQUIRED)
|
||||
message(STATUS "cuda_standard_required: ${IN_USE_CUDA_STANDARD_REQUIRED}")
|
||||
|
||||
# We don't use PUBLIC or other keyword for reasons explained in the
|
||||
# CUDA_LINK_LIBRARIES_KEYWORD section in
|
||||
# https://cmake.org/cmake/help/latest/module/FindCUDA.html
|
||||
target_link_libraries(fmt-in-cuda-test fmt::fmt)
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright (c) 2019, Paul Dreik
|
||||
# License: see LICENSE.rst in the fmt root directory
|
||||
|
||||
# Link in the main function. Useful for reproducing, kcov, gdb, afl, valgrind.
|
||||
# (Note that libFuzzer can also reproduce, just pass it the files.)
|
||||
@@ -7,11 +6,13 @@ option(FMT_FUZZ_LINKMAIN "Enables the reproduce mode, instead of libFuzzer" On)
|
||||
|
||||
# For oss-fuzz - insert $LIB_FUZZING_ENGINE into the link flags, but only for
|
||||
# the fuzz targets, otherwise the CMake configuration step fails.
|
||||
set(FMT_FUZZ_LDFLAGS "" CACHE STRING "LDFLAGS for the fuzz targets")
|
||||
set(FMT_FUZZ_LDFLAGS
|
||||
""
|
||||
CACHE STRING "LDFLAGS for the fuzz targets")
|
||||
|
||||
# Adds a binary for reproducing, i.e. no fuzzing, just enables replaying data
|
||||
# through the fuzzers.
|
||||
function(add_fuzzer source)
|
||||
function (add_fuzzer source)
|
||||
get_filename_component(basename ${source} NAME_WE)
|
||||
set(name ${basename}-fuzzer)
|
||||
add_executable(${name} ${source} fuzzer-common.h)
|
||||
@@ -23,8 +24,9 @@ function(add_fuzzer source)
|
||||
target_link_libraries(${name} PRIVATE ${FMT_FUZZ_LDFLAGS})
|
||||
endif ()
|
||||
target_compile_features(${name} PRIVATE cxx_std_14)
|
||||
endfunction()
|
||||
endfunction ()
|
||||
|
||||
foreach (source chrono-duration.cc chrono-timepoint.cc float.cc named-arg.cc one-arg.cc two-args.cc)
|
||||
foreach (source chrono-duration.cc chrono-timepoint.cc float.cc named-arg.cc
|
||||
one-arg.cc two-args.cc)
|
||||
add_fuzzer(${source})
|
||||
endforeach ()
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# Build the google test library
|
||||
# Compile Google Test ourselves instead of using pre-compiled libraries. See the
|
||||
# Google Test FAQ "Why is it not recommended to install a pre-compiled copy of
|
||||
# Google Test (for example, into /usr/local)?" at
|
||||
# http://code.google.com/p/googletest/wiki/FAQ for more details.
|
||||
|
||||
# Compile Google Test ourselves instead of using pre-compiled libraries.
|
||||
# See the Google Test FAQ "Why is it not recommended to install a
|
||||
# pre-compiled copy of Google Test (for example, into /usr/local)?"
|
||||
# at http://code.google.com/p/googletest/wiki/FAQ for more details.
|
||||
add_library(gtest STATIC
|
||||
gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h)
|
||||
add_library(gtest STATIC gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h
|
||||
gtest/gtest-spi.h)
|
||||
target_compile_definitions(gtest PUBLIC GTEST_HAS_STD_WSTRING=1)
|
||||
target_include_directories(gtest SYSTEM PUBLIC .)
|
||||
target_compile_features(gtest PUBLIC cxx_std_11)
|
||||
|
||||
Reference in New Issue
Block a user