-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
58 lines (46 loc) · 1.48 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
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(predator_prey)
# Include what you use detector
find_program(IWYU NAMES include-what-you-use)
if(IWYU)
message(STATUS "executing include-what-you-use")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU})
endif()
# Set parameters
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# Add the executable
file(GLOB SOURCES src/*.cpp include/*.h)
add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE src/ include/)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
target_compile_options(
${PROJECT_NAME}
PUBLIC -Werror
-Wall
-Wextra
-O3
-flto=auto
-fpic
-pthread
-ffunction-sections
-fdata-sections)
# Link
add_subdirectory(lib/robosimcpp)
target_link_libraries(${PROJECT_NAME} PRIVATE robosim)
target_include_directories(${PROJECT_NAME} PRIVATE lib/robosimcpp/include)
# torch
find_package(Torch REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES})
# Link
# The following code block is suggested to be used on Windows. According to
# https://github.com/pytorch/pytorch/issues/25457, the DLLs need to be copied to
# avoid memory errors.
if(MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll
")
add_custom_command(
TARGET example-app
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TORCH_DLLS}
$<TARGET_FILE_DIR:example-app>)
endif(MSVC)