forked from d99kris/rapidcsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
215 lines (199 loc) · 6.03 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# Project
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(rapidcsv VERSION 1.0 LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 11)
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_compile_options("/utf-8")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith \
-Wcast-qual -Wno-missing-braces -Wswitch-default -Wcast-align \
-Wunreachable-code -Wundef -Wuninitialized -Wold-style-cast \
-Wsign-conversion -Weffc++")
endif()
# Build type
set(DEFAULT_BUILD_TYPE "Release")
if((EXISTS "${CMAKE_SOURCE_DIR}/.svn") OR (EXISTS "${CMAKE_SOURCE_DIR}/.git"))
set(DEFAULT_BUILD_TYPE "Debug")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Using build type '${DEFAULT_BUILD_TYPE}' (default).")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
else()
message(STATUS "Using build type '${CMAKE_BUILD_TYPE}'.")
endif()
# Library
add_library(rapidcsv INTERFACE)
target_include_directories(rapidcsv INTERFACE src)
# Ccache
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Found ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
# Tests
option(RAPIDCSV_BUILD_TESTS "Build tests" OFF)
message(STATUS "Build tests: ${RAPIDCSV_BUILD_TESTS}")
if(RAPIDCSV_BUILD_TESTS)
# Test init
include(CTest)
enable_testing()
# Enable codecvt tests if supported
if (CMAKE_CXX_STANDARD VERSION_LESS "17")
include(CheckIncludeFileCXX)
check_include_file_cxx(codecvt HAS_CODECVT)
if(HAS_CODECVT)
target_compile_definitions(rapidcsv INTERFACE HAS_CODECVT)
endif()
else()
message(STATUS "Skip check for C++ include codecvt - C++${CMAKE_CXX_STANDARD}")
endif()
# Test macro add_perf_test
macro(add_perf_test testname)
if(CMAKE_BUILD_TYPE MATCHES "Release")
FILE(GLOB sources tests/${testname}*.cpp)
add_executable(${testname} ${sources})
add_test(NAME ${testname} COMMAND "${PROJECT_BINARY_DIR}/${testname}")
target_link_libraries(${testname} PUBLIC rapidcsv)
endif()
endmacro(add_perf_test)
# Test macro add_unit_test
macro(add_unit_test testname)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
FILE(GLOB sources tests/${testname}*.cpp)
add_executable(${testname} ${sources})
add_test(NAME ${testname} COMMAND "${PROJECT_BINARY_DIR}/${testname}")
target_link_libraries(${testname} PUBLIC rapidcsv)
endif()
endmacro(add_unit_test)
# Unit tests
add_unit_test(test001)
add_unit_test(test002)
add_unit_test(test003)
add_unit_test(test004)
add_unit_test(test005)
add_unit_test(test006)
add_unit_test(test007)
add_unit_test(test008)
add_unit_test(test009)
add_unit_test(test010)
add_unit_test(test011)
add_unit_test(test012)
add_unit_test(test013)
add_unit_test(test014)
add_unit_test(test015)
add_unit_test(test016)
add_unit_test(test017)
add_unit_test(test018)
add_unit_test(test019)
add_unit_test(test020)
add_unit_test(test021)
add_unit_test(test022)
add_unit_test(test023)
add_unit_test(test024)
add_unit_test(test025)
add_unit_test(test026)
add_unit_test(test027)
add_unit_test(test028)
add_unit_test(test029)
add_unit_test(test030)
add_unit_test(test031)
add_unit_test(test032)
add_unit_test(test033)
add_unit_test(test034)
add_unit_test(test035)
add_unit_test(test036)
add_unit_test(test037)
add_unit_test(test038)
add_unit_test(test039)
add_unit_test(test040)
add_unit_test(test041)
add_unit_test(test042)
add_unit_test(test043)
add_unit_test(test044)
add_unit_test(test045)
add_unit_test(test046)
add_unit_test(test047)
add_unit_test(test048)
add_unit_test(test049)
add_unit_test(test050)
add_unit_test(test051)
add_unit_test(test052)
add_unit_test(test053)
add_unit_test(test054)
add_unit_test(test055)
add_unit_test(test056)
if(HAS_CODECVT)
add_unit_test(test057)
add_unit_test(test058)
add_unit_test(test059)
add_unit_test(test060)
endif()
add_unit_test(test061)
add_unit_test(test062)
add_unit_test(test063)
add_unit_test(test064)
add_unit_test(test065)
add_unit_test(test066)
add_unit_test(test067)
add_unit_test(test068)
add_unit_test(test069)
add_unit_test(test070)
add_unit_test(test071)
add_unit_test(test072)
add_unit_test(test073)
add_unit_test(test074)
add_unit_test(test075)
add_unit_test(test076)
add_unit_test(test077)
add_unit_test(test078)
add_unit_test(test079)
add_unit_test(test080)
add_unit_test(test081)
add_unit_test(test082)
add_unit_test(test083)
add_unit_test(test084)
if(HAS_CODECVT)
add_unit_test(test085)
endif()
add_unit_test(test086)
add_unit_test(test087)
add_unit_test(test088)
add_unit_test(test089)
add_unit_test(test090)
# perf tests
add_perf_test(ptest001)
add_perf_test(ptest002)
# Examples
# Test macro add_example
macro(add_example testname)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_executable(${testname} examples/${testname}.cpp)
target_link_libraries(${testname} PUBLIC rapidcsv)
endif()
endmacro(add_example)
add_example(ex001 examples/ex001.cpp)
add_example(ex002 examples/ex002.cpp)
add_example(ex003 examples/ex003.cpp)
add_example(ex004 examples/ex004.cpp)
add_example(ex005 examples/ex005.cpp)
add_example(ex006 examples/ex006.cpp)
add_example(ex007 examples/ex007.cpp)
add_example(ex008 examples/ex008.cpp)
add_example(ex009 examples/ex009.cpp)
endif()
# Install / Uninstall targets for standalone rapidcsv build
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
message(STATUS "Install/uninstall targets enabled.")
# Install
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/rapidcsv.h DESTINATION include)
# Uninstall
add_custom_target(uninstall COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/include/rapidcsv.h"
)
else()
message(STATUS "Install/uninstall targets disabled.")
endif()