Skip to content

Commit

Permalink
cmake: Install glslang.pc
Browse files Browse the repository at this point in the history
  • Loading branch information
jpr42 committed Mar 9, 2025
1 parent 3b495e1 commit 5d2171c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
key: ubuntu-22-${{ matrix.cmake_build_type }}-${{ matrix.compiler.cc }}-${{matrix.compiler.cxx}}
- run: ./update_glslang_sources.py
- name: Configure
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON -DCMAKE_INSTALL_PREFIX="$PWD/build/install"
env:
CC: ${{matrix.compiler.cc}}
CXX: ${{matrix.compiler.cxx}}
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build --prefix build/install
run: cmake --install build
- name: Test find_package support
run: |
cmake -S Test/find_package -B build/find_package && \
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
key: ubuntu-22-${{ matrix.cmake_build_type }}-${{ matrix.compiler.cc }}-${{matrix.compiler.cxx}}
- run: ./update_glslang_sources.py
- name: Configure
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON -DBUILD_SHARED_LIBS=ON
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="$PWD/build/install"
env:
CC: ${{matrix.compiler.cc}}
CXX: ${{matrix.compiler.cxx}}
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build --prefix build/install
run: cmake --install build
- name: Test find_package support
run: |
cmake -S Test/find_package -B build/find_package && \
Expand Down Expand Up @@ -145,14 +145,14 @@ jobs:
key: linux_backcompat
- run: ./update_glslang_sources.py
- name: Configure
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D GLSLANG_TESTS=ON
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D GLSLANG_TESTS=ON -DCMAKE_INSTALL_PREFIX="$PWD/build/install"
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build --prefix build/install
run: cmake --install build
- name: Test find_package support
run: |
cmake -S Test/find_package -B build/find_package && \
Expand All @@ -172,12 +172,12 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: lukka/get-cmake@56d043d188c3612951d8755da8f4b709ec951ad6 # v3.31.6
- run: ./update_glslang_sources.py
- run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -G Ninja -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON
- run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -G Ninja -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON -DCMAKE_INSTALL_PREFIX="$PWD/build/install"
env:
CC: ${{matrix.compiler.cc}}
CXX: ${{matrix.compiler.cxx}}
- run: cmake --build build
- run: cmake --install build --prefix build/install
- run: cmake --install build
- name: Test find_package support
run: |
cmake -S Test/find_package -B build/find_package && \
Expand All @@ -196,12 +196,12 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: lukka/get-cmake@56d043d188c3612951d8755da8f4b709ec951ad6 # v3.31.6
- run: ./update_glslang_sources.py
- run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -G Ninja -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON -DBUILD_SHARED_LIBS=ON
- run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -G Ninja -DBUILD_WERROR=ON -D GLSLANG_TESTS=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="$PWD/build/install"
env:
CC: ${{matrix.compiler.cc}}
CXX: ${{matrix.compiler.cxx}}
- run: cmake --build build
- run: cmake --install build --prefix build/install
- run: cmake --install build
- name: Test find_package support
run: |
cmake -S Test/find_package -B build/find_package && \
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,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 @@ -398,4 +402,19 @@ if (GLSLANG_ENABLE_INSTALL)
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

# 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})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/glslang/glslang.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/glslang.pc"
@ONLY
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/glslang.pc"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
endif()
21 changes: 21 additions & 0 deletions Test/find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,24 @@ if (target_type STREQUAL STATIC_LIBRARY)
COMMAND glslang::spirv-remap --help
)
endif()

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

# 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()

find_package(PkgConfig REQUIRED QUIET) # Use PkgConfig to find Linux system libraries
pkg_check_modules(glslang REQUIRED QUIET 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=@CMAKE_INSTALL_PREFIX@
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

0 comments on commit 5d2171c

Please sign in to comment.