Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shaderc, spirv-tools] Fix cmake config, add usage, minor fixes #31912

Merged
merged 14 commits into from
Jun 14, 2023
70 changes: 70 additions & 0 deletions ports/shaderc/cmake-config-export.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
diff --git a/libshaderc/CMakeLists.txt b/libshaderc/CMakeLists.txt
index d3bc639..6432a9b 100644
--- a/libshaderc/CMakeLists.txt
+++ b/libshaderc/CMakeLists.txt
@@ -28,7 +28,9 @@ if (NOT BUILD_SHARED_LIBS)
add_library(shaderc STATIC ${SHADERC_SOURCES})
shaderc_default_compile_options(shaderc)
target_include_directories(shaderc
- PUBLIC include
+ PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+ $<INSTALL_INTERFACE:include>
PRIVATE ${glslang_SOURCE_DIR}
${SPIRV-Headers_SOURCE_DIR}/include)
set(shaderc_install_target shaderc)
@@ -37,7 +39,9 @@ else()
add_library(shaderc_shared SHARED ${SHADERC_SOURCES})
shaderc_default_compile_options(shaderc_shared)
target_include_directories(shaderc_shared
- PUBLIC include
+ PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+ $<INSTALL_INTERFACE:include>
PRIVATE ${glslang_SOURCE_DIR}
${SPIRV-Headers_SOURCE_DIR}/include)
target_compile_definitions(shaderc_shared
@@ -60,9 +64,14 @@ if(SHADERC_ENABLE_INSTALL)
${CMAKE_INSTALL_INCLUDEDIR}/shaderc)

