Skip to content

Commit beea249

Browse files
kbenziesvenvh
authored andcommitted
cmake: Fix using spirv-tools package on Ubuntu 22.04
When using the `spirv-tools` system package on Ubuntu 20.04 the `SPIRV-Tools-shared` CMake target, which represents `/usr/lib/x86_64-linux-gnu/libSPIRV-Tools.so`, is imported and used for linking and include directories. However, on Ubuntu 22.04 it does not exist which results in the following error: ``` CMake Error at /builds/SPIRV-LLVM-Translator/CMakeLists.txt:124 (get_target_property): get_target_property() called with non-existent target "SPIRV-Tools-shared". ``` Instead, on Ubuntu 22.04 the `SPIRV-Tools-static` CMake target is imported, which represents `/usr/lib/x86_64-linux-gnu/libSPIRV-Tools.a`, which suggests the project or package maintainers changed the default library type being compiled. This patch updates the `CMakeLists.txt` to check if either of these targets exists, preferring the shared library, before attempting to get properties from the target or use it as a link library. If neither target exists it is treated as a fatal error.
1 parent 8ea20af commit beea249

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,19 @@ if (NOT SPIRV_TOOLS_FOUND)
120120
find_package(SPIRV-Tools-tools)
121121
if (SPIRV-Tools_FOUND AND SPIRV-Tools-tools_FOUND)
122122
set(SPIRV_TOOLS_FOUND TRUE)
123-
set(SPIRV_TOOLS_LDFLAGS SPIRV-Tools-shared)
124-
get_target_property(SPIRV_TOOLS_INCLUDE_DIRS SPIRV-Tools-shared INTERFACE_INCLUDE_DIRECTORIES)
123+
# check for the existance of library targets in the found packages
124+
if(TARGET SPIRV-Tools-shared)
125+
# use the shared libary target if present
126+
set(SPIRV-Tools-library SPIRV-Tools-shared)
127+
elseif(TARGET SPIRV-Tools-static)
128+
# otherwise fallback to the static library target
129+
set(SPIRV-Tools-library SPIRV-Tools-static)
130+
else()
131+
message(FATAL_ERROR "Found SPIRV-Tools package but neither "
132+
"SPIRV-Tools-shared or SPIRV-Tools-static targets exist.")
133+
endif()
134+
set(SPIRV_TOOLS_LDFLAGS ${SPIRV-Tools-library})
135+
get_target_property(SPIRV_TOOLS_INCLUDE_DIRS ${SPIRV-Tools-library} INTERFACE_INCLUDE_DIRECTORIES)
125136
endif()
126137
endif()
127138

0 commit comments

Comments
 (0)