| 1 |
set(FOLDER_NAME "thirdparty") |
| 2 |
|
| 3 |
# Only show moderate warnings for external library code. |
| 4 |
if(IS_MSVC) |
| 5 |
string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 6 |
string(REGEX REPLACE "/Wall" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 7 |
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 8 |
string(REGEX REPLACE "/Wall" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 9 |
elseif(IS_GNU OR IS_CLANG) |
| 10 |
string(REGEX REPLACE "-Wall" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 11 |
string(REGEX REPLACE "-Wall" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 12 |
endif() |
| 13 |
|
| 14 |
if(IS_MSVC) |
| 15 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0") |
| 16 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0") |
| 17 |
elseif(IS_GNU OR IS_CLANG) |
| 18 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") |
| 19 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") |
| 20 |
endif() |
| 21 |
|
| 22 |
set(CLANG_TIDY_EXE_TEMP ${CLANG_TIDY_EXE}) |
| 23 |
set(CLANG_TIDY_EXE "") |
| 24 |
if(LSD_ENABLED) |
| 25 |
add_subdirectory(LSD) |
| 26 |
endif() |
| 27 |
add_subdirectory(PoissonRecon) |
| 28 |
if(GPU_ENABLED) |
| 29 |
add_subdirectory(SiftGPU) |
| 30 |
endif() |
| 31 |
add_subdirectory(VLFeat) |
| 32 |
|
| 33 |
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.28") |
| 34 |
set(_fetch_content_declare_args "SYSTEM" "EXCLUDE_FROM_ALL") |
| 35 |
endif() |
| 36 |
|
| 37 |
if(FETCH_POSELIB) |
| 38 |
include(FetchContent) |
| 39 |
FetchContent_Declare(poselib |
| 40 |
URL https://github.com/PoseLib/PoseLib/archive/fa7280fee27f97aff31ae7f98bab7f583fac7d08.zip |
| 41 |
URL_HASH SHA256=5408d4ae8ce367cb2f076bc6c5f0f6f78abd3573d2c015304b04e46f23455f5b |
| 42 |
${_fetch_content_declare_args} |
| 43 |
) |
| 44 |
message(STATUS "Configuring PoseLib...") |
| 45 |
set(MARCH_NATIVE OFF CACHE BOOL "") |
| 46 |
FetchContent_MakeAvailable(poselib) |
| 47 |
# Rename PoseLib's benchmark folder to avoid conflict with Google Benchmark's |
| 48 |
# benchmark/benchmark.h header (PoseLib exposes its entire source dir as include path) |
| 49 |
if(EXISTS "${poselib_SOURCE_DIR}/benchmark") |
| 50 |
file(RENAME "${poselib_SOURCE_DIR}/benchmark" "${poselib_SOURCE_DIR}/poselib_benchmark") |
| 51 |
endif() |
| 52 |
message(STATUS "Configuring PoseLib... done") |
| 53 |
endif() |
| 54 |
|
| 55 |
if(FETCH_FAISS) |
| 56 |
include(FetchContent) |
| 57 |
FetchContent_Declare(faiss |
| 58 |
URL https://github.com/facebookresearch/faiss/archive/refs/tags/v1.14.1.zip |
| 59 |
URL_HASH SHA256=4b1ae7e7a0a46385b4084f0e3945623a15fcf99d793bf44d82aae8e24f11e5f5 |
| 60 |
${_fetch_content_declare_args} |
| 61 |
) |
| 62 |
message(STATUS "Configuring faiss...") |
| 63 |
# Use dynamic dispatch (dd) to automatically select the highest SIMD |
| 64 |
# instruction set supported by the target machine (e.g., AVX2, AVX512). |
| 65 |
# Dynamic dispatch is not supported on MSVC (faiss v1.14.1). |
| 66 |
if(NOT IS_MSVC) |
| 67 |
set(FAISS_OPT_LEVEL dd) |
| 68 |
endif() |
| 69 |
set(FAISS_ENABLE_GPU OFF) |
| 70 |
set(FAISS_ENABLE_PYTHON OFF) |
| 71 |
set(FAISS_ENABLE_MKL OFF) |
| 72 |
set(BUILD_TESTING OFF) |
| 73 |
FetchContent_MakeAvailable(faiss) |
| 74 |
# Fix MSVC linker warning LNK4286: faiss headers use FAISS_API which |
| 75 |
# defaults to dllimport on Windows, but we build faiss as a static library. |
| 76 |
# Adding FAISS_MAIN_LIB as PUBLIC ensures consumers also get this defined. |
| 77 |
if(WIN32 AND TARGET faiss) |
| 78 |
target_compile_definitions(faiss PUBLIC FAISS_MAIN_LIB) |
| 79 |
endif() |
| 80 |
message(STATUS "Configuring faiss... done") |
| 81 |
endif() |
| 82 |
|
| 83 |
if(CASPAR_ENABLED AND NOT CUDA_ENABLED) |
| 84 |
message(FATAL_ERROR "Caspar requires CUDA") |
| 85 |
endif() |
| 86 |
|
| 87 |
if(CASPAR_ENABLED AND CUDA_ENABLED) |
| 88 |
|
| 89 |
# TODO(tordnat): Make Caspar set CASPAR_MIN_ARCH when generating build files |
| 90 |
set(CASPAR_MIN_ARCH 75) |
| 91 |
foreach(_arch ${CMAKE_CUDA_ARCHITECTURES}) |
| 92 |
if(_arch LESS ${CASPAR_MIN_ARCH}) |
| 93 |
message(FATAL_ERROR "Caspar requires CUDA architecture >= ${CASPAR_MIN_ARCH}, but ${_arch} was requested. " |
| 94 |
"Set CMAKE_CUDA_ARCHITECTURES to ${CASPAR_MIN_ARCH} or higher, or disable Caspar with -DCASPAR_ENABLED=OFF.") |
| 95 |
endif() |
| 96 |
endforeach() |
| 97 |
|
| 98 |
message(STATUS "Enabling Caspar support") |
| 99 |
|
| 100 |
if(CASPAR_USE_DOUBLE) |
| 101 |
set(_caspar_precision "f64") |
| 102 |
else() |
| 103 |
set(_caspar_precision "f32") |
| 104 |
endif() |
| 105 |
|
| 106 |
set(CASPAR_GEN_DIR |
| 107 |
"${CMAKE_SOURCE_DIR}/src/thirdparty/Symforce-Caspar/generated/${_caspar_precision}") |
| 108 |
|
| 109 |
if(NOT EXISTS "${CASPAR_GEN_DIR}/CMakeLists.txt") |
| 110 |
message(FATAL_ERROR |
| 111 |
"Caspar: pre-generated code not found for precision '${_caspar_precision}'.\n" |
| 112 |
"Expected: ${CASPAR_GEN_DIR}/CMakeLists.txt\n" |
| 113 |
"Re-run generate_caspar.py to regenerate.") |
| 114 |
endif() |
| 115 |
|
| 116 |
include(FetchContent) |
| 117 |
FetchContent_Declare(caspar |
| 118 |
SOURCE_DIR ${CASPAR_GEN_DIR} |
| 119 |
${_fetch_content_declare_args} |
| 120 |
) |
| 121 |
message(STATUS "Configuring Caspar...") |
| 122 |
FetchContent_MakeAvailable(caspar) |
| 123 |
# Wrap the source-tree include path in BUILD_INTERFACE so caspar_lib_core |
| 124 |
# can be part of install(EXPORT). Caspar's generated CMakeLists.txt uses a |
| 125 |
# raw ${CMAKE_CURRENT_SOURCE_DIR} which CMake rejects on exported targets. |
| 126 |
set_target_properties(caspar_lib_core PROPERTIES |
| 127 |
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CASPAR_GEN_DIR}>") |
| 128 |
# Silence warnings from auto-generated Caspar CUDA sources, matching the |
| 129 |
# blanket `-w`/`/W0` policy applied to other thirdparty C++ code above. |
| 130 |
target_compile_options(caspar_lib_core PRIVATE |
| 131 |
$<$<COMPILE_LANGUAGE:CUDA>:-w> |
| 132 |
$<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe=--diag_suppress=550> |
| 133 |
$<$<COMPILE_LANGUAGE:CXX>:$<IF:$<CXX_COMPILER_ID:MSVC>,/W0,-w>> |
| 134 |
) |
| 135 |
if(IS_MSVC) |
| 136 |
set(_MSVC_COMPACT_HEADER "${CASPAR_GEN_DIR}/../../msvc_compact.h") |
| 137 |
set(_MSVC_CUDA_COMPACT_HEADER "${CASPAR_GEN_DIR}/../../msvc_cuda_compact.h") |
| 138 |
target_compile_options(caspar_lib_core PRIVATE |
| 139 |
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/FI"${_MSVC_COMPACT_HEADER}"> |
| 140 |
# Keep CUDA pre-includes minimal and use NVCC's native pre-include |
| 141 |
# option to avoid forcing C++ standard library headers into NVCC's |
| 142 |
# MSVC host pass. |
| 143 |
$<$<COMPILE_LANGUAGE:CUDA>:--pre-include="${_MSVC_CUDA_COMPACT_HEADER}"> |
| 144 |
) |
| 145 |
endif() |
| 146 |
message(STATUS "Configuring Caspar... done") |
| 147 |
|
| 148 |
message(STATUS "Caspar precision: ${_caspar_precision}") |
| 149 |
message(STATUS "Caspar source dir: ${CASPAR_GEN_DIR}") |
| 150 |
endif() |
| 151 |
|
| 152 |
set(CLANG_TIDY_EXE ${CLANG_TIDY_EXE_TEMP}) |