diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index f1b79098b0..9883c31e15 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -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}} @@ -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 && \ @@ -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}} @@ -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 && \ @@ -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 && \ @@ -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 && \ @@ -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 && \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 361760f350..d212ae1eb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -364,6 +364,9 @@ 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") @@ -371,6 +374,7 @@ if (GLSLANG_ENABLE_INSTALL) 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" @@ -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() diff --git a/Test/find_package/CMakeLists.txt b/Test/find_package/CMakeLists.txt index 5eef2fb49d..3f88ba63b3 100644 --- a/Test/find_package/CMakeLists.txt +++ b/Test/find_package/CMakeLists.txt @@ -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 +) diff --git a/glslang/glslang.pc.in b/glslang/glslang.pc.in new file mode 100644 index 0000000000..7e2e88ef53 --- /dev/null +++ b/glslang/glslang.pc.in @@ -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