-
Notifications
You must be signed in to change notification settings - Fork 51
/
CMakeLists.txt
73 lines (66 loc) · 3.39 KB
/
CMakeLists.txt
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
find_package(Python COMPONENTS Interpreter)
# this benchmark compares the binaries from several float libraries
function(c4core_bm_readfloat name define)
set(target c4core-bm-readfloat-${name})
c4_add_executable(${target}
SOURCES read.cpp
LIBS ${ARGN}
FOLDER bm/float)
use_static_libc(${target})
if(NOT "${define}" STREQUAL "")
target_compile_definitions(${target} PUBLIC ${define}=1)
endif()
if(NOT TARGET c4core-bm-readfloat)
add_custom_target(c4core-bm-readfloat)
endif()
add_dependencies(c4core-bm-readfloat ${target})
set(measure ${CMAKE_CURRENT_LIST_DIR}/measure.py)
target_sources(${target} PRIVATE ${measure})
if(UNIX)
set(unix --unix) # $<$<BOOL:UNIX>:--unix>
endif()
add_custom_command(TARGET ${target} PRE_BUILD
COMMAND ${Python_EXECUTABLE} ${measure} start ${target}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${Python_EXECUTABLE} ${measure} finish ${unix} ${target} $<TARGET_FILE:${target}>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endfunction()
function(use_static_libc target)
if(MSVC)
# https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html
set_property(TARGET ${target} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
# https://stackoverflow.com/questions/38694058/cmake-linking-statically-against-libgcc-and-libstdc-into-a-shared-library
target_link_libraries(${target} PUBLIC -static-libgcc -static-libstdc++)
endif()
endfunction()
c4core_bm_readfloat(baseline "")
c4core_bm_readfloat(std_atof C4FLOAT_STD_ATOF)
c4core_bm_readfloat(sscanf_f C4FLOAT_SSCANF_F)
c4core_bm_readfloat(sscanf_d C4FLOAT_SSCANF_D)
c4core_bm_readfloat(iostream_f C4FLOAT_IOSTREAM_F)
c4core_bm_readfloat(iostream_d C4FLOAT_IOSTREAM_D)
c4core_bm_readfloat(fast_float_f C4FLOAT_FASTFLOAT_F fast_float)
c4core_bm_readfloat(fast_float_d C4FLOAT_FASTFLOAT_D fast_float)
c4core_bm_readfloat(ryu_f C4FLOAT_RYU_F ryu_c4)
c4core_bm_readfloat(ryu_d C4FLOAT_RYU_D ryu_c4)
get_property(known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
if(cxx_std_17 IN_LIST known_features)
c4core_bm_readfloat(fast_fp_f_limited C4FLOAT_FP_F_LIMITED jkj_fp)
c4core_bm_readfloat(fast_fp_d_limited C4FLOAT_FP_D_LIMITED jkj_fp)
c4core_bm_readfloat(fast_fp_f_unlimited C4FLOAT_FP_F_UNLIMITED jkj_fp)
c4core_bm_readfloat(fast_fp_d_unlimited C4FLOAT_FP_D_UNLIMITED jkj_fp)
target_compile_features(c4core-bm-readfloat-fast_fp_f_limited PRIVATE cxx_std_17)
target_compile_features(c4core-bm-readfloat-fast_fp_d_limited PRIVATE cxx_std_17)
target_compile_features(c4core-bm-readfloat-fast_fp_f_unlimited PRIVATE cxx_std_17)
target_compile_features(c4core-bm-readfloat-fast_fp_d_unlimited PRIVATE cxx_std_17)
# incredible - 3 years of C++17 and from_chars()/to_chars() is not available
if(NOT ((CMAKE_CXX_COMPILER_ID STREQUAL GNU) OR (CMAKE_CXX_COMPILER_ID STREQUAL Clang)))
c4core_bm_readfloat(std_from_chars_f C4FLOAT_STD_FROM_CHARS_F)
c4core_bm_readfloat(std_from_chars_d C4FLOAT_STD_FROM_CHARS_D)
target_compile_features(c4core-bm-readfloat-std_from_chars_f PRIVATE cxx_std_17)
target_compile_features(c4core-bm-readfloat-std_from_chars_d PRIVATE cxx_std_17)
endif()
endif()