|
1 | 1 | cmake_minimum_required(VERSION 3.10) |
2 | | -project(chess_engine) |
| 2 | +project(cppchess_engine) |
3 | 3 |
|
4 | 4 | # Use C++17 |
5 | 5 | set(CMAKE_CXX_STANDARD 17) |
6 | 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
7 | | - |
8 | | -# Optional: enable warnings (MSVC specific flags) |
9 | | -if (MSVC) |
10 | | - add_compile_options(/W4 /permissive-) |
11 | | -else() |
12 | | - add_compile_options(-Wall -Wextra -pedantic) |
13 | | -endif() |
14 | | - |
15 | | -# Add the source files |
16 | | -set(SOURCES |
17 | | - main.cpp |
18 | | - eval.cpp |
19 | | - search.cpp |
20 | | - tt.cpp |
21 | | - movepick.cpp |
22 | | - uci.cpp |
23 | | - ucioptions.cpp |
24 | | - timeman.cpp |
| 7 | +include(FetchContent) |
| 8 | +set(BUILD_TESTING OFF) |
| 9 | +FetchContent_Declare( |
| 10 | + chesslib |
| 11 | + GIT_REPOSITORY https://github.com/winapiadmin/chesslib.git |
| 12 | + GIT_TAG main |
| 13 | +) |
| 14 | +FetchContent_Declare( |
| 15 | + tbprobe |
| 16 | + GIT_REPOSITORY https://github.com/winapiadmin/tb_probing_tool.git |
| 17 | + GIT_TAG main |
| 18 | +) |
| 19 | +set(BUILD_GAVIOTA OFF CACHE BOOL "Enable Gaviota TB probing" FORCE) |
| 20 | +option(ENGINE_TUNING "enable Texel tuning (requires csv-parser)" OFF) |
| 21 | +FetchContent_MakeAvailable(chesslib tbprobe) |
| 22 | +set(SOURCES |
| 23 | + "main.cpp" |
| 24 | + "timeman.cpp" |
| 25 | + "eval.cpp" |
| 26 | + "tune.cpp" |
| 27 | + "ucioption.cpp" |
| 28 | + "tt.cpp" |
| 29 | + "uci.cpp" |
| 30 | + "search.cpp" |
| 31 | + "score.cpp" |
| 32 | + "movepick.cpp" |
| 33 | + "tb.cpp" |
25 | 34 | ) |
26 | 35 |
|
27 | | -# Define the executable |
28 | | -add_executable(${PROJECT_NAME} ${SOURCES}) |
29 | | - |
30 | | -# Threading support |
31 | | -find_package(Threads REQUIRED) |
32 | | -target_link_libraries(${PROJECT_NAME} Threads::Threads) |
33 | | - |
34 | | -# Platform-specific threading configurations |
35 | | -if(WIN32) |
36 | | - if(MSVC) |
37 | | - # Windows with MSVC - uses Windows threading API |
38 | | - target_compile_definitions(${PROJECT_NAME} PRIVATE WIN32_LEAN_AND_MEAN) |
39 | | - elseif(MINGW) |
40 | | - # MinGW on Windows - uses pthread |
41 | | - target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN32_WINNT=0x0601) |
42 | | - # MinGW might need explicit pthread linking |
43 | | - if(CMAKE_THREAD_LIBS_INIT) |
44 | | - target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) |
45 | | - endif() |
46 | | - endif() |
47 | | -elseif(UNIX) |
48 | | - # Unix/Linux systems - uses pthread |
49 | | - if(CMAKE_THREAD_LIBS_INIT) |
50 | | - target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) |
51 | | - endif() |
52 | | - # Some older systems might need explicit -pthread flag |
53 | | - if(CMAKE_USE_PTHREADS_INIT) |
54 | | - target_compile_options(${PROJECT_NAME} PRIVATE -pthread) |
55 | | - target_link_options(${PROJECT_NAME} PRIVATE -pthread) |
56 | | - endif() |
| 36 | +if(ENGINE_TUNING) |
| 37 | + list(APPEND SOURCES "tune_cmd.cpp") |
57 | 38 | endif() |
58 | 39 |
|
59 | | -# Optional: Add atomic library support for older compilers |
60 | | -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9") |
61 | | - target_link_libraries(${PROJECT_NAME} atomic) |
62 | | -endif() |
| 40 | +add_executable(engine ${SOURCES}) |
63 | 41 |
|
64 | | -# Set default build type if none is specified |
65 | | -if(NOT CMAKE_BUILD_TYPE) |
66 | | - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type (Debug, Release, etc.)" FORCE) |
| 42 | +target_link_libraries(engine PRIVATE chesslib syzygy_probe) |
| 43 | +target_include_directories(engine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${chesslib_SOURCE_DIR}) |
| 44 | +execute_process( |
| 45 | + COMMAND git rev-parse --short HEAD |
| 46 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 47 | + ERROR_QUIET |
| 48 | + OUTPUT_VARIABLE GIT_SHA |
| 49 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 50 | +) |
| 51 | +if(GIT_SHA STREQUAL "") |
| 52 | + set(GIT_SHA "unknown") |
67 | 53 | endif() |
| 54 | +execute_process( |
| 55 | + COMMAND git describe --tags --exact-match |
| 56 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 57 | + OUTPUT_VARIABLE GIT_TAG |
| 58 | + ERROR_QUIET |
| 59 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 60 | +) |
68 | 61 |
|
69 | | -# Optional: Add specific compile flags per build type |
70 | | -if(NOT MSVC) |
71 | | - set(CMAKE_CXX_FLAGS_DEBUG "-g -march=native -mtune=native") |
72 | | - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native -mtune=native -funroll-loops -ftree-vectorize -fomit-frame-pointer") |
| 62 | +if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR NOT CMAKE_BUILD_TYPE) |
| 63 | + set(BUILD_VERSION "debug-${GIT_SHA}") |
| 64 | +elseif(GIT_TAG) |
| 65 | + set(BUILD_VERSION "${GIT_TAG}") |
73 | 66 | else() |
74 | | - set(CMAKE_CXX_FLAGS_DEBUG "/Zi /Od") |
75 | | - set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG") |
| 67 | + set(BUILD_VERSION "release-${GIT_SHA}") |
| 68 | +endif() |
| 69 | + |
| 70 | +message(STATUS "Build Version: ${BUILD_VERSION}") |
| 71 | +target_compile_definitions(engine PRIVATE BUILD_VERSION="${BUILD_VERSION}") |
| 72 | +if (ENGINE_TUNING) |
| 73 | + FetchContent_Declare( |
| 74 | + csv |
| 75 | + GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser.git |
| 76 | + GIT_TAG master |
| 77 | + ) |
| 78 | + FetchContent_MakeAvailable(csv) |
| 79 | + target_link_libraries(engine PRIVATE csv) |
| 80 | + target_compile_definitions(engine PRIVATE USE_CSV_PARSER) |
76 | 81 | endif() |
0 commit comments