install(TARGETS ${shaderc_install_target} shaderc_util
+ EXPORT unofficial-shaderc-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+ install(EXPORT unofficial-shaderc-targets
+ NAMESPACE unofficial::shaderc::
+ DESTINATION share/unofficial-shaderc
+ )
endif(SHADERC_ENABLE_INSTALL)

find_package(Threads)
@@ -79,6 +88,15 @@ else()
target_link_libraries(shaderc_shared PRIVATE ${SHADERC_LIBS})
endif()

+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/unofficial-shaderc-config.cmake" [[
+include(CMakeFindDependencyMacro)
+find_dependency(glslang CONFIG)
+find_dependency(SPIRV-Tools CONFIG)
+find_dependency(SPIRV-Tools-opt CONFIG)
+include("${CMAKE_CURRENT_LIST_DIR}/unofficial-shaderc-targets.cmake")
+]])
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unofficial-shaderc-config.cmake DESTINATION share/unofficial-shaderc)
+
shaderc_add_tests(
TEST_PREFIX shaderc
LINK_LIBS shaderc
diff --git a/libshaderc_util/CMakeLists.txt b/libshaderc_util/CMakeLists.txt
index 99ce3c4..3d5a222 100644
--- a/libshaderc_util/CMakeLists.txt
+++ b/libshaderc_util/CMakeLists.txt
@@ -39,7 +39,7 @@ add_library(shaderc_util STATIC

shaderc_default_compile_options(shaderc_util)
target_include_directories(shaderc_util
- PUBLIC include PRIVATE ${glslang_SOURCE_DIR})
+ PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> PRIVATE ${glslang_SOURCE_DIR})
# We use parts of Glslang's HLSL compilation interface, which
# now requires this preprocessor definition.
add_definitions(-DENABLE_HLSL)
16 changes: 16 additions & 0 deletions ports/shaderc/cmake-project-include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(SHADERC_GLSLANG_DIR "" CACHE STRING "unused")
find_package(glslang CONFIG REQUIRED)
add_library(glslang ALIAS glslang::glslang)
add_library(HLSL ALIAS glslang::HLSL)
add_library(MachineIndependent ALIAS glslang::MachineIndependent)
add_library(OSDependent ALIAS glslang::OSDependent)
add_library(OGLCompiler ALIAS glslang::OGLCompiler)
add_library(SPIRV ALIAS glslang::SPIRV)

find_path(glslang_SOURCE_DIR glslang/Public/ShaderLang.h REQUIRED)
set(glslang_SOURCE_DIR "${glslang_SOURCE_DIR}/glslang" "${glslang_SOURCE_DIR}" CACHE STRING "" FORCE)

set(SHADERC_SPIRV_TOOLS_DIR "" CACHE STRING "unused")
find_package(SPIRV-Tools CONFIG REQUIRED)
add_library(SPIRV-Tools ALIAS SPIRV-Tools-static) # as linked by SPIRV-Tools-opt
find_package(SPIRV-Tools-opt CONFIG REQUIRED)
18 changes: 16 additions & 2 deletions ports/shaderc/fix-build-type.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 52ebd1c..f73252f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -144,6 +144,8 @@ function(define_pkg_config_file NAME LIBS)
endif()
endfunction()

+if(BUILD_SHARED_LIBS)
define_pkg_config_file(shaderc -lshaderc_shared)
+else()
define_pkg_config_file(shaderc_static "-lshaderc ${EXTRA_STATIC_PKGCONFIG_LIBS} -lshaderc_util")
-define_pkg_config_file(shaderc_combined -lshaderc_combined)
+endif()
diff --git a/libshaderc/CMakeLists.txt b/libshaderc/CMakeLists.txt
index 3ada419..f3277f0 100644
index 3ada419..d3bc639 100644
--- a/libshaderc/CMakeLists.txt
+++ b/libshaderc/CMakeLists.txt
@@ -24,13 +24,16 @@ set(SHADERC_SOURCES
Expand Down Expand Up @@ -33,7 +47,7 @@ index 3ada419..f3277f0 100644
${CMAKE_INSTALL_INCLUDEDIR}/shaderc)

- install(TARGETS shaderc shaderc_shared
+ install(TARGETS ${shaderc_install_target}
+ install(TARGETS ${shaderc_install_target} shaderc_util
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand Down
93 changes: 0 additions & 93 deletions ports/shaderc/fix-export-cmakefiles.patch

This file was deleted.

18 changes: 0 additions & 18 deletions ports/shaderc/fix-install-shaderc_util.patch

This file was deleted.

22 changes: 0 additions & 22 deletions ports/shaderc/glslang/CMakeLists.txt

This file was deleted.

14 changes: 6 additions & 8 deletions ports/shaderc/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,40 @@ vcpkg_from_github(
PATCHES
disable-update-version.patch
fix-build-type.patch
fix-install-shaderc_util.patch
fix-export-cmakefiles.patch
cmake-config-export.patch
# NOTE: This should be removed when shaderc gets updated to use glslang 11.12.0
fix-tbuiltinresource-for-glslang-11-12.patch
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/build-version.inc" DESTINATION "${SOURCE_PATH}/glslc/src")

set(OPTIONS)
set(OPTIONS "")
if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
list(APPEND OPTIONS -DSHADERC_ENABLE_SHARED_CRT=ON)
endif()

# shaderc uses python to manipulate copyright information
vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_EXE_PATH ${PYTHON3} DIRECTORY)
get_filename_component(PYTHON3_EXE_PATH "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path(PREPEND "${PYTHON3_EXE_PATH}")

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${OPTIONS}
-DSHADERC_SKIP_TESTS=true
-DSHADERC_GLSLANG_DIR=${CMAKE_CURRENT_LIST_DIR}/glslang
-DSHADERC_SPIRV_TOOLS_DIR=${CMAKE_CURRENT_LIST_DIR}/spirv-tools
"-DCMAKE_PROJECT_INCLUDE=${CMAKE_CURRENT_LIST_DIR}/cmake-project-include.cmake"
vicroms marked this conversation as resolved.
Show resolved Hide resolved
-DSHADERC_ENABLE_EXAMPLES=OFF
-DSHADERC_SKIP_TESTS=true
)

vcpkg_cmake_install()

vcpkg_fixup_pkgconfig()
vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-shaderc CONFIG_PATH share/unofficial-shaderc)
vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-shaderc_util CONFIG_PATH share/unofficial-shaderc_util)

vcpkg_copy_tools(TOOL_NAMES glslc AUTO_CLEAN)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
8 changes: 0 additions & 8 deletions ports/shaderc/spirv-tools/CMakeLists.txt

This file was deleted.

4 changes: 4 additions & 0 deletions ports/shaderc/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
shaderc provides CMake targets:

find_package(unofficial-shaderc CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::shaderc::shaderc)
vicroms marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion ports/shaderc/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shaderc",
"version": "2021.1",
"port-version": 3,
"port-version": 4,
"description": "A collection of tools, libraries and tests for shader compilation.",
"homepage": "https://github.com/google/shaderc",
"license": "Apache-2.0",
Expand Down
13 changes: 13 additions & 0 deletions ports/spirv-tools/cmake-config-dir.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b8fe92..8f3f91a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -269,7 +269,7 @@ else()
endif()

if(ENABLE_SPIRV_TOOLS_INSTALL)
- if(WIN32)
+ if(0)
macro(spvtools_config_package_dir TARGET PATH)
set(${PATH} ${TARGET}/cmake)
endmacro()
18 changes: 18 additions & 0 deletions ports/spirv-tools/fix-tool-deps.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2cf1e40..5f2a86c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -280,8 +280,13 @@ if(ENABLE_SPIRV_TOOLS_INSTALL)
endif()

macro(spvtools_generate_config_file TARGET)
+ set(sgcf_find_extra "")
+ if(NOT "${TARGET}" STREQUAL "SPIRV-Tools-opt")
+ set(sgcf_find_extra "find_dependency(SPIRV-Tools-opt)\n")
+ endif()
file(WRITE ${CMAKE_BINARY_DIR}/${TARGET}Config.cmake
"include(CMakeFindDependencyMacro)\n"
+ ${sgcf_find_extra}
Comment on lines +9 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"find_dependency(${SPIRV_TOOLS})\n"
"include(\${CMAKE_CURRENT_LIST_DIR}/${TARGET}Targets.cmake)\n"
"set(${TARGET}_LIBRARIES ${TARGET})\n"
Loading