glslang
glslang copied to clipboard
Fix export configurations paths for Unixes
Note that I mention Arch Linux because it is the system I base my example on, but this fix is for all platforms including Windows if installed correctly.
Current State
The current way glslang installs its export targets makes them impossible to find using command cmake patterns.
I am using Arch Linux and here is where the official glslang package installs the cmake configuration
/usr/lib/cmake/HLSLTargets-release.cmake
/usr/lib/cmake/HLSLTargets.cmake
/usr/lib/cmake/OGLCompilerTargets-release.cmake
/usr/lib/cmake/OGLCompilerTargets.cmake
/usr/lib/cmake/OSDependentTargets-release.cmake
/usr/lib/cmake/OSDependentTargets.cmake
/usr/lib/cmake/SPIRVTargets-release.cmake
/usr/lib/cmake/SPIRVTargets.cmake
/usr/lib/cmake/SPVRemapperTargets-release.cmake
/usr/lib/cmake/SPVRemapperTargets.cmake
/usr/lib/cmake/glslang-default-resource-limitsTargets-release.cmake
/usr/lib/cmake/glslang-default-resource-limitsTargets.cmake
/usr/lib/cmake/glslangTargets-release.cmake
/usr/lib/cmake/glslangTargets.cmake
/usr/lib/cmake/glslangValidatorTargets-release.cmake
/usr/lib/cmake/glslangValidatorTargets.cmake
/usr/lib/cmake/spirv-remapTargets-release.cmake
/usr/lib/cmake/spirv-remapTargets.cmake
The location actually makes it impossible for find_package(glslang)
to find them in CONFIG
mode.
According to the cmake docs, cmake will look in the following directories (for Arch Linux):
/usr/(lib*|share)/cmake/glslang*/
/usr/(lib*|share)/glslang*/
/usr/(lib*|share)/glslang*/(cmake|CMake)/
/usr/glslang*/(lib*|share)/cmake/<name>*/
/usr/glslang*/(lib*|share)/glslang*/
/usr/glslang*/(lib*|share)/glslang*/(cmake|CMake)/
As we can see, none of these paths match the installation.
Secondly, unless otherwise specified, cmake will look for a file called <name>Config.cmake
or <lower-case-name>-config.cmake
. The names are currenly suffixed with Targets
when they should be suffixed with Config
.
Thirdly, it is modern cmake convention that if there are multiple targets under the same package umbrella, that namespace and components be used.
Prior to this fix using glslangValidator
required the following cmake command
find_program(GLSLANG_VALIDATOR NAMES glslangValidator)
Suggested Fix
This PR fixed the three stated problems by adding the package name to the exported configurations.
The names of the configs now have Config
as a suffix.
The different targets are now components in the glslang::
namespace.
There is now only one configuration file which provides all the targets.
/usr/lib/cmake/glslang/glslangConfig.cmake
In CMake, the targets are now easy to access:
find_package(Threads)
find_package(glslang REQUIRED COMPONENTS glslang glslangValidator)
target_link_libraries(example PRIVATE glslang::glslang)
add_custom_target(validator-version
COMMAND glslang::glslangValidator -v)
Now using glslangValidator
requires only find_package(glslang)
which will find the path with the help of CMake and the config.
Known Limitation
I believe this was a pre-existing issue, but using glslang
on Unix requires Threads
.
If the user doesn't do find_package(Threads)
prior to find_package(glslang)
, they get the following message when configuring:
CMake Error at CMakeLists.txt:1 (add_executable):
Target "example" links to target "Threads::Threads" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
Alternative fix
There is another way to generate a Config file which would leave the *Target.cmake
files in place.
It would require maintaining a glslangConfig.cmake
template file which imports the *Target.cmake
files.
This requires a little more care from the maintainers as it is no longer created automatically by CMake and requires detecting platforms and options such as ENABLE_HLSL
.
On the plus side, the user would not have to do find_package(Threads)
prior to find_package(glslang)
, as @mathstuf pointed out in the comments.
An example of such a configuration is found there: https://cmake.org/cmake/help/v3.17/manual/cmake-packages.7.html#creating-a-package-configuration-file
oh, first notice of this PR, i've pushed https://github.com/KhronosGroup/glslang/pull/2127 for fix path issue. but you PR seems more complete
can you rebase it?
greetings
Rebased on current master
@johnkslang could I get a review?
I believe this was a pre-existing issue, but using glslang on Unix requires Threads. If the user doesn't do find_package(Threads) prior to find_package(glslang), they get the following message when configuring:
You can do find_dependency(Threads)
from the Config.cmake
file to fix this.
FWIW my test of this branch on Windows/Ninja Debug and RelWithDebInfo worked and saved having to use my iffy FindGLSLANG.cmake module
I can confirm that this is still needed as of 2067d1a93e6edc17f2a6b7e3e5138a9bbcd35ef9 (didn't check in latest master
, as 2067d1a is what I need for the current Vulkan SDK release).
Here's what the current install script produces for me on Mageia:
$ find /usr/lib64/cmake/ -maxdepth 1 -type f | sort
/usr/lib64/cmake/BoostDetectToolset-1.73.0.cmake
/usr/lib64/cmake/glslang-default-resource-limitsTargets.cmake
/usr/lib64/cmake/glslang-default-resource-limitsTargets-relwithdebinfo.cmake
/usr/lib64/cmake/glslangTargets.cmake
/usr/lib64/cmake/glslangTargets-relwithdebinfo.cmake
/usr/lib64/cmake/glslangValidatorTargets.cmake
/usr/lib64/cmake/glslangValidatorTargets-relwithdebinfo.cmake
/usr/lib64/cmake/HLSLTargets.cmake
/usr/lib64/cmake/HLSLTargets-relwithdebinfo.cmake
/usr/lib64/cmake/OGLCompilerTargets.cmake
/usr/lib64/cmake/OGLCompilerTargets-relwithdebinfo.cmake
/usr/lib64/cmake/OSDependentTargets.cmake
/usr/lib64/cmake/OSDependentTargets-relwithdebinfo.cmake
/usr/lib64/cmake/spirv-remapTargets.cmake
/usr/lib64/cmake/spirv-remapTargets-relwithdebinfo.cmake
/usr/lib64/cmake/SPIRVTargets.cmake
/usr/lib64/cmake/SPIRVTargets-relwithdebinfo.cmake
/usr/lib64/cmake/SPVRemapperTargets.cmake
/usr/lib64/cmake/SPVRemapperTargets-relwithdebinfo.cmake
$ find /usr/lib64/cmake/ -maxdepth 1 -type d | sort
/usr/lib64/cmake/
/usr/lib64/cmake/Alembic
/usr/lib64/cmake/Boost-1.73.0
/usr/lib64/cmake/boost_atomic-1.73.0
/usr/lib64/cmake/boost_chrono-1.73.0
/usr/lib64/cmake/boost_container-1.73.0
/usr/lib64/cmake/boost_context-1.73.0
/usr/lib64/cmake/boost_contract-1.73.0
/usr/lib64/cmake/boost_coroutine-1.73.0
/usr/lib64/cmake/boost_date_time-1.73.0
/usr/lib64/cmake/boost_exception-1.73.0
/usr/lib64/cmake/boost_fiber-1.73.0
/usr/lib64/cmake/boost_fiber_numa-1.73.0
/usr/lib64/cmake/boost_filesystem-1.73.0
/usr/lib64/cmake/boost_graph-1.73.0
/usr/lib64/cmake/boost_headers-1.73.0
/usr/lib64/cmake/boost_iostreams-1.73.0
/usr/lib64/cmake/boost_locale-1.73.0
/usr/lib64/cmake/boost_log-1.73.0
/usr/lib64/cmake/boost_log_setup-1.73.0
/usr/lib64/cmake/boost_math_c99-1.73.0
/usr/lib64/cmake/boost_math_c99f-1.73.0
/usr/lib64/cmake/boost_math_c99l-1.73.0
/usr/lib64/cmake/boost_math_tr1-1.73.0
/usr/lib64/cmake/boost_math_tr1f-1.73.0
/usr/lib64/cmake/boost_math_tr1l-1.73.0
/usr/lib64/cmake/boost_mpi_python-1.73.0
/usr/lib64/cmake/boost_nowide-1.73.0
/usr/lib64/cmake/boost_numpy-1.73.0
/usr/lib64/cmake/boost_prg_exec_monitor-1.73.0
/usr/lib64/cmake/boost_program_options-1.73.0
/usr/lib64/cmake/boost_python-1.73.0
/usr/lib64/cmake/boost_random-1.73.0
/usr/lib64/cmake/boost_regex-1.73.0
/usr/lib64/cmake/boost_serialization-1.73.0
/usr/lib64/cmake/boost_stacktrace_addr2line-1.73.0
/usr/lib64/cmake/boost_stacktrace_backtrace-1.73.0
/usr/lib64/cmake/boost_stacktrace_basic-1.73.0
/usr/lib64/cmake/boost_stacktrace_noop-1.73.0
/usr/lib64/cmake/boost_stacktrace_windbg-1.73.0
/usr/lib64/cmake/boost_stacktrace_windbg_cached-1.73.0
/usr/lib64/cmake/boost_system-1.73.0
/usr/lib64/cmake/boost_thread-1.73.0
/usr/lib64/cmake/boost_timer-1.73.0
/usr/lib64/cmake/boost_type_erasure-1.73.0
/usr/lib64/cmake/boost_unit_test_framework-1.73.0
/usr/lib64/cmake/boost_wave-1.73.0
/usr/lib64/cmake/boost_wserialization-1.73.0
/usr/lib64/cmake/bullet
/usr/lib64/cmake/clang
/usr/lib64/cmake/DBus1
/usr/lib64/cmake/dbusmenu-qt5
/usr/lib64/cmake/dcmtk
/usr/lib64/cmake/double-conversion
/usr/lib64/cmake/embree-3.12.0
/usr/lib64/cmake/fftw3
/usr/lib64/cmake/glm
/usr/lib64/cmake/GTest
/usr/lib64/cmake/harfbuzz
/usr/lib64/cmake/IlmBase
/usr/lib64/cmake/KF5Archive
/usr/lib64/cmake/KF5Attica
/usr/lib64/cmake/KF5Auth
/usr/lib64/cmake/KF5Bookmarks
/usr/lib64/cmake/KF5Codecs
/usr/lib64/cmake/KF5Completion
/usr/lib64/cmake/KF5Config
/usr/lib64/cmake/KF5ConfigWidgets
/usr/lib64/cmake/KF5CoreAddons
/usr/lib64/cmake/KF5Crash
/usr/lib64/cmake/KF5DBusAddons
/usr/lib64/cmake/KF5Declarative
/usr/lib64/cmake/KF5GlobalAccel
/usr/lib64/cmake/KF5GuiAddons
/usr/lib64/cmake/KF5I18n
/usr/lib64/cmake/KF5IconThemes
/usr/lib64/cmake/KF5ItemViews
/usr/lib64/cmake/KF5JobWidgets
/usr/lib64/cmake/KF5KIO
/usr/lib64/cmake/KF5Notifications
/usr/lib64/cmake/KF5Package
/usr/lib64/cmake/KF5Plasma
/usr/lib64/cmake/KF5PlasmaQuick
/usr/lib64/cmake/KF5Service
/usr/lib64/cmake/KF5Solid
/usr/lib64/cmake/KF5Sonnet
/usr/lib64/cmake/KF5TextWidgets
/usr/lib64/cmake/KF5Wayland
/usr/lib64/cmake/KF5WidgetsAddons
/usr/lib64/cmake/KF5WindowSystem
/usr/lib64/cmake/KF5XmlGui
/usr/lib64/cmake/liblcf
/usr/lib64/cmake/libssh
/usr/lib64/cmake/libxml2
/usr/lib64/cmake/libzip
/usr/lib64/cmake/llvm
/usr/lib64/cmake/md4c
/usr/lib64/cmake/md4c-html
/usr/lib64/cmake/OpenAL
/usr/lib64/cmake/OpenCOLLADA
/usr/lib64/cmake/OpenColorIO
/usr/lib64/cmake/OpenCV
/usr/lib64/cmake/OpenEXR
/usr/lib64/cmake/OpenImageDenoise
/usr/lib64/cmake/pugixml
/usr/lib64/cmake/PulseAudio
/usr/lib64/cmake/Qt5
/usr/lib64/cmake/Qt5AttributionsScannerTools
/usr/lib64/cmake/Qt5Charts
/usr/lib64/cmake/Qt5Concurrent
/usr/lib64/cmake/Qt5Core
/usr/lib64/cmake/Qt5DBus
/usr/lib64/cmake/Qt5DocTools
/usr/lib64/cmake/Qt5EglFSDeviceIntegration
/usr/lib64/cmake/Qt5Gui
/usr/lib64/cmake/Qt5Help
/usr/lib64/cmake/Qt5LinguistTools
/usr/lib64/cmake/Qt5Multimedia
/usr/lib64/cmake/Qt5Network
/usr/lib64/cmake/Qt5OpenGL
/usr/lib64/cmake/Qt5OpenGLExtensions
/usr/lib64/cmake/Qt5PrintSupport
/usr/lib64/cmake/Qt5Qml
/usr/lib64/cmake/Qt5QmlDebug
/usr/lib64/cmake/Qt5QmlDevTools
/usr/lib64/cmake/Qt5QmlImportScanner
/usr/lib64/cmake/Qt5QmlModels
/usr/lib64/cmake/Qt5Quick
/usr/lib64/cmake/Qt5QuickCompiler
/usr/lib64/cmake/Qt5QuickTest
/usr/lib64/cmake/Qt5Script
/usr/lib64/cmake/Qt5Sql
/usr/lib64/cmake/Qt5Svg
/usr/lib64/cmake/Qt5Test
/usr/lib64/cmake/Qt5TextToSpeech
/usr/lib64/cmake/Qt5Widgets
/usr/lib64/cmake/Qt5X11Extras
/usr/lib64/cmake/Qt5XcbQpa
/usr/lib64/cmake/Qt5Xml
/usr/lib64/cmake/RapidJSON
/usr/lib64/cmake/SDL2
/usr/lib64/cmake/SFML
/usr/lib64/cmake/Snappy
/usr/lib64/cmake/SPIRV-Tools
/usr/lib64/cmake/SPIRV-Tools-link
/usr/lib64/cmake/SPIRV-Tools-opt
/usr/lib64/cmake/SPIRV-Tools-reduce
/usr/lib64/cmake/tbb
/usr/lib64/cmake/wslay
/usr/lib64/cmake/yaml-cpp
As you can see (aside from a global Boost helper), all other system packages put their CMake config into <cmake path>/<library name>/
and not directly in the root folder of the CMake path.
Here's a branch with the two commits from this PR rebased on 2067d1a93e6edc17f2a6b7e3e5138a9bbcd35ef9, with a fix for https://github.com/KhronosGroup/glslang/pull/1978#discussion_r503185551:
https://github.com/akien-mga/glslang/tree/cmake-config-install
Here's a branch with the two commits from this PR rebased on 2067d1a, with a fix for #1978 (comment):
https://github.com/akien-mga/glslang/tree/cmake-config-install
Updated to solve conflicts with current master
branch (538231d8b46c22474a558671f89f80b25fcec72d).
Can you resolve the remaining conflicts?
They are resolved in https://github.com/akien-mga/glslang/tree/cmake-config-install - I can't update @bwrsandman's branch which is the base for this PR, but they might do so in time. I just updated my branch because I need this patch for my Linux distribution package (Mageia).
This was superseded by #2989 and could likely be closed.
Closing due to inactivity and due to being superseded by #2989.