-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a single CMake config package for all SPIRV-Cross targets #2253
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ project(SPIRV-Cross LANGUAGES CXX C) | |
enable_testing() | ||
|
||
include(GNUInstallDirs) | ||
include(CMakePackageConfigHelpers) | ||
|
||
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF) | ||
option(SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF) | ||
|
@@ -187,13 +188,12 @@ macro(spirv_cross_add_library name config_name library_type) | |
|
||
if (NOT SPIRV_CROSS_SKIP_INSTALL) | ||
install(TARGETS ${name} | ||
EXPORT ${config_name}Config | ||
EXPORT SPIRV-CrossTargets | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross) | ||
install(FILES ${hdrs} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross) | ||
install(EXPORT ${config_name}Config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${config_name}/cmake) | ||
export(TARGETS ${name} FILE ${config_name}Config.cmake) | ||
endif() | ||
endmacro() | ||
|
@@ -621,3 +621,35 @@ if (SPIRV_CROSS_CLI) | |
endif() | ||
endif() | ||
endif() | ||
|
||
if (NOT SPIRV_CROSS_SKIP_INSTALL) | ||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake.in" [=[ | ||
@PACKAGE_INIT@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/SPIRV-CrossTargets.cmake") | ||
]=]) | ||
|
||
configure_package_config_file( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this is new to me. Is there any place I can read up on CMake best practices regarding this code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not have a specific tutorial but I can share a few links and tips. Let's start with some CMake documentation link:
In the existing code I have found that it is better to use the Also, I hope this helps ! Last but not least, here are two more maybe useful links:
|
||
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake" | ||
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/SPIRV-Cross | ||
) | ||
|
||
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfigVersion.cmake" | ||
VERSION ${SPIRV_CROSS_VERSION} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SPIRV-Cross project uses a specifc ABI version but this does not match any published tags (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no SPIRV-Cross "version" per-se and I think the .so version is bumped when the C API is updated. Whatever shipped in an SDK shipped in an SDK, and I think someone tags those commits. Maybe it would be possible for SDK builds to explicitly override a version string or something. Using the git commit as a version is probably the only reasonable way if there is no tag for that particular commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting that we allow user to choose what would be the
Sounds reasonable, just to double check we would then have version which are not human readable as they would simply be git (short) SHA right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be fine with an option override for version strings. What is the intention for that version string? Package maintainers in distros and LunarG when packaging it in an SDK release? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my perspective I am interested for it as a package maintainer for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove Filtering on versions can be added in a later pr. |
||
COMPATIBILITY SameMajorVersion | ||
) | ||
|
||
install( | ||
EXPORT SPIRV-CrossTargets | ||
NAMESPACE "SPIRV-Cross::" | ||
DESTINATION "${CMAKE_INSTALL_DATADIR}/SPIRV-Cross" | ||
) | ||
|
||
install( | ||
FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfigVersion.cmake" | ||
DESTINATION | ||
"${CMAKE_INSTALL_DATADIR}/SPIRV-Cross" | ||
) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this break existing consumers of SPIRV-Cross?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right, I am not familiar how existing users are consuming this export set today.
I would be better to just generate a new one instead of replacing the existing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can let the new
SPIRV-CrossConfig.cmake
make use components:Then you can do things like:
find_package(SPIRV-Cross REQUIRED COMPONENTS spirv_cross_c_shared)
while still remaining compatible with
find_package(spirv_cross_c_shared REQUIRED)
(I think CMake does not allow exporting targets to more then one export set)