From 178bfcf5bc304137dd5f8e4752f01a8d50a88757 Mon Sep 17 00:00:00 2001 From: jasonliu-- Date: Fri, 20 Oct 2023 23:15:00 -0400 Subject: [PATCH] Generate pkg-config file during install builds This commit causes CMake to generate a pkg-config file when ENABLE_GLSLANG_INSTALL is enabled. This allows software projects that use pkg-config (and not CMake) to find external dependencies (e.g., Godot 4.x), to find and properly link to a pre-built glslang package. Closes #1715. --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a734ad1f87..52a06b83cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -370,4 +370,35 @@ if(ENABLE_GLSLANG_INSTALL) DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) + + # Generate a pkg-config file, so that software projects which use + # pkg-config to locate dependencies can find glslang + + # This template is filled-in by CMake's `configure_file(... @ONLY)`. + # The `@...@` are substituted by CMake's configure_file(), either + # from variables set in CMakeLists.txt or by CMake itself. + # (Based on: https://www.scivision.dev/cmake-generate-pkg-config/) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc.in" [=[ +prefix="@CMAKE_INSTALL_PREFIX@" +exec_prefix="${prefix}" +libdir="${prefix}/lib" +includedir="${prefix}/include" + +Name: @PROJECT_NAME@ +Description: official reference compiler front end for the OpenGL ES and OpenGL shading languages +Version: @PROJECT_VERSION@ +Cflags: -I"${includedir}" +Libs: -L"${libdir}" -l@PROJECT_NAME@ + ]=]) + configure_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" + @ONLY + ) + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" + DESTINATION + "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + ) endif()