Skip to content

Build interface include path for glslang/SPIRV/* inconsistent with install layout #4185

@LDAP

Description

@LDAP

glslang version: 16.2.0

Description

When glslang is used as a cmake subproject (e.g. via add_subdirectory or meson's cmake subproject integration), #include "glslang/SPIRV/GlslangToSpv.h" fails to compile because the header cannot be found. The SPIRV cmake target declares:

  target_include_directories(SPIRV PUBLIC
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
      $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

CMAKE_CURRENT_SOURCE_DIR in SPIRV/CMakeLists.txt is <root>/SPIRV/. This means the BUILD interface adds <root>/ to include paths.
With that, glslang/SPIRV/GlslangToSpv.h resolves to <root>/glslang/SPIRV/GlslangToSpv.h, which does not exist in the source tree. The actual file is at <root>/SPIRV/GlslangToSpv.h.

The INSTALL interface correctly places headers at <prefix>/include/glslang/SPIRV/GlslangToSpv.h, so glslang/SPIRV/GlslangToSpv.h works for installed glslang.

The two interfaces are inconsistent.

Expected behaviour

#include "glslang/SPIRV/GlslangToSpv.h" should compile when glslang is used as a cmake subproject, consistent with the installed layout.

Suggested fix

Either add a glslang/SPIRV/ directory (or symlink) to the source tree mirroring the install layout, or adjust the BUILD interface include path so that glslang/SPIRV/GlslangToSpv.h resolves correctly from the source tree.

I patched the CMakeLists.txt like to fix the issue on by Ubuntu and Windows CIs:

...
if(ENABLE_SPIRV)
    add_subdirectory(SPIRV)
    # @LDAP: create glslang/SPIRV/ symlink in the generated include dir so that
    # #include "glslang/SPIRV/GlslangToSpv.h" works consistently with the install layout.
    file(MAKE_DIRECTORY "${GLSLANG_GENERATED_INCLUDEDIR}/glslang")
    file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/SPIRV" "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/SPIRV" SYMBOLIC COPY_ON_ERROR)
endif()
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions