This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathCMakeLists.txt
89 lines (79 loc) · 2.41 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
cmake_minimum_required(VERSION 3.10.0)
project(CppRl
LANGUAGES CXX
VERSION 1.2.0
DESCRIPTION "Reinforcement learning in C++ using PyTorch"
)
# Project-wide properties
set(CMAKE_CXX_STANDARD 17)
# Cppcheck
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
list(APPEND CPPCHECK_ARGS
--enable=warning
--std=c++14
--force
--verbose
--quiet
--inline-suppr
--error-exitcode=1
--language=c++
--config-exclude=${CMAKE_CURRENT_LIST_DIR}/src/third_party
--config-exclude=${CMAKE_CURRENT_LIST_DIR}/lib
-i${CMAKE_CURRENT_LIST_DIR}/example/lib
--suppressions-list=${CMAKE_CURRENT_LIST_DIR}/CppCheckSuppressions.txt
-I ${CMAKE_CURRENT_LIST_DIR}/src
-I ${CMAKE_CURRENT_LIST_DIR}/include
-I ${CMAKE_CURRENT_LIST_DIR}/example
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/example
)
add_custom_target(
check
COMMAND cppcheck ${CPPCHECK_ARGS}
COMMENT "Running Cppcheck"
)
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# Dependencies
## PyTorch
if (NOT TORCH_FOUND)
find_package(Torch REQUIRED)
if (TORCH_CXX_FLAGS)
set(CMAKE_CXX_FLAGS ${TORCH_CXX_FLAGS})
endif()
endif (NOT TORCH_FOUND)
# Define targets
add_library(cpprl STATIC "")
target_compile_definitions(cpprl PRIVATE DOCTEST_CONFIG_DISABLE)
option(CPPRL_BUILD_TESTS "Whether or not to build the CppRl tests" ON)
if (CPPRL_BUILD_TESTS)
add_executable(cpprl_tests "")
endif(CPPRL_BUILD_TESTS)
# Enable all warnings
if(MSVC)
target_compile_options(cpprl PRIVATE /W0)
else(MSVC)
target_compile_options(cpprl PRIVATE -Wall -Wextra -pedantic)
endif(MSVC)
# Includes
set(CPPRL_INCLUDE_DIRS
include
src
${TORCH_INCLUDE_DIRS}
)
target_include_directories(cpprl PRIVATE ${CPPRL_INCLUDE_DIRS})
if (CPPRL_BUILD_TESTS)
target_include_directories(cpprl_tests PRIVATE ${CPPRL_INCLUDE_DIRS})
endif(CPPRL_BUILD_TESTS)
# Linking
target_link_libraries(cpprl torch ${TORCH_LIBRARIES})
target_link_libraries(cpprl torch ${TORCH_LIBRARIES})
if (CPPRL_BUILD_TESTS)
target_link_libraries(cpprl_tests torch ${TORCH_LIBRARIES})
endif(CPPRL_BUILD_TESTS)
# Example
option(CPPRL_BUILD_EXAMPLE "Whether or not to build the CppRl Gym example" ON)
if (CPPRL_BUILD_EXAMPLE)
add_subdirectory(example)
endif(CPPRL_BUILD_EXAMPLE)
# Recurse into source tree
add_subdirectory(src)