Skip to content

Commit 7d24295

Browse files
authored
Fix(cmake): CMake doesn't find system installed SPIRV-Headers (KhronosGroup#5422)
To build repository version from sources current cmake require to explicitly clone SPIRV-Headers repository to directory named 'external' with fixed name 'spirv-headers'. This is a behavior which doesn't support searching global headers and also CMAKE_PREFIX_PATH which makes development in some environments less convenient than it should be. The commit fixes this issue with keeping previous clone option intact.
1 parent f0cc85e commit 7d24295

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

external/CMakeLists.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ function(pop_variable var)
2727
endfunction()
2828

2929
if (DEFINED SPIRV-Headers_SOURCE_DIR)
30-
# This allows flexible position of the SPIRV-Headers repo.
31-
set(SPIRV_HEADER_DIR ${SPIRV-Headers_SOURCE_DIR})
30+
add_subdirectory(${SPIRV-Headers_SOURCE_DIR})
31+
set(SPIRV-Headers_INCLUDE_DIRS ${SPIRV-Headers_SOURCE_DIR}/include)
32+
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers/)
33+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers/)
34+
set(SPIRV-Headers_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers/include)
35+
elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers/)
36+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers/)
37+
set(SPIRV-Headers_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers/include)
38+
elseif()
3239
else()
33-
set(SPIRV_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers)
34-
endif()
35-
36-
if (IS_DIRECTORY ${SPIRV_HEADER_DIR})
37-
# TODO(dneto): We should not be modifying the parent scope.
38-
set(SPIRV_HEADER_INCLUDE_DIR ${SPIRV_HEADER_DIR}/include PARENT_SCOPE)
39-
40-
# Add SPIRV-Headers as a sub-project if it isn't already defined.
41-
# Do this so enclosing projects can use SPIRV-Headers_SOURCE_DIR to find
42-
# headers to include.
43-
if (NOT DEFINED SPIRV-Headers_SOURCE_DIR)
44-
add_subdirectory(${SPIRV_HEADER_DIR})
40+
find_package(SPIRV-Headers QUIET)
41+
if (SPIRV-Headers_FOUND)
42+
get_target_property(SPIRV-Headers_INCLUDE_DIRS SPIRV-Headers::SPIRV-Headers INTERFACE_INCLUDE_DIRECTORIES)
43+
else ()
44+
message(FATAL_ERROR
45+
"SPIRV-Headers was not found - please checkout a copy under external/.")
4546
endif()
46-
else()
47-
message(FATAL_ERROR
48-
"SPIRV-Headers was not found - please checkout a copy under external/.")
4947
endif()
48+
set(SPIRV_HEADER_INCLUDE_DIR ${SPIRV-Headers_INCLUDE_DIRS} PARENT_SCOPE)
49+
message(STATUS "Found SPIRV-Headers: ${SPIRV-Headers_INCLUDE_DIRS}")
5050

5151
if (NOT ${SPIRV_SKIP_TESTS})
5252
# Find gmock if we can. If it's not already configured, then try finding

0 commit comments

Comments
 (0)