Skip to content

Commit

Permalink
feat: support installing and finding filament via find_package
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 10, 2024
1 parent 4186e99 commit 741306c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
56 changes: 52 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif()
# ==================================================================================================
# Project declaration
# ==================================================================================================
project(TNT)
project(filament VERSION 1.56.0)

# ==================================================================================================
# Options
Expand Down Expand Up @@ -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."
)
Expand Down Expand Up @@ -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
"$<BUILD_INTERFACE:${_dep_include}>$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
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()
9 changes: 9 additions & 0 deletions filamentConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(filament_VERSION @PACKAGE_VERSION@)

@PACKAGE_INIT@

@PACKAGE_DEPENDENCIES@

include("${CMAKE_CURRENT_LIST_DIR}/filamentTargets.cmake")

@INCLUDED_CONTENT@

0 comments on commit 741306c

Please sign in to comment.