This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
115 lines (91 loc) · 5.25 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
cmake_minimum_required(VERSION 3.15)
file(STRINGS version.txt SPJ_VERSION LIMIT_COUNT 1)
project(stormphranj VERSION ${SPJ_VERSION})
set(CMAKE_CXX_STANDARD 20)
set(SPJ_DEFAULT_NET_NAME net008)
set(SPJ_CLANG CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(MSVC AND NOT SPJ_CLANG)
message(FATAL_ERROR Stormphranj does not support building with MSVC)
endif()
option(SPJ_EMBED_COMMIT_HASH "whether to include the current git commit in the UCI version string" ON)
if(SPJ_EMBED_COMMIT_HASH)
set(SPJ_COMMIT_HASH "unknown")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND git log -1 --pretty=format:%h
OUTPUT_VARIABLE SPJ_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
endif()
# for fathom
add_compile_definitions(_SILENCE_CXX20_ATOMIC_INIT_DEPRECATION_WARNING)
if(MSVC)
add_compile_options(/EHsc)
# for fathom
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:DebugDLL>")
endif()
find_package(Threads REQUIRED)
# cmake forces thin lto on clang for CMAKE_INTERPROCEDURAL_OPTIMIZATION, thanks cmake
add_compile_options($<$<CONFIG:Release>:-flto>)
option(SPJ_FAST_PEXT "whether pext and pdep are usably fast on this architecture, for building native binaries" ON)
set(stormphranj_COMMON_SRC src/types.h src/main.cpp src/uci.h src/uci.cpp src/core.h src/util/bitfield.h src/util/bits.h
src/util/parse.h src/util/split.h src/util/split.cpp src/util/rng.h src/util/static_vector.h src/bitboard.h
src/move.h src/keys.h src/position/position.h src/position/position.cpp src/search.h src/search.cpp src/movegen.h
src/movegen.cpp src/attacks/util.h src/attacks/attacks.h src/util/timer.h src/util/timer.cpp src/pretty.h
src/pretty.cpp src/rays.h src/ttable.h src/ttable.cpp src/limit/limit.h src/limit/trivial.h src/limit/time.h
src/limit/time.cpp src/util/cemath.h src/eval/nnue.h src/eval/nnue.cpp src/util/range.h src/arch.h src/perft.h
src/perft.cpp src/search_fwd.h src/see.h src/bench.h src/bench.cpp src/tunable.h src/tunable.cpp src/opts.h
src/opts.cpp src/position/boards.h src/history.h src/datagen/datagen.h src/datagen/datagen.cpp src/util/u4array.h
src/eval/eval.h src/util/barrier.h src/util/simd.h src/wdl.h src/wdl.cpp src/eval/arch.h src/cuckoo.h src/cuckoo.cpp
src/eval/nnue/network.h src/eval/nnue/layers.h src/eval/nnue/activation.h src/eval/nnue/output.h
src/eval/nnue/input.h src/util/memstream.h src/util/aligned_array.h src/eval/nnue/io.h src/eval/nnue/features.h
src/datagen/format.h src/datagen/common.h src/datagen/marlinformat.h src/datagen/marlinformat.cpp
src/datagen/viri_binpack.h src/datagen/viri_binpack.cpp)
set(stormphranj_BMI2_SRC src/attacks/bmi2/data.h src/attacks/bmi2/attacks.h src/attacks/bmi2/attacks.cpp)
set(stormphranj_NON_BMI2_SRC src/attacks/black_magic/data.h src/attacks/black_magic/attacks.h
src/attacks/black_magic/attacks.cpp)
add_executable(stormphranj-native ${stormphranj_COMMON_SRC} ${stormphranj_BMI2_SRC} ${stormphranj_NON_BMI2_SRC})
add_executable(stormphranj-avx512 ${stormphranj_COMMON_SRC} ${stormphranj_BMI2_SRC})
add_executable(stormphranj-avx2-bmi2 ${stormphranj_COMMON_SRC} ${stormphranj_BMI2_SRC})
add_executable(stormphranj-avx2 ${stormphranj_COMMON_SRC} ${stormphranj_NON_BMI2_SRC})
add_executable(stormphranj-sse41-popcnt ${stormphranj_COMMON_SRC} ${stormphranj_NON_BMI2_SRC})
target_compile_options(stormphranj-native PUBLIC -march=native)
target_compile_options(stormphranj-avx512 PUBLIC -march=x86-64-v4)
target_compile_options(stormphranj-avx2-bmi2 PUBLIC -march=haswell)
# excavator without amd-specific extensions and bmi2
target_compile_options(stormphranj-avx2 PUBLIC -march=bdver4 -mno-tbm -mno-sse4a -mno-bmi2)
target_compile_options(stormphranj-sse41-popcnt PUBLIC -march=nehalem)
if(NOT MSVC)
target_compile_options(stormphranj-native PUBLIC -mtune=native)
target_compile_options(stormphranj-avx512 PUBLIC -mtune=znver4)
target_compile_options(stormphranj-avx2-bmi2 PUBLIC -mtune=haswell)
target_compile_options(stormphranj-avx2 PUBLIC -mtune=znver2) # zen 2
target_compile_options(stormphranj-sse41-popcnt PUBLIC -mtune=sandybridge)
else() # clang
target_compile_options(stormphranj-native PUBLIC /tune:native)
target_compile_options(stormphranj-avx512 PUBLIC /tune:znver4)
target_compile_options(stormphranj-avx2-bmi2 PUBLIC /tune:haswell)
target_compile_options(stormphranj-avx2 PUBLIC /tune:znver2) # zen 2
target_compile_options(stormphranj-sse41-popcnt PUBLIC /tune:sandybridge)
endif()
if(SPJ_FAST_PEXT)
target_compile_definitions(stormphranj-native PUBLIC SPJ_FAST_PEXT)
endif()
get_directory_property(TARGETS BUILDSYSTEM_TARGETS)
foreach(TARGET ${TARGETS})
string(REPLACE "stormphranj-" "" ARCH_NAME "${TARGET}")
string(REPLACE "-" "_" ARCH_NAME "${ARCH_NAME}")
string(TOUPPER ${ARCH_NAME} ARCH_NAME)
target_compile_definitions(${TARGET} PUBLIC SPJ_VERSION=${CMAKE_PROJECT_VERSION}
SPJ_${ARCH_NAME} SPJ_NETWORK_FILE="${PROJECT_SOURCE_DIR}/src/eval/${SPJ_DEFAULT_NET_NAME}.nnue")
string(REPLACE "stormphranj-" "stormphranj-${CMAKE_PROJECT_VERSION}-" TARGET_NAME "${TARGET}")
set_property(TARGET ${TARGET} PROPERTY OUTPUT_NAME "${TARGET_NAME}")
if(SPJ_EMBED_COMMIT_HASH)
target_compile_definitions(${TARGET} PUBLIC SPJ_COMMIT_HASH=${SPJ_COMMIT_HASH})
endif()
target_link_libraries(${TARGET} Threads::Threads)
endforeach()