| 1 |
# FetchContent requires cmake >=3.11 |
| 2 |
# see https://cmake.org/cmake/help/v3.11/module/FetchContent.html |
| 3 |
cmake_minimum_required(VERSION 3.11 FATAL_ERROR) |
| 4 |
|
| 5 |
include(FetchContent) |
| 6 |
|
| 7 |
option(SYSTEM_DOCTEST "Use system copy of doctest" OFF) |
| 8 |
option(FASTFLOAT_SUPPLEMENTAL_TESTS "Run supplemental tests" ON) |
| 9 |
|
| 10 |
if (NOT SYSTEM_DOCTEST) |
| 11 |
FetchContent_Declare(doctest |
| 12 |
GIT_REPOSITORY https://github.com/lemire/doctest.git) |
| 13 |
else () |
| 14 |
find_package(doctest REQUIRED) |
| 15 |
endif() |
| 16 |
if (FASTFLOAT_SUPPLEMENTAL_TESTS) |
| 17 |
FetchContent_Declare(supplemental_test_files |
| 18 |
GIT_REPOSITORY https://github.com/fastfloat/supplemental_test_files.git |
| 19 |
GIT_TAG origin/main) |
| 20 |
endif() |
| 21 |
|
| 22 |
|
| 23 |
# FetchContent_MakeAvailable() was only introduced in 3.14 |
| 24 |
# https://cmake.org/cmake/help/v3.14/release/3.14.html#modules |
| 25 |
if (NOT SYSTEM_DOCTEST) |
| 26 |
FetchContent_MakeAvailable(doctest) |
| 27 |
endif() |
| 28 |
|
| 29 |
add_library(supplemental-data INTERFACE) |
| 30 |
if (FASTFLOAT_SUPPLEMENTAL_TESTS) |
| 31 |
message(STATUS "Supplemental tests enabled. Retrieving test files.") |
| 32 |
FetchContent_MakeAvailable(supplemental_test_files) |
| 33 |
message(STATUS "Supplemental test files retrieved.") |
| 34 |
target_compile_definitions(supplemental-data INTERFACE SUPPLEMENTAL_TEST_DATA_DIR="${supplemental_test_files_BINARY_DIR}/data") |
| 35 |
endif() |
| 36 |
|
| 37 |
function(fast_float_add_cpp_test TEST_NAME) |
| 38 |
add_executable(${TEST_NAME} ${TEST_NAME}.cpp) |
| 39 |
if(CMAKE_CROSSCOMPILING) |
| 40 |
set(ccemulator ${CMAKE_CROSSCOMPILING_EMULATOR}) |
| 41 |
endif() |
| 42 |
add_test(NAME ${TEST_NAME} |
| 43 |
COMMAND ${ccemulator} $<TARGET_FILE:${TEST_NAME}>) |
| 44 |
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
| 45 |
target_compile_options(${TEST_NAME} PUBLIC /EHsc) |
| 46 |
endif() |
| 47 |
if(NOT WIN32) |
| 48 |
target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++) |
| 49 |
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion) |
| 50 |
endif() |
| 51 |
target_link_libraries(${TEST_NAME} PUBLIC fast_float supplemental-data) |
| 52 |
if (NOT SYSTEM_DOCTEST) |
| 53 |
target_link_libraries(${TEST_NAME} PUBLIC doctest) |
| 54 |
else () |
| 55 |
target_link_libraries(${TEST_NAME} PUBLIC doctest::doctest) |
| 56 |
endif() |
| 57 |
endfunction(fast_float_add_cpp_test) |
| 58 |
|
| 59 |
fast_float_add_cpp_test(rcppfastfloat_test) |
| 60 |
fast_float_add_cpp_test(wide_char_test) |
| 61 |
fast_float_add_cpp_test(supported_chars_test) |
| 62 |
fast_float_add_cpp_test(example_test) |
| 63 |
fast_float_add_cpp_test(example_comma_test) |
| 64 |
fast_float_add_cpp_test(example_integer_times_pow10) |
| 65 |
fast_float_add_cpp_test(basictest) |
| 66 |
option(FASTFLOAT_CONSTEXPR_TESTS "Require constexpr tests (build will fail if the compiler won't support it)" OFF) |
| 67 |
if (FASTFLOAT_CONSTEXPR_TESTS) |
| 68 |
target_compile_features(basictest PRIVATE cxx_std_20) |
| 69 |
target_compile_definitions(basictest PRIVATE FASTFLOAT_CONSTEXPR_TESTS) |
| 70 |
else() |
| 71 |
target_compile_features(basictest PRIVATE cxx_std_17) |
| 72 |
endif() |
| 73 |
if (FASTFLOAT_SUPPLEMENTAL_TESTS) |
| 74 |
target_compile_definitions(basictest PRIVATE FASTFLOAT_SUPPLEMENTAL_TESTS) |
| 75 |
endif() |
| 76 |
fast_float_add_cpp_test(p2497) |
| 77 |
fast_float_add_cpp_test(long_test) |
| 78 |
fast_float_add_cpp_test(powersoffive_hardround) |
| 79 |
fast_float_add_cpp_test(string_test) |
| 80 |
fast_float_add_cpp_test(fast_int) |
| 81 |
target_compile_features(fast_int PRIVATE cxx_std_17) |
| 82 |
fast_float_add_cpp_test(json_fmt) |
| 83 |
fast_float_add_cpp_test(fortran) |
| 84 |
if(CMAKE_CXX_STANDARD GREATER_EQUAL 23) |
| 85 |
option(FASTFLOAT_FIXEDWIDTH_TESTS "Require fixed width test for C++23 (build will fail if the compiler won't support it)" ON) |
| 86 |
else() |
| 87 |
option(FASTFLOAT_FIXEDWIDTH_TESTS "Require fixed width test for C++23 (build will fail if the compiler won't support it)" OFF) |
| 88 |
endif() |
| 89 |
if (FASTFLOAT_FIXEDWIDTH_TESTS) |
| 90 |
fast_float_add_cpp_test(fixedwidthtest) |
| 91 |
target_compile_features(fixedwidthtest PUBLIC cxx_std_23) |
| 92 |
endif() |
| 93 |
|
| 94 |
option(FASTFLOAT_EXHAUSTIVE "Exhaustive tests" OFF) |
| 95 |
|
| 96 |
if (FASTFLOAT_EXHAUSTIVE) |
| 97 |
fast_float_add_cpp_test(short_random_string) |
| 98 |
fast_float_add_cpp_test(exhaustive32_midpoint) |
| 99 |
fast_float_add_cpp_test(random_string) |
| 100 |
fast_float_add_cpp_test(exhaustive32) |
| 101 |
fast_float_add_cpp_test(exhaustive32_64) |
| 102 |
fast_float_add_cpp_test(long_exhaustive32) |
| 103 |
fast_float_add_cpp_test(long_exhaustive32_64) |
| 104 |
fast_float_add_cpp_test(long_random64) |
| 105 |
fast_float_add_cpp_test(random64) |
| 106 |
endif(FASTFLOAT_EXHAUSTIVE) |
| 107 |
|
| 108 |
add_subdirectory(build_tests) |
| 109 |
add_subdirectory(bloat_analysis) |