-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 614061ad4..a93499b01 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -23,6 +23,8 @@ option(FILAMENT_TESTS "Build tests" ON) | ||
|
||
option(FILAMENT_BENCHMARKS "Build benchmarks" ON) | ||
|
||
+option(FILAMENT_PREFER_EXTERNAL "Prefer the dependencies found externally via CMake" OFF) | ||
+ | ||
option(FILAMENT_USE_EXTERNAL_GLES3 "Experimental: Compile Filament against OpenGL ES 3" OFF) | ||
|
||
option(FILAMENT_ENABLE_LTO "Enable link-time optimizations if supported by the compiler" OFF) | ||
@@ -718,9 +720,58 @@ endfunction() | ||
# Sub-projects | ||
# ================================================================================================== | ||
|
||
+set(added_subdirectories) | ||
+ | ||
+# Add an external library suth that | ||
+# - prefer find_package if FILAMENT_PREFER_EXTERNAL defined | ||
+# - otherwise add the external subdirectory | ||
+macro(add_external_library package_name subdirectory targets target_aliases) | ||
+ if(FILAMENT_PREFER_EXTERNAL) | ||
+ find_package(${package_name}) | ||
+ | ||
+ # add aliases for targets | ||
+ foreach(target target_alias IN ZIP_LISTS targets target_aliases) | ||
+ if(TARGET ${target} AND NOT "${target}" STREQUAL "${target_alias}") | ||
+ get_target_property(target_type ${target} TYPE) | ||
+ if (${target_type} STREQUAL "EXECUTABLE") | ||
+ add_executable(${target_alias} ALIAS ${target}) | ||
+ else() | ||
+ add_library(${target_alias} ALIAS ${target}) | ||
+ endif() | ||
+ endif() | ||
+ endforeach() | ||
+ endif() | ||
+ | ||
+ list(FIND added_subdirectories "${subdirectory}" has_subdirectory) | ||
+ if(NOT ${package_name}_FOUND AND NOT has_subdirectory EQUAL -1) | ||
+ add_subdirectory(${EXTERNAL}/${subdirectory}) | ||
+ list(APPEND ${subdirectory}) | ||
+ endif() | ||
+endmacro() | ||
+ | ||
+# Add an external header-only library suth that | ||
+# - prefer find_path if FILAMENT_PREFER_EXTERNAL defined | ||
+# - otherwise add the external subdirectory | ||
+macro(add_external_header_library package_name subdirectory header target) | ||
+ if(FILAMENT_PREFER_EXTERNAL) | ||
+ find_path(${package_name}_INCLUDE_DIRS ${header}) | ||
+ | ||
+ if(${package_name}_INCLUDE_DIRS_FOUND) | ||
+ add_library(${target} INTERFACE) | ||
+ target_include_directories(${target} INTERFACE ${${package_name}_INCLUDE_DIRS}) | ||
+ endif() | ||
+ endif() | ||
+ | ||
+ list(FIND added_subdirectories "${subdirectory}" has_subdirectory) | ||
+ if(NOT ${package_name}_INCLUDE_DIRS_FOUND AND NOT has_subdirectory EQUAL -1) | ||
+ add_subdirectory(${EXTERNAL}/${subdirectory}) | ||
+ list(APPEND ${subdirectory}) | ||
+ endif() | ||
+endmacro() | ||
+ | ||
# Common to all platforms | ||
if(FILAMENT_TESTS) | ||
-add_subdirectory(${EXTERNAL}/libgtest/tnt) | ||
+ add_external_library("GTest" "libgtest/tnt" "GTest::gtest" "gtest") | ||
endif() | ||
add_subdirectory(${LIBRARIES}/camutils) | ||
add_subdirectory(${LIBRARIES}/filabridge) | ||
@@ -739,21 +790,21 @@ add_subdirectory(${LIBRARIES}/utils) | ||
add_subdirectory(${LIBRARIES}/viewer) | ||
add_subdirectory(${FILAMENT}/filament) | ||
add_subdirectory(${FILAMENT}/shaders) | ||
-add_subdirectory(${EXTERNAL}/basisu/tnt) | ||
-add_subdirectory(${EXTERNAL}/civetweb/tnt) | ||
-add_subdirectory(${EXTERNAL}/imgui/tnt) | ||
-add_subdirectory(${EXTERNAL}/robin-map/tnt) | ||
-add_subdirectory(${EXTERNAL}/smol-v/tnt) | ||
+add_external_library("basisu" "basisu/tnt" "basisu::basisu;basisu::basisu_encoder" "basisu;basisu_encoder") | ||
+add_external_library("civetweb" "civetweb/tnt" "civetweb::civetweb" "civetweb") | ||
+add_external_library("imgui" "imgui/tnt" "imgui::imgui" "imgui") | ||
+add_external_library("tsl-robin-map" "robin-map/tnt" "tsl::robin_map" "tsl") | ||
+add_external_library("smol-v" "smol-v/tnt" "smol-v::smol-v" "smol-v") | ||
if(FILAMENT_BENCHMARKS) | ||
-add_subdirectory(${EXTERNAL}/benchmark/tnt) | ||
+ add_external_library("benchmark" "benchmark/tnt" "benchmark::benchmark;benchmark::benchmark_main" "benchmark;benchmark_main") | ||
endif() | ||
-add_subdirectory(${EXTERNAL}/meshoptimizer/tnt) | ||
-add_subdirectory(${EXTERNAL}/mikktspace) | ||
-add_subdirectory(${EXTERNAL}/cgltf/tnt) | ||
-add_subdirectory(${EXTERNAL}/draco/tnt) | ||
-add_subdirectory(${EXTERNAL}/jsmn/tnt) | ||
-add_subdirectory(${EXTERNAL}/stb/tnt) | ||
-add_subdirectory(${EXTERNAL}/getopt) | ||
+add_external_library("meshoptimizer" "meshoptimizer/tnt" "meshoptimizer::meshoptimizer" "meshoptimizer") | ||
+add_external_library("mikktspace" "mikktspace/tnt" "mikktspace::mikktspace" "mikktspace") | ||
+add_external_header_library("cgltf" "cgltf/tnt" "cgltf.h" "cgltf") | ||
+add_external_library("draco" "draco/tnt" "draco::draco" "draco") | ||
+add_external_header_library("jsmn" "jsmn/tnt" "jsmn.h" "jsmn") | ||
+add_external_library("Stb" "stb/tnt" "stb_include.h" "stb") | ||
+add_external_header_library("getopt" "getopt" "stdint.h" "getopt") | ||
|
||
# Note that this has to be placed after mikktspace in order for combine_static_libs to work. | ||
add_subdirectory(${LIBRARIES}/geometry) | ||
@@ -761,9 +812,16 @@ add_subdirectory(${LIBRARIES}/geometry) | ||
if (FILAMENT_BUILD_FILAMAT OR IS_HOST_PLATFORM) | ||
# spirv-tools must come before filamat, as filamat relies on the presence of the | ||
# spirv-tools_SOURCE_DIR variable. | ||
- add_subdirectory(${EXTERNAL}/spirv-tools) | ||
- add_subdirectory(${EXTERNAL}/glslang/tnt) | ||
- add_subdirectory(${EXTERNAL}/spirv-cross/tnt) | ||
+ if(BUILD_SHARED_LIBS) | ||
+ add_external_library("SPIRV-Tools" "spirv-tools" "SPIRV-Tools-shared" "SPIRV-Tools") | ||
+ else() | ||
+ add_external_library("SPIRV-Tools" "spirv-tools" "SPIRV-Tools-static" "SPIRV-Tools") | ||
+ endif() | ||
+ add_external_library("SPIRV-Tools-opt" "spirv-tools" "SPIRV-Tools-opt" "SPIRV-Tools-opt") | ||
+ add_external_library("glslang" "glslang/tnt" "glslang::glslang;glslang::SPIRV;glslang::OGLCompiler" "glslang;SPIRV;OGLCompiler") | ||
+ add_external_library("spirv_cross_core" "spirv-cross/tnt" "spirv-cross-core" "spirv-cross-core") | ||
+ add_external_library("spirv_cross_glsl" "spirv-cross/tnt" "spirv-cross-glsl" "spirv-cross-glsl") | ||
+ add_external_library("spirv_cross_msl" "spirv-cross/tnt" "spirv-cross-msl" "spirv-cross-msl") | ||
add_subdirectory(${LIBRARIES}/filamat) | ||
|
||
# the material debugger requires filamat | ||
@@ -774,9 +832,9 @@ endif() | ||
|
||
if (FILAMENT_SUPPORTS_VULKAN) | ||
add_subdirectory(${LIBRARIES}/bluevk) | ||
- add_subdirectory(${EXTERNAL}/vkmemalloc/tnt) | ||
+ add_external_library("vkmemalloc" "vkmemalloc/tnt" "vkmemalloc::vkmemalloc" "vkmemalloc") | ||
set(SPIRV_HEADERS_SKIP_EXAMPLES ON) | ||
- add_subdirectory(${EXTERNAL}/spirv-headers) | ||
+ add_external_header_library("SPIRV_HEADERS" "spirv-headers" "spirv/1.0/GLSL.std.450.h" "SPIRV-Headers") | ||
endif() | ||
|
||
set(FILAMENT_SAMPLES_BINARY_DIR ${PROJECT_BINARY_DIR}/samples) | ||
@@ -797,11 +855,11 @@ if (IS_HOST_PLATFORM) | ||
|
||
add_subdirectory(${FILAMENT}/samples) | ||
|
||
- add_subdirectory(${EXTERNAL}/libassimp/tnt) | ||
- add_subdirectory(${EXTERNAL}/libpng/tnt) | ||
- add_subdirectory(${EXTERNAL}/libsdl2/tnt) | ||
- add_subdirectory(${EXTERNAL}/libz/tnt) | ||
- add_subdirectory(${EXTERNAL}/tinyexr/tnt) | ||
+ add_external_library("assimp" "libassimp/tnt" "assimp::assimp" "assimp") | ||
+ add_external_library("PNG" "libpng/tnt" "PNG::PNG" "png") | ||
+ add_external_library("SDL2" "libsdl2/tnt" "SDL2::SDL2;SDL2::SDL2main" "sdl2;sdl2main") | ||
+ add_external_library("ZLIB" "libz/tnt" "ZLIB::ZLIB" "z") | ||
+ add_external_library("tinyexr" "tinyexr/tnt" "tinyexr::tinyexr;unofficial::tinyexr::tinyexr" "tinyexr;tinyexr") | ||
|
||
add_subdirectory(${TOOLS}/cmgen) | ||
add_subdirectory(${TOOLS}/cso-lut) | ||
-- | ||
2.45.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters