Skip to content

Commit

Permalink
[build] Export cmake config to ease clients usage in Cmake (#5162)
Browse files Browse the repository at this point in the history
* Generate cmake config for export core

* Minor

* Fix glm headers
  • Loading branch information
qiao-bo authored Jun 15, 2022
1 parent d976ddd commit 40ff61d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
84 changes: 84 additions & 0 deletions cmake/TaichiExportCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,87 @@ target_link_libraries(${TAICHI_EXPORT_CORE_NAME} PRIVATE taichi_isolated_core)
set_target_properties(${TAICHI_EXPORT_CORE_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build")

target_include_directories(${TAICHI_EXPORT_CORE_NAME}
PUBLIC
# Used when building the library:
$<BUILD_INTERFACE:${taichi_export_core_BINARY_DIR}/include>
$<BUILD_INTERFACE:${taichi_export_core_SOURCE_DIR}/include>
# Used when installing the library:
$<INSTALL_INTERFACE:include>
PRIVATE
# Used only when building the library:
${PROJECT_SOURCE_DIR})

# This helper provides us standard locations across Linux/Windows/MacOS
include(GNUInstallDirs)

install(TARGETS ${TAICHI_EXPORT_CORE_NAME} EXPORT ${TAICHI_EXPORT_CORE_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

# Install the export set, which contains the meta data of the target
install(EXPORT ${TAICHI_EXPORT_CORE_NAME}Targets
FILE ${TAICHI_EXPORT_CORE_NAME}Targets.cmake
NAMESPACE ${TAICHI_EXPORT_CORE_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TAICHI_EXPORT_CORE_NAME}
)

include(CMakePackageConfigHelpers)

# Generate the config file
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${TAICHI_EXPORT_CORE_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${TAICHI_EXPORT_CORE_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${TAICHI_EXPORT_CORE_NAME}
)

# Generate the config version file
set(${TAICHI_EXPORT_CORE_NAME}_VERSION "${TI_VERSION_MAJOR}.${TI_VERSION_MINOR}.${TI_VERSION_PATCH}")
write_basic_package_version_file(
"${TAICHI_EXPORT_CORE_NAME}ConfigVersion.cmake"
VERSION ${${TAICHI_EXPORT_CORE_NAME}_VERSION}
COMPATIBILITY SameMajorVersion
)

# Install the config files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${TAICHI_EXPORT_CORE_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${TAICHI_EXPORT_CORE_NAME}ConfigVersion.cmake"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${TAICHI_EXPORT_CORE_NAME}
)

# Install public headers for this target
# TODO: Replace files here with public headers when ready.
install(DIRECTORY
${PROJECT_SOURCE_DIR}/taichi
${PROJECT_SOURCE_DIR}/external/spdlog/include/spdlog
${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include/vulkan
${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include/vulkan
${PROJECT_SOURCE_DIR}/external/glm/glm
${PROJECT_SOURCE_DIR}/external/eigen
DESTINATION include
FILES_MATCHING
PATTERN *.h
PATTERN *.hpp
PATTERN *.inl
)
install(DIRECTORY
${PROJECT_SOURCE_DIR}/external/eigen/Eigen
DESTINATION include
)
file(GLOB TAICHI_PUBLIC_HEADERS_TEMP
"external/volk/*.h" "external/volk/*.hpp"
"external/imgui/*.h" "external/imgui/*.hpp"
"external/imgui/backends/*.h" "external/imgui/backends/*.hpp"
"external/VulkanMemoryAllocator/include/*.h"
)
install(FILES
${TAICHI_PUBLIC_HEADERS_TEMP}
DESTINATION include
)
5 changes: 5 additions & 0 deletions cmake/taichi_export_coreConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

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

check_required_components("@PROJECT_NAME@")

0 comments on commit 40ff61d

Please sign in to comment.