-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
326 lines (275 loc) · 8.73 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# This file is part of SoFCheck
#
# Copyright (c) 2020-2023 Alexander Kernozhitsky and SoFCheck contributors
#
# SoFCheck is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SoFCheck is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SoFCheck. If not, see <https://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.14)
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project(SoFCheck)
# Include helper modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
include(Platform)
include(Benchmark)
include(BoostStacktrace)
include(JsonCpp)
include(CxxOpts)
include(PGO)
find_package(PythonInterp 3.6)
find_package(UnixCommands)
find_package(Git)
# Declare configuration options
set(USE_SEARCH_DIAGNOSTICS OFF CACHE BOOL
"Build with search diagnostics (the engine becomes slower but checks itself for errors)")
# Add include directories
include_directories("${PROJECT_BINARY_DIR}/src")
include_directories(src)
# Add targets to build
add_library(sof_version STATIC
"${PROJECT_BINARY_DIR}/src/version/version.cpp"
)
add_library(sof_util STATIC
src/util/formatter.cpp
src/util/ioutil.cpp
src/util/logging.cpp
src/util/misc.cpp
src/util/optparse.cpp
src/util/parallel.cpp
src/util/strutil.cpp
src/util/random.cpp
)
target_link_libraries(sof_util
PUBLIC ${CXXOPTS_TARGET}
PRIVATE Threads::Threads ${BOOST_STACKTRACE_TARGET}
)
add_library(sof_core STATIC
src/core/board.cpp
src/core/init.cpp
src/core/move_parser.cpp
src/core/move.cpp
src/core/movegen.cpp
src/core/strutil.cpp
src/core/private/magic.cpp
src/core/private/zobrist.cpp
src/core/test/selftest.cpp
"${PROJECT_BINARY_DIR}/src/core/private/near_attacks.h"
"${PROJECT_BINARY_DIR}/src/core/private/magic_consts.h"
"${PROJECT_BINARY_DIR}/src/core/private/between_consts.h"
)
target_link_libraries(sof_core PUBLIC sof_util)
add_library(sof_bot_api STATIC
src/bot_api/connection.cpp
src/bot_api/options.cpp
src/bot_api/strutil.cpp
)
target_link_libraries(sof_bot_api PUBLIC sof_core sof_util Threads::Threads)
add_library(sof_bot_api_clients STATIC
src/bot_api/clients/private/uci_option_escape.cpp
src/bot_api/clients/uci.cpp
)
target_link_libraries(sof_bot_api_clients PUBLIC sof_core sof_util sof_bot_api Threads::Threads)
add_library(sof_gameset STATIC
src/gameset/reader.cpp
src/gameset/types.cpp
)
target_link_libraries(sof_gameset PUBLIC sof_core sof_util)
add_library(sof_eval STATIC
src/eval/evaluate.cpp
"${PROJECT_BINARY_DIR}/src/eval/feature_count.h"
"${PROJECT_BINARY_DIR}/src/eval/private/bitboard.h"
"${PROJECT_BINARY_DIR}/src/eval/private/weights.h"
"${PROJECT_BINARY_DIR}/src/eval/private/weight_values.h"
)
target_link_libraries(sof_eval PUBLIC sof_core sof_util sof_bot_api)
add_library(sof_eval_feat STATIC
src/eval/feat/feat.cpp
)
target_link_libraries(sof_eval_feat
PUBLIC sof_util
PRIVATE ${JSONCPP_TARGET}
)
add_library(sof_search STATIC
src/search/search.cpp
src/search/private/limits.cpp
src/search/private/job.cpp
src/search/private/job_runner.cpp
src/search/private/move_picker.cpp
src/search/private/transposition_table.cpp
src/search/private/types.cpp
src/search/private/util.cpp
)
target_link_libraries(sof_search
PUBLIC sof_bot_api Threads::Threads
PRIVATE ${LIBATOMIC_TARGET} sof_core sof_util sof_eval sof_version
)
add_executable(sofcheck
src/search/bin/main.cpp
)
target_link_libraries(sofcheck sof_bot_api sof_bot_api_clients sof_search)
add_executable(make_dataset
src/eval/feat/bin/make_dataset.cpp
)
target_link_libraries(
make_dataset
sof_core sof_util sof_eval sof_eval_feat sof_gameset Threads::Threads ${JSONCPP_TARGET}
)
add_executable(apply_weights
src/eval/feat/bin/apply_weights.cpp
)
target_link_libraries(apply_weights sof_util sof_eval_feat ${JSONCPP_TARGET})
add_executable(show_weights
src/eval/feat/bin/show_weights.cpp
)
target_link_libraries(show_weights sof_util sof_eval_feat ${JSONCPP_TARGET})
# Generate files
include(Generators)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.20)
configure_file(tools/owl.py.in
"${PROJECT_BINARY_DIR}/owl.py"
@ONLY
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
else()
configure_file(tools/owl.py.in "${PROJECT_BINARY_DIR}/tmp/owl.py" @ONLY)
file(COPY
"${PROJECT_BINARY_DIR}/tmp/owl.py"
DESTINATION "${PROJECT_BINARY_DIR}"
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
endif()
configure_file(src/config.h.in "${PROJECT_BINARY_DIR}/src/config.h")
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src/version")
if(Git_FOUND AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
set(GIT_HEAD_DEPS "${PROJECT_SOURCE_DIR}/.git/logs/HEAD")
else()
set(GIT_HEAD_DEPS "")
set(GIT_EXECUTABLE "")
endif()
add_custom_command(
OUTPUT "${PROJECT_BINARY_DIR}/src/version/version.cpp"
COMMAND "${CMAKE_COMMAND}"
-DINPUT_FILE=${PROJECT_SOURCE_DIR}/src/version/version.cpp.in
-DOUTPUT_FILE=${PROJECT_BINARY_DIR}/src/version/version.cpp
-DGIT_EXECUTABLE="${GIT_EXECUTABLE}"
-P "${PROJECT_SOURCE_DIR}/cmake/scripts/GitRevisionConfig.cmake"
DEPENDS
"${PROJECT_SOURCE_DIR}/cmake/scripts/GitRevisionConfig.cmake"
"${PROJECT_SOURCE_DIR}/src/version/version.cpp.in"
${GIT_HEAD_DEPS}
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
)
generate_file(
gen/core/near_attacks.cpp
src/core/private/near_attacks.h
)
generate_file(
gen/core/magic_consts.cpp
src/core/private/magic_consts.h
)
generate_file(
gen/core/between_consts.cpp
src/core/private/between_consts.h
)
generate_file_json(
gen/eval/feature_count.cpp
src/eval/feature_count.h
src/eval/features.json
)
target_link_libraries(gen_eval_feature_count sof_eval_feat)
generate_file(
gen/eval/bitboard.cpp
src/eval/private/bitboard.h
)
generate_file_json(
gen/eval/weight_values.cpp
src/eval/private/weight_values.h
src/eval/features.json
)
target_link_libraries(gen_eval_weight_values sof_eval_feat)
generate_file_json(
gen/eval/weights.cpp
src/eval/private/weights.h
src/eval/features.json
)
target_link_libraries(gen_eval_weights sof_eval_feat)
# Add benchmarks
if(benchmark_FOUND)
add_executable(bench_is_move_legal bench/core/bench_is_move_legal.cpp)
target_benchmark(bench_is_move_legal)
target_link_libraries(bench_is_move_legal sof_core sof_util)
endif()
# Add self-tests
add_subdirectory(selftest)
# Add tests
enable_testing()
find_package(GTest)
add_executable(test_uci_client
src/bot_api/clients/test/uci.cpp
)
target_link_libraries(test_uci_client sof_core sof_util sof_bot_api_clients)
if(GTest_FOUND)
include(GoogleTest)
add_executable(test_eval_unit_test
src/eval/test/score.cpp
)
target_link_libraries(test_eval_unit_test GTest::GTest GTest::Main)
gtest_add_tests(TARGET test_eval_unit_test)
add_executable(test_eval_feat_unit_test
src/eval/feat/test/feat.cpp
)
target_link_libraries(test_eval_feat_unit_test
sof_eval_feat sof_util ${JSONCPP_TARGET} GTest::GTest GTest::Main
)
gtest_add_tests(TARGET test_eval_feat_unit_test)
add_executable(test_util_unit_test
src/util/test/parallel.cpp
src/util/test/strutil.cpp
src/util/test/valarray.cpp
)
target_link_libraries(test_util_unit_test sof_util GTest::GTest GTest::Main Threads::Threads)
gtest_add_tests(TARGET test_util_unit_test)
endif()
if(BASH AND PYTHONINTERP_FOUND)
foreach(test_id 1 2)
add_test(
NAME uci-client-${test_id}
COMMAND "${CMAKE_COMMAND}" -E env
"CMAKE_COMMAND=${CMAKE_COMMAND}"
"PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
"COMMUNICATE_SCRIPT=${PROJECT_SOURCE_DIR}/tools/communicate_process.py"
"TEST_EXECUTABLE=$<TARGET_FILE:test_uci_client>"
"IN_FILE=${PROJECT_SOURCE_DIR}/src/bot_api/clients/test/uci_in${test_id}.txt"
"OUT_FILE=${PROJECT_BINARY_DIR}/test_uci_client_${test_id}.txt"
"ANS_FILE=${PROJECT_SOURCE_DIR}/src/bot_api/clients/test/uci_out${test_id}.txt"
"${BASH}" "${PROJECT_SOURCE_DIR}/src/bot_api/clients/test/uci_run.sh"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
)
endforeach()
endif()
if(PYTHONINTERP_FOUND)
add_test(
NAME smoke
COMMAND "${PYTHON_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/tools/run_test_positions.py"
"$<TARGET_FILE:sofcheck>"
)
endif()
# Add install section
install(TARGETS sofcheck RUNTIME DESTINATION bin)