Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
205 lines (172 loc) · 8.46 KB
/
Copy pathCMakeLists.txt
File metadata and controls
205 lines (172 loc) · 8.46 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
cmake_minimum_required(VERSION 3.24)
# Load project version from the single source of truth version.txt file
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" LIBARGUS_VERSION_RAW)
string(STRIP "${LIBARGUS_VERSION_RAW}" LIBARGUS_VERSION)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/libargus.h")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/jni/argus_jni.cc")
project(libargus VERSION ${LIBARGUS_VERSION} LANGUAGES C CXX)
add_compile_definitions(LIBARGUS_VERSION="${LIBARGUS_VERSION}")
# A JVM may preload its own app-local MSVC runtime before loading argus.dll.
# Link the release and all statically merged dependencies to the static runtime
# so C++ objects never cross an incompatible host-runtime boundary.
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# Force modern C++ standards across all compiled objects
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Enforce Position Independent Code for Project Panama shared-library mapping
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(FetchContent)
include(cmake/ArgusBuild.cmake)
# =========================================================================
# 1. Global Hardware Acceleration Pipeline Configuration
# =========================================================================
option(GGML_CUDA "Compile with NVIDIA CUDA Core acceleration" OFF)
option(GGML_METAL "Compile with Apple Silicon Metal acceleration" OFF)
option(GGML_HIP "Compile with AMD ROCm/HIP acceleration" OFF)
option(GGML_VULKAN "Compile with Vulkan acceleration" OFF)
set(ARGUS_ACCELERATOR_COUNT 0)
foreach(backend GGML_CUDA GGML_METAL GGML_HIP GGML_VULKAN)
if(${backend})
math(EXPR ARGUS_ACCELERATOR_COUNT "${ARGUS_ACCELERATOR_COUNT} + 1")
endif()
endforeach()
if(ARGUS_ACCELERATOR_COUNT GREATER 1)
message(FATAL_ERROR "Select at most one libargus accelerator backend")
endif()
if(GGML_CUDA)
add_compile_definitions(GGML_USE_CUDA)
set(ARGUS_ACCELERATOR_DEFINITION ARGUS_BUILD_CUDA)
# Enable explicit compiler optimizations for target GPU architectures
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
# Target Turing (7.5), Ampere (8.0, 8.6), Ada Lovelace (8.9), Hopper (9.0) + 90-virtual PTX fallback
set(CMAKE_CUDA_ARCHITECTURES "75-real;80-real;86-real;89-real;90-real;90-virtual")
endif()
endif()
if(GGML_METAL)
add_compile_definitions(GGML_USE_METAL)
set(ARGUS_ACCELERATOR_DEFINITION ARGUS_BUILD_METAL)
endif()
if(GGML_HIP)
add_compile_definitions(GGML_USE_HIP)
set(ARGUS_ACCELERATOR_DEFINITION ARGUS_BUILD_HIP)
endif()
if(GGML_VULKAN)
add_compile_definitions(GGML_USE_VULKAN)
set(ARGUS_ACCELERATOR_DEFINITION ARGUS_BUILD_VULKAN)
endif()
# =========================================================================
# 2. Dependency Isolation & Upstream Bloat Suppression
# =========================================================================
# Force static compilation of upstream components so they merge directly into libargus
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Force static compilation of upstream components so they merge directly into libargus")
# Disable all non-essential upstream components before loading build targets
set(LLAMA_BUILD_EXAMPLES OFF CACHE INTERNAL "Disable llama.cpp CLI applications")
set(LLAMA_BUILD_SERVER OFF CACHE INTERNAL "Disable llama.cpp embedded server binary")
set(LLAMA_BUILD_TESTS OFF CACHE INTERNAL "Disable llama.cpp testing footprint")
set(LLAMA_BUILD_MTMD ON CACHE INTERNAL "Force building the mtmd library standalone")
set(WHISPER_BUILD_EXAMPLES OFF CACHE INTERNAL "Disable whisper.cpp CLI tools")
set(WHISPER_BUILD_TESTS OFF CACHE INTERNAL "Disable whisper.cpp validation tests")
# Fetch core llama.cpp framework layer
FetchContent_Declare(
llamacpp
GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
GIT_TAG ${ARGUS_LLAMA_REVISION}
)
# Fetch core whisper.cpp framework layer
FetchContent_Declare(
whispercpp
GIT_REPOSITORY https://github.com/ggml-org/whisper.cpp.git
GIT_TAG ${ARGUS_WHISPER_REVISION}
)
# Make components available sequentially; whisper automatically inherits the
# pre-existing initialized 'ggml' targets exposed by the llama subproject
FetchContent_MakeAvailable(llamacpp whispercpp)
include(cmake/PatchLlama.cmake)
# =========================================================================
# 3. Target Assembly Configuration (libargus Public Layer)
# =========================================================================
# Gather all local internal source files
set(ARGUS_SOURCES
src/argus_common.cc
src/argus_text.cc
src/argus_audio.cc
src/argus_multimodal.cc
)
if(ARGUS_JNI_ENABLED)
list(APPEND ARGUS_SOURCES src/jni/argus_jni.cc)
endif()
# Standardize build output artifact locations across multi-config generators
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Create the final single process-global shared library target
add_library(argus SHARED ${ARGUS_SOURCES})
# Mark target as building the shared library to activate dllexport on MSVC
target_compile_definitions(argus PRIVATE ARGUS_BUILDING_DLL ${ARGUS_ACCELERATOR_DEFINITION})
# Hide private implementation symbols from static dependencies (ggml, llama, whisper, mtmd)
set_target_properties(argus PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
# Explicitly map unmanaged include paths for compiler visibility
target_include_directories(argus PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${llamacpp_SOURCE_DIR}/ggml/include>
$<BUILD_INTERFACE:${llamacpp_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${llamacpp_SOURCE_DIR}/tools/mtmd>
$<BUILD_INTERFACE:${whispercpp_SOURCE_DIR}/include>
)
# Statically link libargus directly into the isolated tensor primitives
target_link_libraries(argus PRIVATE
llama
whisper
ggml
mtmd
)
argus_configure_target(argus)
# Enable integrated unit tests
enable_testing()
add_executable(test_libargus tests/test_libargus.cc)
target_include_directories(test_libargus PRIVATE include tests)
if(ARGUS_TESTING)
target_compile_definitions(test_libargus PRIVATE ARGUS_TESTING)
target_link_libraries(test_libargus PRIVATE argus_test)
else()
target_link_libraries(test_libargus PRIVATE argus)
endif()
add_test(NAME test_libargus COMMAND test_libargus)
set_tests_properties(test_libargus PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_executable(test_media tests/test_media.cc)
target_link_libraries(test_media PRIVATE argus)
add_test(NAME test_media COMMAND test_media)
set_tests_properties(test_media PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" TIMEOUT 60)
option(ARGUS_MEDIA_REQUIRED "Require real FFmpeg video integration" OFF)
if(ARGUS_MEDIA_REQUIRED)
find_program(ARGUS_FFMPEG ffmpeg REQUIRED)
find_program(ARGUS_FFPROBE ffprobe REQUIRED)
add_test(NAME test_video COMMAND test_media --video)
set_tests_properties(test_video PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" TIMEOUT 60)
endif()
if(ARGUS_TESTING)
add_library(argus_test SHARED ${ARGUS_SOURCES} tests/native_test_hooks.cc)
target_compile_definitions(argus_test PRIVATE ARGUS_BUILDING_DLL ARGUS_TESTING ${ARGUS_ACCELERATOR_DEFINITION})
target_include_directories(argus_test PRIVATE src tests)
target_link_libraries(argus_test PRIVATE llama whisper ggml mtmd)
target_include_directories(argus_test PUBLIC ${CMAKE_SOURCE_DIR}/include
${llamacpp_SOURCE_DIR}/include ${llamacpp_SOURCE_DIR}/tools/mtmd
${whispercpp_SOURCE_DIR}/include ${llamacpp_SOURCE_DIR}/ggml/include)
argus_configure_target(argus_test)
add_executable(test_concurrency tests/test_concurrency.cc)
target_include_directories(test_concurrency PRIVATE tests src)
target_link_libraries(test_concurrency PRIVATE argus_test)
add_test(NAME test_concurrency COMMAND test_concurrency)
set_tests_properties(test_concurrency PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" TIMEOUT 60)
endif()