-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
177 lines (143 loc) · 5.35 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
cmake_minimum_required(VERSION 3.14)
project(c_numconv_benchmark)
# ------------------------------------------------------------------------------
# build type
if(XCODE OR MSVC)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to: Release")
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif()
# ------------------------------------------------------------------------------
# vendor
set(vendors "")
# fmt
add_subdirectory(vendor/fmt)
list(APPEND vendors "fmt")
# google double conversion
add_subdirectory(vendor/double-conversion)
list(APPEND vendors "double-conversion")
# lemire fast double parser (header only)
add_library(fast_double_parser INTERFACE)
target_include_directories(fast_double_parser INTERFACE "vendor/fast_double_parser/include")
list(APPEND vendors "fast_double_parser")
# dragonbox
add_subdirectory(vendor/dragonbox)
list(APPEND vendors "dragonbox_to_chars")
# grisu-exact
add_library(grisu_exact STATIC
"vendor/Grisu-Exact/grisu_exact.h"
"vendor/Grisu-Exact/fp_to_chars.h"
"vendor/Grisu-Exact/fp_to_chars/fp_to_chars.cpp"
)
target_include_directories(grisu_exact INTERFACE "vendor/Grisu-Exact")
list(APPEND vendors "grisu_exact")
# schubfach
file(GLOB SOURCES "vendor/Drachennest/src/*.cc" "vendor/Drachennest/src/*.h")
add_library(schubfach STATIC ${SOURCES})
target_include_directories(schubfach INTERFACE "vendor/Drachennest/src")
list(APPEND vendors "schubfach")
# erthink (header only)
add_library(erthink INTERFACE)
target_include_directories(erthink INTERFACE "vendor/erthink")
list(APPEND vendors "erthink")
# ryu
if(NOT MSVC)
file(GLOB SOURCES
"vendor/ryu/ryu/*.h"
"vendor/ryu/ryu/*.c"
)
add_library(ryu STATIC ${SOURCES})
target_include_directories(ryu PUBLIC "vendor/ryu")
list(APPEND vendors "ryu")
endif()
# david gay
add_library(david_gay STATIC
"vendor/david_gay/david_gay_dtoa.h"
"vendor/david_gay/david_gay_dtoa.c"
)
target_include_directories(david_gay PUBLIC "vendor/david_gay")
list(APPEND vendors "david_gay")
# swift dtoa
add_library(swift_dtoa STATIC
"vendor/swift_dtoa/SwiftDtoa.h"
"vendor/swift_dtoa/SwiftDtoa.cpp"
)
target_include_directories(swift_dtoa PUBLIC "vendor/swift_dtoa")
list(APPEND vendors "swift_dtoa")
# yy_double
add_library(yy_double STATIC
"vendor/yy_double/yy_double.h"
"vendor/yy_double/yy_double.c"
)
target_include_directories(swift_dtoa PUBLIC "vendor/yy_double")
list(APPEND vendors "yy_double")
# yybench
add_subdirectory(vendor/yybench)
list(APPEND vendors "yybench")
# ------------------------------------------------------------------------------
# runs
set(run_names "itoa" "dtoa" "atoi" "strtod")
foreach(run_name ${run_names})
# create exe
add_executable("run_${run_name}" "")
# add source files
file(GLOB SOURCES
"src/${run_name}/*.h"
"src/${run_name}/*.c"
"src/${run_name}/*.cpp"
)
list(APPEND SOURCES "src/main/main.c")
target_sources("run_${run_name}" PRIVATE ${SOURCES})
target_include_directories("run_${run_name}" PRIVATE "src/${run_name}")
# add links
target_link_libraries("run_${run_name}" PRIVATE ${vendors})
# align all functions 64 bytes
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options("run_${run_name}" PRIVATE "-mllvm" "-align-all-functions=7")
elseif (CMAKE_C_COMPILER_ID MATCHES "GNU")
target_compile_options("run_${run_name}" PRIVATE "-falign-functions=64")
endif()
endforeach()
# config project
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DBENCHMARK_DATA_PATH="${CMAKE_CURRENT_BINARY_DIR}")
elseif(XCODE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(XcodeProperty)
foreach(run_name ${run_names})
set_default_xcode_property("run_${run_name}")
set_xcode_deployment_version("run_${run_name}" "10.11" "9.0" "9.0" "2.0")
set_xcode_language_standard("run_${run_name}" "gnu11" "gnu++17")
if(NOT IOS)
set_xcode_property("run_${run_name}" OTHER_CFLAGS[variant=Debug] -DBENCHMARK_DATA_PATH="\\\\\"${CMAKE_CURRENT_BINARY_DIR}\\\\\"")
set_xcode_property("run_${run_name}" OTHER_CFLAGS[variant=Release] -DBENCHMARK_DATA_PATH="\\\\\"${CMAKE_CURRENT_BINARY_DIR}\\\\\"")
endif()
endforeach()
foreach(vendor ${vendors})
get_property(vendor_type TARGET ${vendor} PROPERTY TYPE)
if(NOT vendor_type STREQUAL "INTERFACE_LIBRARY")
set_default_xcode_property(${vendor})
set_xcode_deployment_version(${vendor} "10.11" "9.0" "9.0" "2.0")
set_xcode_language_standard(${vendor} "gnu11" "gnu++17")
endif()
endforeach()
else()
add_definitions(-DBENCHMARK_DATA_PATH="${CMAKE_CURRENT_BINARY_DIR}")
endif()
# copy test data
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})