From 741306c0a7972b94f65933075b79eb6537626adb Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Nov 2024 10:19:18 -0800 Subject: [PATCH] feat: support installing and finding filament via `find_package` --- CMakeLists.txt | 56 ++++++++++++++++++++++++++++++++++++++--- filamentConfig.cmake.in | 9 +++++++ 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 filamentConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 649577b396c..ef849127e74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() # ================================================================================================== # Project declaration # ================================================================================================== -project(TNT) +project(filament VERSION 1.56.0) # ================================================================================================== # Options @@ -47,6 +47,8 @@ option(FILAMENT_ENABLE_MULTIVIEW "Enable multiview for Filament" OFF) option(FILAMENT_SUPPORTS_OSMESA "Enable OSMesa (headless GL context) for Filament" OFF) +option(FILAMENT_INSTALL_RULES "Enable Filament's install rules" ON) + set(FILAMENT_NDK_VERSION "" CACHE STRING "Android NDK version or version prefix to be used when building for Android." ) @@ -829,7 +831,53 @@ if (IS_HOST_PLATFORM) add_subdirectory(${TOOLS}/uberz) endif() -# Generate exported executables for cross-compiled builds (Android, WebGL, and iOS) -if (NOT CMAKE_CROSSCOMPILING) - export(TARGETS matc cmgen filamesh mipgen resgen uberz glslminifier FILE ${IMPORT_EXECUTABLES}) +if(FILAMENT_INSTALL_RULES) + # version file + include(CMakePackageConfigHelpers) + include(GNUInstallDirs) + write_basic_package_version_file("${CMAKE_BINARY_DIR}/filamentConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + install(FILES "${CMAKE_BINARY_DIR}/filamentConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/filament + COMPONENT filament) + + # public header dependencies + set(HEADER_DEPS cgltf jsmn SPIRV-Headers) + foreach(_dep ${HEADER_DEPS}) + get_target_property(_dep_include ${_dep} INTERFACE_INCLUDE_DIRECTORIES) + set_target_properties(${_dep} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "$$" + ) + endforeach() + install(TARGETS ${HEADER_DEPS} EXPORT filament-targets COMPONENT filament-dependencies) + export(TARGETS ${HEADER_DEPS} + NAMESPACE filament:: + FILE "${CMAKE_BINARY_DIR}/filamentTargets-Dependencies.cmake") + + # config file + set(PACKAGE_VERSION ${PROJECT_VERSION}) + configure_package_config_file("${CMAKE_CURRENT_LIST_DIR}/filamentConfig.cmake.in" + "${CMAKE_BINARY_DIR}/filamentConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/filament) + install(FILES "${CMAKE_BINARY_DIR}/filamentConfig.cmake" + DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/filament + COMPONENT filament) + + # targets file + set(TARGETS camutils filabridge filaflat filagui filameshio uberarchive gltfio_core gltfio ibl ibl-lite filament-iblprefilter + image ktxreader math mathio uberzlib utils viewer backend backend_headers vkshaders backend_test_linux filament + shaders geometry filamat matdbg_resources matdbg bluevk bluegl imageio cmgen cso-lut filamesh glslminifier matlang + matc matinfo matedit mipgen normal-blending resgen rgb-to-lmsr roughness-prefilter specular-color uberz + getopt smol-v vkmemalloc) + install(TARGETS ${TARGETS} EXPORT filament-targets COMPONENT filament) + export(TARGETS ${TARGETS} + NAMESPACE filament:: + FILE "${CMAKE_BINARY_DIR}/filamentTargets.cmake") + export(PACKAGE filament) + install(EXPORT filament-targets + NAMESPACE filament:: + DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/filament + FILE "filamentTargets.cmake" + COMPONENT filament) endif() diff --git a/filamentConfig.cmake.in b/filamentConfig.cmake.in new file mode 100644 index 00000000000..ee320541d1d --- /dev/null +++ b/filamentConfig.cmake.in @@ -0,0 +1,9 @@ +set(filament_VERSION @PACKAGE_VERSION@) + +@PACKAGE_INIT@ + +@PACKAGE_DEPENDENCIES@ + +include("${CMAKE_CURRENT_LIST_DIR}/filamentTargets.cmake") + +@INCLUDED_CONTENT@