forked from hijkzzz/alpha-zero-gomoku
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
55 lines (43 loc) · 1.56 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
cmake_minimum_required(VERSION 3.8.0)
project(library)
# option
option(WRAP_LIB "wrap library" ON)
option(UNIT_TEST "unit test" OFF)
# gcc
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_STANDARD 14)
endif()
# find torch
find_package(PythonInterp REQUIRED)
# set(CMAKE_PREFIX_PATH /root/alphazero-gomoku/alpha-zero-gomoku-master/build/libtorch/share/cmake/Torch)
# set it to the link to your conda torch
set(CMAKE_PREFIX_PATH /home/mwj/anaconda3/envs/alphazero-gomoku/lib/python3.7/site-packages/torch/share/cmake/Torch)
find_package(Torch REQUIRED)
# find swig
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
# find python
find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})
# add sources
include_directories(./src)
aux_source_directory(./src SOURCES)
# swig
if(WRAP_LIB)
set_property(SOURCE ./src/library.i PROPERTY CPLUSPLUS ON)
swig_add_library(library TYPE SHARED LANGUAGE python SOURCES ./src/library.i ${SOURCES})
swig_link_libraries(library ${PYTHON_LIBRARIES} ${TORCH_LIBRARIES})
endif()
# unit test
if(UNIT_TEST)
add_library(test_lib ${SOURCES})
target_link_libraries(test_lib ${TORCH_LIBRARIES})
add_executable(thread_pool_test ./test/thread_pool_test.cpp)
target_link_libraries(thread_pool_test test_lib)
add_executable(gomoku_test ./test/gomoku_test.cpp)
target_link_libraries(gomoku_test test_lib)
add_executable(libtorch_test ./test/libtorch_test.cpp)
target_link_libraries(libtorch_test test_lib)
add_executable(mcts_test ./test/mcts_test.cpp)
target_link_libraries(mcts_test test_lib)
endif()