forked from natpate/ninfer-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
117 lines (105 loc) · 4.08 KB
/
Copy pathCMakeLists.txt
File metadata and controls
117 lines (105 loc) · 4.08 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
cmake_minimum_required(VERSION 3.28)
# The current implementation is compiled only for sm_120a. Set and validate the
# architecture before CUDA compiler detection so CMake never injects a generic
# host-toolchain default or accepts an unsupported target.
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 120a CACHE STRING "CUDA architectures to build")
endif()
if(NOT CMAKE_CUDA_ARCHITECTURES STREQUAL "120a")
message(FATAL_ERROR
"NInfer supports only CMAKE_CUDA_ARCHITECTURES=120a; got "
"'${CMAKE_CUDA_ARCHITECTURES}'")
endif()
project(ninfer LANGUAGES C CXX CUDA)
# --- Global settings ---------------------------------------------------------
option(NINFER_BUILD_APPS "Build the NInfer CLI and server" ON)
option(BUILD_TESTING "Build NInfer tests" OFF)
option(NINFER_BUILD_BENCHMARKS "Build NInfer benchmarks" OFF)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # clangd / IDE tooling
if(MSVC)
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
# MSVC encodes narrow string literals in the locale codepage unless /utf-8 is set. The fmt
# bundled with spdlog static-asserts that the literal encoding is UTF-8, so pass /utf-8 to
# every host-compiled translation unit (and to the CUDA host passes via -Xcompiler).
add_compile_options(
$<$<COMPILE_LANGUAGE:C,CXX>:/Zc:preprocessor>
$<$<COMPILE_LANGUAGE:C,CXX>:/utf-8>
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/Zc:preprocessor>
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/utf-8>)
# CUDA's static runtime requests LIBCMT even when the application and vcpkg dependencies use
# the project-wide /MD runtime. Keep one CRT in the final process.
add_link_options(/NODEFAULTLIB:LIBCMT)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_GENERATOR MATCHES "Ninja")
set_property(GLOBAL PROPERTY JOB_POOLS cuda_link=1)
set(CMAKE_JOB_POOL_LINK cuda_link)
endif()
if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 13.1)
message(FATAL_ERROR
"NInfer requires CUDA 13.1 or newer; found CUDA compiler "
"${CMAKE_CUDA_COMPILER_VERSION}")
endif()
set(NINFER_BUILD_MEDIA_ACQUIRE OFF)
if(NINFER_BUILD_APPS OR BUILD_TESTING)
set(NINFER_BUILD_MEDIA_ACQUIRE ON)
endif()
set(NINFER_BUILD_PROMPT_INPUT OFF)
if(NINFER_BUILD_APPS OR BUILD_TESTING)
set(NINFER_BUILD_PROMPT_INPUT ON)
endif()
set(NINFER_BUILD_SERVE OFF)
if(NINFER_BUILD_APPS OR BUILD_TESTING)
set(NINFER_BUILD_SERVE ON)
endif()
find_package(CUDAToolkit REQUIRED)
if(WIN32)
set(NINFER_CUDART_TARGET CUDA::cudart_static)
else()
set(NINFER_CUDART_TARGET CUDA::cudart)
endif()
if(WIN32 OR DEFINED VCPKG_TARGET_TRIPLET)
find_package(FFMPEG REQUIRED)
add_library(ninfer_ffmpeg_dependencies INTERFACE)
target_include_directories(ninfer_ffmpeg_dependencies INTERFACE ${FFMPEG_INCLUDE_DIRS})
target_link_directories(ninfer_ffmpeg_dependencies INTERFACE ${FFMPEG_LIBRARY_DIRS})
target_link_libraries(ninfer_ffmpeg_dependencies INTERFACE ${FFMPEG_LIBRARIES})
set(NINFER_FFMPEG_TARGET ninfer_ffmpeg_dependencies)
if(NINFER_BUILD_MEDIA_ACQUIRE)
find_package(CURL 7.85 REQUIRED)
set(NINFER_CURL_TARGET CURL::libcurl)
endif()
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET
libavformat>=60 libavcodec>=60 libavutil>=58 libswscale>=7)
set(NINFER_FFMPEG_TARGET PkgConfig::FFMPEG)
if(NINFER_BUILD_MEDIA_ACQUIRE)
pkg_check_modules(LIBCURL REQUIRED IMPORTED_TARGET libcurl>=7.85)
set(NINFER_CURL_TARGET PkgConfig::LIBCURL)
endif()
endif()
find_package(Threads REQUIRED)
if(NINFER_BUILD_APPS OR BUILD_TESTING)
# Product operational logging is an offline, repository-pinned dependency. Core-only builds do
# not configure or link it.
add_subdirectory(third_party/spdlog)
endif()
# --- Subdirectories ----------------------------------------------------------
add_subdirectory(src)
if(NINFER_BUILD_APPS)
add_subdirectory(apps)
endif()
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
if(NINFER_BUILD_BENCHMARKS)
add_subdirectory(bench)
endif()