-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
98 lines (81 loc) · 3.76 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
cmake_minimum_required(VERSION 3.17)
# We enabled NDEBUG even for debug builds because a gcc bug leads to a spurious assert() deep
# in the eigen3 library
add_definitions(-DNDEBUG)
set(CAFFE2_USE_CUDNN ON CACHE BOOL "Enable cuDNN support")
# Currently needed for gcc 12+
set(ENV{NVCC_APPEND_FLAGS} "-allow-unsupported-compiler")
# First-class CUDA support
project(alphazero LANGUAGES CXX CUDA)
find_package (Eigen3 3.4 REQUIRED NO_MODULE)
find_package(Torch REQUIRED PATHS ${MY_TORCH_DIR})
find_package(Boost COMPONENTS program_options filesystem json log log_setup REQUIRED)
find_package(GTest REQUIRED)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wshadow -Wno-array-bounds ${TORCH_CXX_FLAGS} -ftemplate-backtrace-limit=50 ${EXTRA_DEFINITIONS}")
# We protect with this if-condition so that clangd-based IDE tools don't complain, as clang does not
# support the -ftemplate-backtrace-limit flag
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-backtrace-limit=50")
endif()
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
include_directories("cpp/include")
include_directories("cpp") # for inline/ subdirectory
include_directories(${EIGEN3_INCLUDE_DIRS})
include_directories(${MY_EIGENRAND_DIR})
include_directories(SYSTEM ${TORCH_INCLUDE_DIRS})
include_directories(${GTEST_INCLUDE_DIRS})
# Clear the targets file at the start of the configuration
file(WRITE ${CMAKE_BINARY_DIR}/targets.txt "")
# Function to append target metadata to the targets.txt file
function(append_target_metadata game_name)
foreach(target ${ARGN})
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL "EXECUTABLE")
get_target_property(output_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
if(NOT output_dir)
set(output_dir "${CMAKE_BINARY_DIR}/bin")
endif()
get_target_property(output_name ${target} OUTPUT_NAME)
if(NOT output_name)
set(output_name ${target})
endif()
file(APPEND ${CMAKE_BINARY_DIR}/targets.txt "${game_name} ${target} ${output_dir} ${output_name}\n")
elseif(target_type STREQUAL "SHARED_LIBRARY")
get_target_property(output_dir ${target} LIBRARY_OUTPUT_DIRECTORY)
if(NOT output_dir)
set(output_dir "${CMAKE_BINARY_DIR}/lib")
endif()
get_target_property(output_name ${target} OUTPUT_NAME)
if(NOT output_name)
set(output_name ${target})
endif()
file(APPEND ${CMAKE_BINARY_DIR}/targets.txt "${game_name} ${target} ${output_dir} lib${output_name}.so\n")
endif()
endforeach()
endfunction()
set(COMMON_EXTERNAL_LIBS ${TORCH_LIBRARIES} ${Boost_LIBRARIES})
set(GTEST_LIBS GTest::GTest GTest::Main gtest)
add_subdirectory("cpp/src")
add_subdirectory("cpp/src/games/blokus")
add_subdirectory("cpp/src/games/chess")
add_subdirectory("cpp/src/games/connect4")
add_subdirectory("cpp/src/games/othello")
add_subdirectory("cpp/src/games/tictactoe")
add_subdirectory("cpp/src/games/nim")
add_subdirectory("cpp/src/games/stochastic_nim")
add_subdirectory("cpp/src/mcts")
add_subdirectory("cpp/src/generic_players")
# https://stackoverflow.com/a/31390758/543913
macro(print_all_variables)
message(STATUS "print_all_variables------------------------------------------{")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "print_all_variables------------------------------------------}")
endmacro()
# print_all_variables()