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