-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
130 lines (105 loc) · 4.68 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
cmake_minimum_required(VERSION 3.14...3.26)
# Read the version from fast_matrix_market.hpp
set(VERSION_HEADER_FILE include/fast_matrix_market/fast_matrix_market.hpp)
file(STRINGS ${VERSION_HEADER_FILE} VERSION_MAJOR_STR REGEX "define .*_VERSION_MAJOR")
file(STRINGS ${VERSION_HEADER_FILE} VERSION_MINOR_STR REGEX "define .*_VERSION_MINOR")
file(STRINGS ${VERSION_HEADER_FILE} VERSION_PATCH_STR REGEX "define .*_VERSION_PATCH")
string(REGEX MATCH "[0-9]+" FMM_MAJOR ${VERSION_MAJOR_STR})
string(REGEX MATCH "[0-9]+" FMM_MINOR ${VERSION_MINOR_STR})
string(REGEX MATCH "[0-9]+" FMM_PATCH ${VERSION_PATCH_STR})
project(fast_matrix_market VERSION "${FMM_MAJOR}.${FMM_MINOR}.${FMM_PATCH}" LANGUAGES CXX)
message("fast_matrix_market version ${PROJECT_VERSION}")
# Main
add_library(fast_matrix_market INTERFACE)
# add alias so the project can be used with add_subdirectory
add_library(fast_matrix_market::fast_matrix_market ALIAS fast_matrix_market)
target_include_directories(
fast_matrix_market INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(fast_matrix_market INTERFACE cxx_std_17)
# Some older compilers (eg. Clang, GCC <9) require extra link flags for C++11 threads
find_package(Threads)
target_link_libraries(fast_matrix_market INTERFACE Threads::Threads)
# CMake options to enable/disable dependencies
option(FMM_USE_FAST_FLOAT "Enable fast_float float/double parser" ON)
option(FMM_USE_DRAGONBOX "Enable dragonbox float/double formatter for shortest representation" ON)
option(FMM_USE_RYU "Enable Ryu float/double formatter with precision support" ON)
############################################
# Test for available versions of std::from_chars.
include(cmake/from_chars_tests.cmake)
include(cmake/to_chars_tests.cmake)
if (from_chars_int_supported)
message("std::from_chars<int> detected.")
target_compile_definitions(fast_matrix_market INTERFACE FMM_FROM_CHARS_INT_SUPPORTED)
else()
message("std::from_chars<int> not detected.")
endif()
if (from_chars_double_supported)
target_compile_definitions(fast_matrix_market INTERFACE FMM_FROM_CHARS_DOUBLE_SUPPORTED)
else()
message("std::from_chars<double> not detected.")
endif()
if (from_chars_long_double_supported)
target_compile_definitions(fast_matrix_market INTERFACE FMM_FROM_CHARS_LONG_DOUBLE_SUPPORTED)
else()
message("std::from_chars<long double> not detected.")
endif()
###############################################
# Test for available versions of std::to_chars.
if (to_chars_int_supported)
message("std::to_chars<int> detected.")
target_compile_definitions(fast_matrix_market INTERFACE FMM_TO_CHARS_INT_SUPPORTED)
else()
message("std::to_chars<int> not detected.")
endif()
if (to_chars_double_supported)
message("std::to_chars<double> detected.")
target_compile_definitions(fast_matrix_market INTERFACE FMM_TO_CHARS_DOUBLE_SUPPORTED)
else()
message("std::to_chars<double> not detected.")
endif()
if (to_chars_long_double_supported)
message("std::to_chars<long double> detected.")
target_compile_definitions(fast_matrix_market INTERFACE FMM_TO_CHARS_LONG_DOUBLE_SUPPORTED)
else()
message("std::to_chars<long double> not detected.")
endif()
###############################################
# Setup dependencies
# Setup fast_float.
# float and double parser.
if (FMM_USE_FAST_FLOAT)
message("Using fast_float")
set(FASTFLOAT_INSTALL OFF)
add_subdirectory(dependencies/fast_float)
target_compile_definitions(fast_matrix_market INTERFACE FMM_USE_FAST_FLOAT)
target_link_libraries(fast_matrix_market INTERFACE fast_float)
endif()
# Setup Dragonbox.
# float and double formatter for shortest representation. No precision support.
if (FMM_USE_DRAGONBOX)
message("Using Dragonbox")
add_subdirectory(dependencies/dragonbox)
target_compile_definitions(fast_matrix_market INTERFACE FMM_USE_DRAGONBOX)
target_link_libraries(fast_matrix_market INTERFACE dragonbox::dragonbox_to_chars)
endif()
# Setup Ryu.
# float, double formatter with precision support. Slower than Dragonbox for shortest representation.
if (FMM_USE_RYU)
message("Using ryu")
add_subdirectory(dependencies/ryu)
target_link_libraries(fast_matrix_market INTERFACE ryu::ryu)
target_compile_definitions(fast_matrix_market INTERFACE FMM_USE_RYU)
endif()
###############################################
# Tests
option(FAST_MATRIX_MARKET_TEST "Enable tests" OFF)
if(FAST_MATRIX_MARKET_TEST)
enable_testing()
add_subdirectory(tests)
endif(FAST_MATRIX_MARKET_TEST)
# Benchmarks
option(FAST_MATRIX_MARKET_BENCH "Enable benchmarks" OFF)
if(FAST_MATRIX_MARKET_BENCH)
add_subdirectory(benchmark)
endif(FAST_MATRIX_MARKET_BENCH)