Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,17 @@ if (GLSLANG_ENABLE_INSTALL)
@INSTALL_CONFIG_UNIX@
include("@PACKAGE_PATH_EXPORT_TARGETS@")
]=])
if (ENABLE_OPT)
set(GLSLANG_PRIVATE_LIBS "-lSPIRV-Tools-opt")
endif()

set(PATH_EXPORT_TARGETS "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake")
if(UNIX OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
set(INSTALL_CONFIG_UNIX [=[
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_dependency(Threads)
]=])
set(GLSLANG_PRIVATE_LIBS "${GLSLANG_PRIVATE_LIBS} -lpthread")
endif()
configure_package_config_file(
"${CMAKE_CURRENT_BINARY_DIR}/glslang-config.cmake.in"
Expand Down Expand Up @@ -430,4 +434,25 @@ if (GLSLANG_ENABLE_INSTALL)
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

# Don't install glslang.pc on Windows.
# See Test/find_package/CMakeLists.txt for full reasoning.
if (WIN32)
return()
endif()

# CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_INCLUDEDIR can be absolute paths or relative.
cmake_path(APPEND CMAKE_INSTALL_LIBDIR_PC "\${exec_prefix}" ${CMAKE_INSTALL_LIBDIR})
cmake_path(APPEND CMAKE_INSTALL_INCLUDEDIR_PC "\${prefix}" ${CMAKE_INSTALL_INCLUDEDIR})
# The substitutions in glslang.pc.in are run twice, the first time at configure time
# for most of the variables, and the second at install time once the actual
# CMAKE_INSTALL_PREFIX is known. To protect the latter we need something that expands
# a literal @ sign.
set(AT "@")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/glslang/glslang.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/glslang.pc"
@ONLY
)
install(CODE "configure_file(\"${CMAKE_CURRENT_BINARY_DIR}/glslang.pc\" \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig/glslang.pc\" @ONLY) ")
endif()
43 changes: 43 additions & 0 deletions Test/find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,46 @@ if (target_type STREQUAL STATIC_LIBRARY)
COMMAND glslang::glslang-standalone --version
)
endif()

# Ensure glslang.pc was installed
find_file(glslang_PC glslang.pc PATH_SUFFIXES lib/pkgconfig)

# NOTE: Windows cannot ship a single reliable glslang.pc
#
# pkg-config simply doesn't have a way to handle binaries having
# different names based on the configuration. While CMake configuration files
# do support multi-config.
# https://github.com/microsoft/vcpkg/discussions/37570
#
# IE: glslangd.lib vs glslang.lib
#
# The debug binaries have a different name on Windows.
#
# CMAKE_DEBUG_POSTFIX has been part of the codebase since 2016 changing it WILL break someone.
# https://github.com/KhronosGroup/glslang/issues/310
if (WIN32)
if (EXISTS ${glslang_PC})
message(FATAL_ERROR "glslang.pc invalid on Windows")
endif()

return()
endif()

# Use CMake itself to verify the pc file.
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.31")
cmake_pkg_config(EXTRACT ${glslang_PC} REQUIRED STRICTNESS "STRICT")

# Ensure glslang.pc matches up with cmake packaging
if (NOT (CMAKE_PKG_CONFIG_VERSION VERSION_EQUAL glslang_VERSION))
message(FATAL_ERROR "${CMAKE_PKG_CONFIG_VERSION} != ${glslang_VERSION}")
endif()
endif()

# Additional sanity check the glslang.pc is correct.
find_package(PkgConfig REQUIRED)
pkg_check_modules(glslang REQUIRED IMPORTED_TARGET glslang)

add_library(stub_pc STATIC stub.cpp)
target_link_libraries(example PRIVATE
PkgConfig::glslang
)
11 changes: 11 additions & 0 deletions glslang/glslang.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@AT@CMAKE_INSTALL_PREFIX@AT@
exec_prefix=${prefix}
libdir=@CMAKE_INSTALL_LIBDIR_PC@
includedir=@CMAKE_INSTALL_INCLUDEDIR_PC@

Name: glslang
Description: Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Version: @GLSLANG_VERSION@
Cflags: -I${includedir}
Libs.private: @GLSLANG_PRIVATE_LIBS@
Libs: -L${libdir} -lglslang
Loading