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

spirv-tools: fix shared build #25310

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
169 changes: 54 additions & 115 deletions recipes/spirv-tools/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from conan.tools.build import check_min_cppstd, stdcpp_library
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, replace_in_file, rm, rmdir, save
from conan.tools.files import copy, get, replace_in_file, rmdir, save
from conan.tools.scm import Version
import os
import textwrap
Expand Down Expand Up @@ -86,29 +86,11 @@ def generate(self):
env.generate()

tc = CMakeToolchain(self)

#====================
# Shared libs mess in Spirv-Tools (see https://github.com/KhronosGroup/SPIRV-Tools/issues/3909)
#====================
# We have 2 solutions if shared True:
# - Only package SPIRV-Tools-shared lib (private symbols properly hidden), and wait resolution
# of above issue before allowing to build shared for all Spirv-Tools libs.
# - Build and package shared libs with all symbols exported
# (it would require CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS for msvc)
# Currently this recipe implements the first solution

# Static and shared libs are controlled by a weird combination
# of SPIRV_TOOLS_BUILD_STATIC and BUILD_SHARED_LIBS.
tc.variables["SPIRV_TOOLS_BUILD_STATIC"] = True
#============

# BUILD_SHARED_LIBS is used if SPIRV_TOOLS_BUILD_STATIC is set to False
tc.variables["SPIRV_TOOLS_BUILD_STATIC"] = False
# Required by the project's CMakeLists.txt
tc.variables["SPIRV-Headers_SOURCE_DIR"] = self.dependencies["spirv-headers"].package_folder.replace("\\", "/")

# There are some switch( ) statements that are causing errors
# need to turn this off
tc.variables["SPIRV_WERROR"] = False

tc.variables["SKIP_SPIRV_TOOLS_INSTALL"] = False
tc.variables["SPIRV_LOG_DEBUG"] = False
tc.variables["SPIRV_SKIP_TESTS"] = True
Expand All @@ -120,12 +102,9 @@ def generate(self):
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
# For iOS/tvOS/watchOS
tc.variables["CMAKE_MACOSX_BUNDLE"] = False

tc.generate()

def _patch_sources(self):
# CMAKE_POSITION_INDEPENDENT_CODE was set ON for the entire
# project in the lists file.
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set(CMAKE_POSITION_INDEPENDENT_CODE ON)", "")

Expand All @@ -142,37 +121,18 @@ def package(self):

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools-link"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools-opt"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools-reduce"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools-lint"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools-diff"))
rmdir(self, os.path.join(self.package_folder, "SPIRV-Tools-tools"))
if self.options.shared:
for file_name in [
"*SPIRV-Tools", "*SPIRV-Tools-opt", "*SPIRV-Tools-link",
"*SPIRV-Tools-reduce", "*SPIRV-Tools-lint",
]:
for ext in [".a", ".lib"]:
rm(self, f"{file_name}{ext}", os.path.join(self.package_folder, "lib"))
else:
rm(self, "*SPIRV-Tools-shared.dll", os.path.join(self.package_folder, "bin"))
rm(self, "*SPIRV-Tools-shared*", os.path.join(self.package_folder, "lib"))

# TODO: to remove in conan v2 once cmake_find_package* generators removed
if self.options.shared:
targets = {"SPIRV-Tools-shared": "spirv-tools::SPIRV-Tools"}
else:
targets = {
"SPIRV-Tools": "spirv-tools::SPIRV-Tools", # before 2020.5, kept for conveniency
"SPIRV-Tools-static": "spirv-tools::SPIRV-Tools",
"SPIRV-Tools-opt": "spirv-tools::SPIRV-Tools-opt",
"SPIRV-Tools-link": "spirv-tools::SPIRV-Tools-link",
"SPIRV-Tools-reduce": "spirv-tools::SPIRV-Tools-reduce",
"SPIRV-Tools-lint": "spirv-tools::SPIRV-Tools-lint",
"SPIRV-Tools-diff": "spirv-tools::SPIRV-Tools-diff",
}
targets = {
"SPIRV-Tools": "spirv-tools::SPIRV-Tools",
"SPIRV-Tools-shared": "spirv-tools::SPIRV-Tools",
"SPIRV-Tools-static": "spirv-tools::SPIRV-Tools",
"SPIRV-Tools-opt": "spirv-tools::SPIRV-Tools-opt",
"SPIRV-Tools-link": "spirv-tools::SPIRV-Tools-link",
"SPIRV-Tools-reduce": "spirv-tools::SPIRV-Tools-reduce",
"SPIRV-Tools-lint": "spirv-tools::SPIRV-Tools-lint",
"SPIRV-Tools-diff": "spirv-tools::SPIRV-Tools-diff",
}
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
targets,
Expand All @@ -195,15 +155,16 @@ def _module_file_rel_path(self):

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "SPIRV-Tools")
self.cpp_info.set_property("pkg_config_name", "SPIRV-Tools-shared" if self.options.shared else "SPIRV-Tools")
self.cpp_info.set_property("pkg_config_name", "SPIRV-Tools")
if self.options.shared:
self.cpp_info.set_property("pkg_config_aliases", ["SPIRV-Tools-shared"])

