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

glslang: add 1.3.224.0 + partial conan v2 support #12967

Merged
merged 2 commits into from
Sep 25, 2022
Merged
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
6 changes: 6 additions & 0 deletions recipes/glslang/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.3.224.0":
url: "https://github.com/KhronosGroup/glslang/archive/refs/tags/sdk-1.3.224.0.tar.gz"
sha256: "c43c6aa149fa1165e01b375b4d95cbc23b4fc72bd9972a89c55dd1eaa8a360ca"
"1.3.216.0":
url: "https://github.com/KhronosGroup/glslang/archive/refs/tags/sdk-1.3.216.0.tar.gz"
sha256: "3f80a926390faedd33e6ed17ec68340abace83913b285174e2dee87156577be5"
Expand All @@ -21,6 +24,9 @@ sources:
url: "https://github.com/KhronosGroup/glslang/archive/8.13.3559.tar.gz"
sha256: "c58fdcf7e00943ba10f9ae565b2725ec9d5be7dab7c8e82cac72fcaa83c652ca"
patches:
"1.3.224.0":
- patch_file: "patches/0001-no-force-glslang-pic.patch"
base_path: "source_subfolder"
"1.3.216.0":
- patch_file: "patches/0001-no-force-glslang-pic.patch"
base_path: "source_subfolder"
Expand Down
77 changes: 44 additions & 33 deletions recipes/glslang/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.files import apply_conandata_patches, copy, get, replace_in_file, rmdir
from conan.tools.scm import Version
from conans import CMake
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.51.3"


class GlslangConan(ConanFile):
Expand Down Expand Up @@ -46,9 +51,9 @@ def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -69,42 +74,37 @@ def _get_compatible_spirv_tools_version(self):

def requirements(self):
if self.options.enable_optimizer:
self.requires("spirv-tools/{}".format(self._get_compatible_spirv_tools_version))
self.requires(f"spirv-tools/{self._get_compatible_spirv_tools_version}")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

