-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
50 lines (45 loc) · 1.64 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
cmake_minimum_required(VERSION 3.4)
project(libtorch_examples)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(libtorch_VERSION 1.4.0)
find_package(Torch ${libtorch_VERSION} EXACT QUIET CONFIG)
if(NOT Torch_FOUND)
message(STATUS "libtorch ${libtorch_VERSION} - not found")
message(STATUS "Fetching libtorch")
include(FetchContent)
FetchContent_Declare(
libtorch
URL https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-${libtorch_VERSION}.zip
SOURCE_DIR libtorch)
FetchContent_GetProperties(libtorch)
if(NOT libtorch_POPULATED)
unset(FETCHCONTENT_QUIET CACHE)
FetchContent_Populate(libtorch)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/libtorch)
endif()
find_package(Torch ${libtorch_VERSION} EXACT CONFIG REQUIRED)
else()
message(STATUS "libtorch ${libtorch_VERSION} - found")
endif()
macro(add_example name)
add_executable(${name} src/${name}.cpp)
target_include_directories(${name} PRIVATE include)
target_link_libraries(${name} ${TORCH_LIBRARIES})
endmacro()
add_example(hello_world)
add_example(simple_optimization_example)
add_example(function_approx)
add_example(time_serie_prediction)
add_example(lstm_example)
add_example(dataset_example)
# Tools
include(${CMAKE_CURRENT_LIST_DIR}/cmake/ClangTools.cmake OPTIONAL
RESULT_VARIABLE CLANG_TOOLS)
if(CLANG_TOOLS)
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)
add_format_target(${PROJECT_NAME} FILES ${SOURCES} ${HEADERS})
add_tidy_target(${PROJECT_NAME} FILES ${SOURCES})
endif()