# SPIRV-Tools
self.cpp_info.components["spirv-tools-core"].set_property(
"cmake_target_name",
"SPIRV-Tools-shared" if self.options.shared else "SPIRV-Tools-static",
)
self.cpp_info.components["spirv-tools-core"].set_property("cmake_target_aliases", ["SPIRV-Tools"]) # before 2020.5, kept for conveniency
self.cpp_info.components["spirv-tools-core"].libs = ["SPIRV-Tools-shared" if self.options.shared else "SPIRV-Tools"]
self.cpp_info.components["spirv-tools-core"].set_property("cmake_target_name", "SPIRV-Tools")
self.cpp_info.components["spirv-tools-core"].set_property("cmake_target_aliases", ["SPIRV-Tools-shared" if self.options.shared else "SPIRV-Tools-static"])
self.cpp_info.components["spirv-tools-core"].libs = ["SPIRV-Tools"]
if self.options.shared:
self.cpp_info.components["spirv-tools-core"].libs.append("SPIRV-Tools-shared")
self.cpp_info.components["spirv-tools-core"].requires = ["spirv-headers::spirv-headers"]
if self.options.shared:
self.cpp_info.components["spirv-tools-core"].defines = ["SPIRV_TOOLS_SHAREDLIB"]
Expand All @@ -215,66 +176,44 @@ def package_info(self):
self.cpp_info.components["spirv-tools-core"].system_libs.append(libcxx)

