-
Notifications
You must be signed in to change notification settings - Fork 88
/
CMakeLists.txt
101 lines (71 loc) · 2.32 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
99
include(GNUInstallDirs)
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 14)
set(PROJECT_VERSION 1.0.0)
project(LibTorchSegmentation VERSION ${PROJECT_VERSION}
DESCRIPTION "Image Segmentation library based on LibTorch")
# First of all set your libtorch path.
set(Torch_DIR $ENV{Torch_DIR}/share/cmake/Torch)
find_package(Torch REQUIRED)
if (Torch_FOUND)
message(STATUS "Torch library found!")
else ()
message(FATAL_ERROR "Could not locate Torch" \n)
endif()
# At this point, OpenCV should be already installed
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV VERSION " ${OpenCV_VERSION})
include_directories(
${OpenCV_INCLUDE_DIRS}
)
find_package(OpenCV REQUIRED)
FILE(GLOB ALL_SOURCES
"src/*.cpp"
"src/architectures/*.cpp"
"src/backbones/*.cpp"
"src/utils/*.cpp"
)
if(BUILD_SHARED)
add_library(segmentation SHARED ${ALL_SOURCES})
message(STATUS "Target shared library")
else()
add_library(segmentation STATIC ${ALL_SOURCES})
message(STATUS "Target static library")
endif()
configure_file(segmentation.pc.in segmentation.pc @ONLY)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/segmentation
FILES_MATCHING
PATTERN "*.h*"
)
install(TARGETS segmentation
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${CMAKE_BINARY_DIR}/segmentation.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"Config.cmake.in"
"SegmentationConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Segmentation
PATH_VARS
CMAKE_INSTALL_LIBDIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/SegmentationConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
### Install Config and ConfigVersion files
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/SegmentationConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/SegmentationConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Segmentation"
)
set_target_properties(segmentation PROPERTIES VERSION ${PROJECT_VERSION})
set(ALL_LIBS
${OpenCV_LIBS}
${TORCH_LIBRARIES}
${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_cudart_static_LIBRARY}
)
target_link_libraries(segmentation ${ALL_LIBS})