# see https://github.com/KhronosGroup/glslang/issues/2283
glslang_version = tools.Version(self.version)
if (self.options.shared and
(self.settings.os == "Windows" or \
(glslang_version >= "7.0.0" and glslang_version < "11.0.0" and tools.is_apple_os(self.settings.os)))
glslang_version = Version(self.version)
if (self.info.options.shared and
(self.info.settings.os == "Windows" or \
(glslang_version >= "7.0.0" and glslang_version < "11.0.0" and is_apple_os(self)))
):
raise ConanInvalidConfiguration(
"glslang {} shared library build is broken on {}".format(
self.version, self.settings.os,
)
)
raise ConanInvalidConfiguration(f"{self.ref} shared library build is broken on {self.info.settings.os}")

if self.options.enable_optimizer and self.options["spirv-tools"].shared:
if self.info.options.enable_optimizer and self.dependencies["spirv-tools"].options.shared:
raise ConanInvalidConfiguration(
"glslang with enable_optimizer requires static spirv-tools, "
f"{self.ref} with enable_optimizer requires static spirv-tools, "
"because SPIRV-Tools-opt is not built if shared"
)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def build(self):
self._patches_sources()
cmake = self._configure_cmake()
cmake.build()

def _patches_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
# Do not force PIC if static (but keep it if shared, because OGLCompiler, OSDependent,
# GenericCodeGen and MachineIndependent are still static and linked to glslang shared)
if not self.options.shared:
Expand All @@ -116,15 +116,15 @@ def _patches_sources(self):
{"target": "OSDependent", "relpath": os.path.join("glslang", "OSDependent", "Windows","CMakeLists.txt")},
{"target": "HLSL" , "relpath": os.path.join("hlsl", "CMakeLists.txt")},
]
glslang_version = tools.Version(self.version)
glslang_version = Version(self.version)
if glslang_version >= "7.0.0" and glslang_version < "11.0.0":
cmake_files_to_fix.append({"target": "glslang" , "relpath": os.path.join("glslang", "CMakeLists.txt")})
else:
cmake_files_to_fix.append({"target": "glslang-default-resource-limits", "relpath": os.path.join("StandAlone" , "CMakeLists.txt")})
cmake_files_to_fix.append({"target": "MachineIndependent", "relpath": os.path.join("glslang", "CMakeLists.txt")})
cmake_files_to_fix.append({"target": "GenericCodeGen", "relpath": os.path.join("glslang", "CMakeLists.txt")})
for cmake_file in cmake_files_to_fix:
tools.replace_in_file(os.path.join(self._source_subfolder, cmake_file["relpath"]),
replace_in_file(self, os.path.join(self.build_folder, self._source_subfolder, cmake_file["relpath"]),
"set_property(TARGET {} PROPERTY POSITION_INDEPENDENT_CODE ON)".format(cmake_file["target"]),
"")

Expand All @@ -136,7 +136,7 @@ def _configure_cmake(self):
self._cmake.definitions["SKIP_GLSLANG_INSTALL"] = False
self._cmake.definitions["ENABLE_SPVREMAPPER"] = self.options.spv_remapper
self._cmake.definitions["ENABLE_GLSLANG_BINARIES"] = self.options.build_executables
glslang_version = tools.Version(self.version)
glslang_version = Version(self.version)
if glslang_version < "7.0.0" or glslang_version >= "8.13.3743":
self._cmake.definitions["ENABLE_GLSLANG_JS"] = False
self._cmake.definitions["ENABLE_GLSLANG_WEBMIN"] = False
Expand All @@ -155,61 +155,70 @@ def _configure_cmake(self):
self._cmake.definitions["USE_CCACHE"] = False
if (glslang_version < "7.0.0" or glslang_version >= "11.6.0") and self.settings.os == "Windows":
self._cmake.definitions["OVERRIDE_MSVCCRT"] = False
if tools.is_apple_os(self.settings.os):
if is_apple_os(self):
self._cmake.definitions["CMAKE_MACOSX_BUNDLE"] = False
# Generate a relocatable shared lib on Macos
self._cmake.definitions["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
copy(self, "LICENSE.txt", src=os.path.join(self.build_folder, self._source_subfolder), dst=os.path.join(self.package_folder, "licenses"))
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
# TODO: glslang exports non-namespaced targets but without config file...
self.cpp_info.set_property("cmake_file_name", "glslang")
self.cpp_info.set_property("cmake_target_name", "glslang::glslang-do-not-use") # because glslang-core target is glslang::glslang

lib_suffix = "d" if self.settings.os == "Windows" and self.settings.build_type == "Debug" else ""
# glslang
self.cpp_info.components["glslang-core"].set_property("cmake_target_name", "glslang::glslang")
self.cpp_info.components["glslang-core"].names["cmake_find_package"] = "glslang"
self.cpp_info.components["glslang-core"].names["cmake_find_package_multi"] = "glslang"
self.cpp_info.components["glslang-core"].libs = ["glslang" + lib_suffix]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["glslang-core"].system_libs.extend(["m", "pthread"])
self.cpp_info.components["glslang-core"].requires = ["oglcompiler", "osdependent"]

glslang_version = tools.Version(self.version)
glslang_version = Version(self.version)
if (glslang_version < "7.0.0" or glslang_version >= "11.0.0"):
if self.options.shared:
self.cpp_info.components["glslang-core"].defines.append("GLSLANG_IS_SHARED_LIBRARY")
else:
# MachineIndependent
self.cpp_info.components["machineindependent"].set_property("cmake_target_name", "glslang::MachineIndependent")
self.cpp_info.components["machineindependent"].names["cmake_find_package"] = "MachineIndependent"
self.cpp_info.components["machineindependent"].names["cmake_find_package_multi"] = "MachineIndependent"
self.cpp_info.components["machineindependent"].libs = ["MachineIndependent" + lib_suffix]
self.cpp_info.components["machineindependent"].requires = ["oglcompiler", "osdependent", "genericcodegen"]
self.cpp_info.components["glslang-core"].requires.append("machineindependent")

# GenericCodeGen
self.cpp_info.components["genericcodegen"].set_property("cmake_target_name", "glslang::GenericCodeGen")
self.cpp_info.components["genericcodegen"].names["cmake_find_package"] = "GenericCodeGen"
self.cpp_info.components["genericcodegen"].names["cmake_find_package_multi"] = "GenericCodeGen"
self.cpp_info.components["genericcodegen"].libs = ["GenericCodeGen" + lib_suffix]
self.cpp_info.components["glslang-core"].requires.append("genericcodegen")

# OSDependent
self.cpp_info.components["osdependent"].set_property("cmake_target_name", "glslang::OSDependent")
self.cpp_info.components["osdependent"].names["cmake_find_package"] = "OSDependent"
self.cpp_info.components["osdependent"].names["cmake_find_package_multi"] = "OSDependent"
self.cpp_info.components["osdependent"].libs = ["OSDependent" + lib_suffix]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["osdependent"].system_libs.append("pthread")

# OGLCompiler
self.cpp_info.components["oglcompiler"].set_property("cmake_target_name", "glslang::OGLCompiler")
self.cpp_info.components["oglcompiler"].names["cmake_find_package"] = "OGLCompiler"
self.cpp_info.components["oglcompiler"].names["cmake_find_package_multi"] = "OGLCompiler"
self.cpp_info.components["oglcompiler"].libs = ["OGLCompiler" + lib_suffix]

# SPIRV
self.cpp_info.components["spirv"].set_property("cmake_target_name", "glslang::SPIRV")
self.cpp_info.components["spirv"].names["cmake_find_package"] = "SPIRV"
self.cpp_info.components["spirv"].names["cmake_find_package_multi"] = "SPIRV"
self.cpp_info.components["spirv"].libs = ["SPIRV" + lib_suffix]
Expand All @@ -220,6 +229,7 @@ def package_info(self):

# HLSL
if self.options.hlsl:
self.cpp_info.components["hlsl"].set_property("cmake_target_name", "glslang::HLSL")
self.cpp_info.components["hlsl"].names["cmake_find_package"] = "HLSL"
self.cpp_info.components["hlsl"].names["cmake_find_package_multi"] = "HLSL"
self.cpp_info.components["hlsl"].libs = ["HLSL" + lib_suffix]
Expand All @@ -228,11 +238,12 @@ def package_info(self):

# SPVRemapper
if self.options.spv_remapper:
self.cpp_info.components["spvremapper"].set_property("cmake_target_name", "glslang::SPVRemapper")
self.cpp_info.components["spvremapper"].names["cmake_find_package"] = "SPVRemapper"
self.cpp_info.components["spvremapper"].names["cmake_find_package_multi"] = "SPVRemapper"
self.cpp_info.components["spvremapper"].libs = ["SPVRemapper" + lib_suffix]

if self.options.build_executables:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.output.info(f"Appending PATH environment variable: {bin_path}")
self.env_info.PATH.append(bin_path)
11 changes: 5 additions & 6 deletions recipes/glslang/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(glslang REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} PRIVATE glslang::glslang)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
21 changes: 15 additions & 6 deletions recipes/glslang/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
shader_name = os.path.join(self.source_folder, "test_package.vert")
self.run("glslangValidator \"{}\"".format(shader_name), run_environment=True)
self.run(f"glslangValidator \"{shader_name}\"", env="conanrun")
11 changes: 11 additions & 0 deletions recipes/glslang/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(glslang REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE glslang::glslang)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
19 changes: 19 additions & 0 deletions recipes/glslang/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
shader_name = os.path.join(self.source_folder, os.pardir, "test_package", "test_package.vert")
self.run(f"glslangValidator \"{shader_name}\"", run_environment=True)
2 changes: 2 additions & 0 deletions recipes/glslang/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.3.224.0":
folder: all
"1.3.216.0":
folder: all
"1.3.211.0":
Expand Down