# FIXME: others components should have their own CMake config file
if not self.options.shared:
# SPIRV-Tools-opt
self.cpp_info.components["spirv-tools-opt"].set_property("cmake_target_name", "SPIRV-Tools-opt")
self.cpp_info.components["spirv-tools-opt"].libs = ["SPIRV-Tools-opt"]
self.cpp_info.components["spirv-tools-opt"].requires = ["spirv-tools-core", "spirv-headers::spirv-headers"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["spirv-tools-opt"].system_libs.append("m")

# SPIRV-Tools-link
self.cpp_info.components["spirv-tools-link"].set_property("cmake_target_name", "SPIRV-Tools-link")
self.cpp_info.components["spirv-tools-link"].libs = ["SPIRV-Tools-link"]
self.cpp_info.components["spirv-tools-link"].requires = ["spirv-tools-core", "spirv-tools-opt"]

# SPIRV-Tools-reduce
self.cpp_info.components["spirv-tools-reduce"].set_property("cmake_target_name", "SPIRV-Tools-reduce")
self.cpp_info.components["spirv-tools-reduce"].libs = ["SPIRV-Tools-reduce"]
self.cpp_info.components["spirv-tools-reduce"].requires = ["spirv-tools-core", "spirv-tools-opt"]

# SPIRV-Tools-lint
self.cpp_info.components["spirv-tools-lint"].set_property("cmake_target_name", "SPIRV-Tools-lint")
self.cpp_info.components["spirv-tools-lint"].libs = ["SPIRV-Tools-lint"]
self.cpp_info.components["spirv-tools-lint"].requires = ["spirv-tools-core", "spirv-tools-opt"]

# SPIRV-Tools-diff
self.cpp_info.components["spirv-tools-diff"].set_property("cmake_target_name", "SPIRV-Tools-diff")
self.cpp_info.components["spirv-tools-diff"].libs = ["SPIRV-Tools-diff"]
self.cpp_info.components["spirv-tools-diff"].requires = ["spirv-tools-core", "spirv-tools-opt"]
# SPIRV-Tools-opt
self.cpp_info.components["spirv-tools-opt"].set_property("cmake_target_name", "SPIRV-Tools-opt")
self.cpp_info.components["spirv-tools-opt"].libs = ["SPIRV-Tools-opt"]
self.cpp_info.components["spirv-tools-opt"].requires = ["spirv-tools-core", "spirv-headers::spirv-headers"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["spirv-tools-opt"].system_libs.append("m")

# SPIRV-Tools-link
self.cpp_info.components["spirv-tools-link"].set_property("cmake_target_name", "SPIRV-Tools-link")
self.cpp_info.components["spirv-tools-link"].libs = ["SPIRV-Tools-link"]
self.cpp_info.components["spirv-tools-link"].requires = ["spirv-tools-core", "spirv-tools-opt"]

# SPIRV-Tools-reduce
self.cpp_info.components["spirv-tools-reduce"].set_property("cmake_target_name", "SPIRV-Tools-reduce")
self.cpp_info.components["spirv-tools-reduce"].libs = ["SPIRV-Tools-reduce"]
self.cpp_info.components["spirv-tools-reduce"].requires = ["spirv-tools-core", "spirv-tools-opt"]

# SPIRV-Tools-lint
self.cpp_info.components["spirv-tools-lint"].set_property("cmake_target_name", "SPIRV-Tools-lint")
self.cpp_info.components["spirv-tools-lint"].libs = ["SPIRV-Tools-lint"]
self.cpp_info.components["spirv-tools-lint"].requires = ["spirv-tools-core", "spirv-tools-opt"]

# SPIRV-Tools-diff
self.cpp_info.components["spirv-tools-diff"].set_property("cmake_target_name", "SPIRV-Tools-diff")
self.cpp_info.components["spirv-tools-diff"].libs = ["SPIRV-Tools-diff"]
self.cpp_info.components["spirv-tools-diff"].requires = ["spirv-tools-core", "spirv-tools-opt"]

if self.options.build_executables:
self.env_info.path.append(os.path.join(self.package_folder, "bin"))

# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
self.cpp_info.filenames["cmake_find_package"] = "SPIRV-Tools"
self.cpp_info.filenames["cmake_find_package_multi"] = "SPIRV-Tools"
self.cpp_info.names["pkg_config"] = "SPIRV-Tools-shared" if self.options.shared else "SPIRV-Tools"
self.cpp_info.components["spirv-tools-core"].names["cmake_find_package"] = "SPIRV-Tools"
self.cpp_info.components["spirv-tools-core"].names["cmake_find_package_multi"] = "SPIRV-Tools"
self.cpp_info.components["spirv-tools-core"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-core"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
if not self.options.shared:
self.cpp_info.components["spirv-tools-opt"].names["cmake_find_package"] = "SPIRV-Tools-opt"
self.cpp_info.components["spirv-tools-opt"].names["cmake_find_package_multi"] = "SPIRV-Tools-opt"
self.cpp_info.components["spirv-tools-opt"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-opt"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-link"].names["cmake_find_package"] = "SPIRV-Tools-link"
self.cpp_info.components["spirv-tools-link"].names["cmake_find_package_multi"] = "SPIRV-Tools-link"
self.cpp_info.components["spirv-tools-link"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-link"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-reduce"].names["cmake_find_package"] = "SPIRV-Tools-reduce"
self.cpp_info.components["spirv-tools-reduce"].names["cmake_find_package_multi"] = "SPIRV-Tools-reduce"
self.cpp_info.components["spirv-tools-reduce"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-reduce"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-lint"].names["cmake_find_package"] = "SPIRV-Tools-lint"
self.cpp_info.components["spirv-tools-lint"].names["cmake_find_package_multi"] = "SPIRV-Tools-lint"
self.cpp_info.components["spirv-tools-lint"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-lint"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-diff"].names["cmake_find_package"] = "SPIRV-Tools-diff"
self.cpp_info.components["spirv-tools-diff"].names["cmake_find_package_multi"] = "SPIRV-Tools-diff"
self.cpp_info.components["spirv-tools-diff"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["spirv-tools-diff"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]

if Version(self.version) < "1.3" and not self.options.shared:
for lib in ["core", "opt", "link", "reduce", "lint", "diff"]:
self.cpp_info.components[f"spirv-tools-{lib}"].names["cmake_find_package"] = f"SPIRV-Tools-{lib}"
self.cpp_info.components[f"spirv-tools-{lib}"].names["cmake_find_package_multi"] = f"SPIRV-Tools-{lib}"
self.cpp_info.components[f"spirv-tools-{lib}"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components[f"spirv-tools-{lib}"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]

if Version(self.version) < "1.3":
del self.cpp_info.components["spirv-tools-diff"]
24 changes: 8 additions & 16 deletions recipes/spirv-tools/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(test_package)

find_package(SPIRV-Tools REQUIRED CONFIG)

add_executable(${PROJECT_NAME}_c test_package.c)
if(TARGET SPIRV-Tools-shared)
target_link_libraries(${PROJECT_NAME}_c PRIVATE SPIRV-Tools-shared)
elseif(TARGET SPIRV-Tools-static)
target_link_libraries(${PROJECT_NAME}_c PRIVATE SPIRV-Tools-static)
else()
target_link_libraries(${PROJECT_NAME}_c PRIVATE SPIRV-Tools)
endif()
target_link_libraries(${PROJECT_NAME}_c PRIVATE SPIRV-Tools)

# TODO: we should call find_package(SPIRV-Tools-opt REQUIRED CONFIG), but not modeled right now
if(TARGET SPIRV-Tools-opt)
add_executable(${PROJECT_NAME}_cpp test_package.cpp)
target_link_libraries(${PROJECT_NAME}_cpp PRIVATE SPIRV-Tools-opt)
if(SPIRV-Tools_VERSION VERSION_LESS "1.3.243.0")
target_compile_features(${PROJECT_NAME}_cpp PRIVATE cxx_std_11)
else()
target_compile_features(${PROJECT_NAME}_cpp PRIVATE cxx_std_17)
endif()
add_executable(${PROJECT_NAME}_cpp test_package.cpp)
target_link_libraries(${PROJECT_NAME}_cpp PRIVATE SPIRV-Tools-opt)
if(SPIRV-Tools_VERSION VERSION_LESS "1.3.243.0")
target_compile_features(${PROJECT_NAME}_cpp PRIVATE cxx_std_11)
else()
target_compile_features(${PROJECT_NAME}_cpp PRIVATE cxx_std_17)
endif()
Loading