-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
79 lines (69 loc) · 2.71 KB
/
CMakeLists.txt
File metadata and controls
79 lines (69 loc) · 2.71 KB
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
cmake_minimum_required(VERSION 3.16)
project(chesslib LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# --- Compiler tuning ---
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
# clang-cl: forward GCC/Clang style constexpr flags via /clang:
add_compile_options(
/clang:-fconstexpr-steps=2000000000
/clang:-fconstexpr-depth=1024
/clang:-march=native
/clang:-mtune=native
/clang:-ftemplate-backtrace-limit=0
)
else()
# native clang++ on *nix or Windows
add_compile_options(
-fconstexpr-steps=2000000000
-fconstexpr-depth=1024
-march=native -mtune=native
-ftemplate-backtrace-limit=0 -static
)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fconstexpr-ops-limit=2000000000 -fconstexpr-depth=1024 -march=native -mtune=native -ftemplate-backtrace-limit=0 -static)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(ARCH_FLAG "/arch:AVX2" CACHE STRING "MSVC architecture flag (/arch:SSE2, /arch:AVX, /arch:AVX2, /arch:AVX512)")
add_compile_options(/constexpr:steps2000000000 /constexpr:depth1024 ${ARCH_FLAG})
endif()
add_compile_definitions(GENERATE_AT_RUNTIME)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_definitions(_DEBUG)
endif()
# --- Core Library ---
set(SOURCES
position.cpp
attacks.cpp "zobrist.cpp"
"moves_io.cpp" "printers.cpp" "movegen.cpp")
add_library(chesslib STATIC ${SOURCES})
target_include_directories(chesslib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# --- Enable CTest integration ---
include(CTest)
if(BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(
doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
GIT_TAG v2.4.12
)
FetchContent_MakeAvailable(doctest)
# --- Test executable ---
add_executable(test_normal tests.cpp)
add_executable(test_chess960 chess960_tests.cpp)
add_executable(NonImportantTests non_core_tests.cpp)
target_link_libraries(test_normal PRIVATE chesslib doctest::doctest)
target_link_libraries(NonImportantTests PRIVATE chesslib doctest::doctest)
target_link_libraries(test_chess960 PRIVATE chesslib doctest::doctest)
add_test(NAME test_normal COMMAND test_normal)
add_test(NAME test_api COMMAND NonImportantTests)
add_test(NAME test_chess960 COMMAND test_chess960)
if (UNIX AND CMAKE_BUILD_TYPE MATCHES "Debug")
set(SANITIZERS "" CACHE STRING "sanitizers such as undefined,address")
if (NOT "${SANITIZERS}" STREQUAL "")
add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer)
add_link_options(-fsanitize=${SANITIZERS})
endif()
endif()
endif()