From 040e377355d48f8b8c7a711c9997babaf9522c36 Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 14:53:13 +0200
Subject: [PATCH 01/11] conan v2 support
---
recipes/xz_utils/all/conanfile.py | 166 +++++++++---------
.../xz_utils/all/test_package/CMakeLists.txt | 7 +-
.../xz_utils/all/test_package/conanfile.py | 28 +--
.../all/test_v1_package/CMakeLists.txt | 10 ++
.../xz_utils/all/test_v1_package/conanfile.py | 17 ++
5 files changed, 125 insertions(+), 103 deletions(-)
create mode 100644 recipes/xz_utils/all/test_v1_package/CMakeLists.txt
create mode 100644 recipes/xz_utils/all/test_v1_package/conanfile.py
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 8358c6924229e..0a87851360232 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -1,9 +1,15 @@
-from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
-from conans.tools import Version
+from conan import ConanFile
+from conan.tools.apple import fix_apple_shared_install_name
+from conan.tools.env import VirtualBuildEnv
+from conan.tools.files import chdir, collect_libs, copy, get, rename, replace_in_file, rm, rmdir, save
+from conan.tools.gnu import Autotools, AutotoolsToolchain
+from conan.tools.layout import basic_layout
+from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain
+from conan.tools.scm import Version
import os
import textwrap
-required_conan_version = ">=1.43.0"
+required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2"
class XZUtils(ConanFile):
@@ -28,16 +34,6 @@ class XZUtils(ConanFile):
"fPIC": True,
}
- _autotools = None
-
- @property
- def _source_subfolder(self):
- return "source_subfolder"
-
- @property
- def _is_msvc(self):
- return str(self.settings.compiler) in ["Visual Studio", "msvc"]
-
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
@@ -54,20 +50,29 @@ def config_options(self):
def configure(self):
if self.options.shared:
del self.options.fPIC
- del self.settings.compiler.cppstd
- del self.settings.compiler.libcxx
+ try:
+ del self.settings.compiler.libcxx
+ except Exception:
+ pass
+ try:
+ del self.settings.compiler.cppstd
+ except Exception:
+ pass
+
+ def layout(self):
+ basic_layout(self, src_folder="src")
def build_requirements(self):
- if self._settings_build.os == "Windows" and not self._is_msvc and \
- not tools.get_env("CONAN_BASH_PATH"):
- self.build_requires("msys2/cci.latest")
+ if self._settings_build.os == "Windows" and not is_msvc(self) and \
+ not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool):
+ self.tool_requires("msys2/cci.latest")
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_folder, strip_root=True)
def _apply_patches(self):
- if tools.Version(self.version) == "5.2.4" and self._is_msvc:
+ if Version(self.version) == "5.2.4" and is_msvc(self):
# Relax Windows SDK restriction
# Workaround is required only for 5.2.4 because since 5.2.5 WindowsTargetPlatformVersion is dropped from vcproj file
#
@@ -75,112 +80,105 @@ def _apply_patches(self):
# undocumented method, but officially recommended workaround by microsoft at at
# https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html
windows_target_platform_version_old = "10.0.15063.0"
- if self.settings.compiler.version == 15:
+ if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) == "15") or \
+ (self.settings.compiler == "msvc" and Version(self.settings.compiler) == "191"):
windows_target_platform_version_new = "$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))"
else:
windows_target_platform_version_new = "10.0"
- tools.replace_in_file(os.path.join(self._source_subfolder, "windows", "vs2017", "liblzma.vcxproj"),
+ replace_in_file(self, os.path.join(self.source_folder, "windows", "vs2017", "liblzma.vcxproj"),
windows_target_platform_version_old,
windows_target_platform_version_new)
- tools.replace_in_file(os.path.join(self._source_subfolder, "windows", "vs2017", "liblzma_dll.vcxproj"),
+ replace_in_file(self, os.path.join(self.source_folder, "windows", "vs2017", "liblzma_dll.vcxproj"),
windows_target_platform_version_old,
windows_target_platform_version_new)
- # Allow to install relocatable shared lib on macOS
- if tools.is_apple_os(self.settings.os):
- tools.replace_in_file(
- os.path.join(self._source_subfolder, "configure"),
- "-install_name \\$rpath/",
- "-install_name @rpath/",
- )
-
def _build_msvc(self):
# windows\INSTALL-MSVC.txt
- msvc_version = "vs2017" if Version(self.settings.compiler.version) >= "15" else "vs2013"
- with tools.chdir(os.path.join(self._source_subfolder, "windows", msvc_version)):
+ if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) >= "15") or \
+ (self.settings.compiler == "msvc" and Version(self.settings.compiler) >= "191"):
+ msvc_version = "vs2017"
+ else:
+ msvc_version = "vs2013"
+ with chdir(os.path.join(self.source_folder, "windows", msvc_version)):
target = "liblzma_dll" if self.options.shared else "liblzma"
msbuild = MSBuild(self)
- msbuild.build(
- "xz_win.sln",
- targets=[target],
- build_type=self._effective_msbuild_type,
- platforms={"x86": "Win32", "x86_64": "x64"},
- upgrade_project=Version(self.settings.compiler.version) >= "17")
-
- def _configure_autotools(self):
- if self._autotools:
- return self._autotools
- self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
- args = ["--disable-doc"]
- if self.settings.os != "Windows" and self.options.get_safe("fPIC", True):
- args.append("--with-pic")
- if self.options.shared:
- args.extend(["--disable-static", "--enable-shared"])
+ msbuild.build_type = self._effective_msbuild_type
+ msbuild.platform = "Win32" if self.settings.arch == "x86" else msbuild.platform
+ msbuild.build("xz_win.sln", targets=[target])
+
+ def generate(self):
+ if is_msvc(self):
+ tc = MSBuildToolchain(self)
+ tc.generate()
else:
- args.extend(["--enable-static", "--disable-shared"])
- if self.settings.build_type == "Debug":
- args.append("--enable-debug")
- self._autotools.configure(configure_dir=self._source_subfolder, args=args, build=False)
- return self._autotools
+ tc = AutotoolsToolchain(self)
+ tc.configure_args.append("--disable-doc")
+ if self.settings.build_type == "Debug":
+ tc.configure_args.append("--enable-debug")
+ tc.generate()
+ env = VirtualBuildEnv(self)
+ env.generate()
def build(self):
self._apply_patches()
- if self._is_msvc:
+ if is_msvc(self):
self._build_msvc()
else:
- autotools = self._configure_autotools()
+ autotools = Autotools(self)
+ self.win_bash = True
+ autotools.configure()
autotools.make()
+ self.win_bash = None
def package(self):
- self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
- if self._is_msvc:
- inc_dir = os.path.join(self._source_subfolder, "src", "liblzma", "api")
- self.copy(pattern="*.h", dst="include", src=inc_dir, keep_path=True)
+ copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
+ if is_msvc(self):
+ inc_dir = os.path.join(self.source_folder, "src", "liblzma", "api")
+ copy(self, "*.h", src=inc_dir, dst=os.path.join(self.package_folder, "include"), keep_path=True)
arch = {"x86": "Win32", "x86_64": "x64"}.get(str(self.settings.arch))
target = "liblzma_dll" if self.options.shared else "liblzma"
msvc_version = "vs2017" if Version(self.settings.compiler.version) >= "15" else "vs2013"
- bin_dir = os.path.join(self._source_subfolder, "windows", msvc_version,
+ bin_dir = os.path.join(self.source_folder, "windows", msvc_version,
self._effective_msbuild_type, arch, target)
- self.copy(pattern="*.lib", dst="lib", src=bin_dir, keep_path=False)
+ copy(self, "*.lib", src=bin_dir, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
if self.options.shared:
- self.copy(pattern="*.dll", dst="bin", src=bin_dir, keep_path=False)
- tools.rename(os.path.join(self.package_folder, "lib", "liblzma.lib"),
+ copy(self, "*.dll", src=bin_dir, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
+ rename(self, os.path.join(self.package_folder, "lib", "liblzma.lib"),
os.path.join(self.package_folder, "lib", "lzma.lib"))
else:
- autotools = self._configure_autotools()
+ autotools = Autotools(self)
+ self.win_bash = True
autotools.install()
- tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
- tools.rmdir(os.path.join(self.package_folder, "share"))
- tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
+ self.win_bash = None
+ rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+ rmdir(self, os.path.join(self.package_folder, "share"))
+ rm(self, "*.la", os.path.join(self.package_folder, "lib"))
+ fix_apple_shared_install_name(self)
self._create_cmake_module_variables(
os.path.join(self.package_folder, self._module_file_rel_path),
- tools.Version(self.version)
)
- @staticmethod
- def _create_cmake_module_variables(module_file, version):
+ def _create_cmake_module_variables(self, module_file):
# TODO: also add LIBLZMA_HAS_AUTO_DECODER, LIBLZMA_HAS_EASY_ENCODER & LIBLZMA_HAS_LZMA_PRESET
- content = textwrap.dedent("""\
- if(DEFINED LibLZMA_FOUND)
- set(LIBLZMA_FOUND ${{LibLZMA_FOUND}})
- endif()
+ content = textwrap.dedent(f"""\
+ set(LIBLZMA_FOUND TRUE)
if(DEFINED LibLZMA_INCLUDE_DIRS)
set(LIBLZMA_INCLUDE_DIRS ${{LibLZMA_INCLUDE_DIRS}})
endif()
if(DEFINED LibLZMA_LIBRARIES)
set(LIBLZMA_LIBRARIES ${{LibLZMA_LIBRARIES}})
endif()
- set(LIBLZMA_VERSION_MAJOR {major})
- set(LIBLZMA_VERSION_MINOR {minor})
- set(LIBLZMA_VERSION_PATCH {patch})
- set(LIBLZMA_VERSION_STRING "{major}.{minor}.{patch}")
- """.format(major=version.major, minor=version.minor, patch=version.patch))
- tools.save(module_file, content)
+ set(LIBLZMA_VERSION_MAJOR {Version(self.version).major})
+ set(LIBLZMA_VERSION_MINOR {Version(self.version).minor})
+ set(LIBLZMA_VERSION_PATCH {Version(self.version).patch})
+ set(LIBLZMA_VERSION_STRING "{self.version}")
+ """)
+ save(self, module_file, content)
@property
def _module_file_rel_path(self):
- return os.path.join("lib", "cmake", "conan-official-{}-variables.cmake".format(self.name))
+ return os.path.join("lib", "cmake", f"conan-official-{self.name}-variables.cmake")
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
@@ -192,7 +190,7 @@ def package_info(self):
self.cpp_info.defines.append("LZMA_API_STATIC")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
- self.cpp_info.libs = tools.collect_libs(self)
+ self.cpp_info.libs = collect_libs(self)
# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
self.cpp_info.names["cmake_find_package"] = "LibLZMA"
diff --git a/recipes/xz_utils/all/test_package/CMakeLists.txt b/recipes/xz_utils/all/test_package/CMakeLists.txt
index 52957893e3d02..e2148d8333786 100644
--- a/recipes/xz_utils/all/test_package/CMakeLists.txt
+++ b/recipes/xz_utils/all/test_package/CMakeLists.txt
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
-project(test_package C)
-
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup(TARGETS)
+project(test_package LANGUAGES C)
find_package(LibLZMA REQUIRED)
add_executable(${PROJECT_NAME} test_package.c)
-target_link_libraries(${PROJECT_NAME} LibLZMA::LibLZMA)
+target_link_libraries(${PROJECT_NAME} PRIVATE LibLZMA::LibLZMA)
diff --git a/recipes/xz_utils/all/test_package/conanfile.py b/recipes/xz_utils/all/test_package/conanfile.py
index 52ff86a518167..0a6bc68712d90 100644
--- a/recipes/xz_utils/all/test_package/conanfile.py
+++ b/recipes/xz_utils/all/test_package/conanfile.py
@@ -1,19 +1,19 @@
-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", "compiler", "build_type", "arch"
- generators = "cmake", "cmake_find_package"
+ settings = "os", "arch", "compiler", "build_type"
+ generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
+ test_type = "explicit"
- def build_requirements(self):
- if self.settings.os == "Macos" and self.settings.arch == "armv8":
- # Workaround for CMake bug with error message:
- # Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
- # set. This could be because you are using a Mac OS X version less than 10.5
- # or because CMake's platform configuration is corrupt.
- # FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
- self.build_requires("cmake/3.22.0")
+ def layout(self):
+ cmake_layout(self)
+
+ def requirements(self):
+ self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
@@ -21,6 +21,6 @@ def build(self):
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")
diff --git a/recipes/xz_utils/all/test_v1_package/CMakeLists.txt b/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
new file mode 100644
index 0000000000000..b56517fa8b604
--- /dev/null
+++ b/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package LANGUAGES C)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(LibLZMA REQUIRED)
+
+add_executable(${PROJECT_NAME} ../test_package/test_package.c)
+target_link_libraries(${PROJECT_NAME} PRIVATE LibLZMA::LibLZMA)
diff --git a/recipes/xz_utils/all/test_v1_package/conanfile.py b/recipes/xz_utils/all/test_v1_package/conanfile.py
new file mode 100644
index 0000000000000..19e6a0c06e3d8
--- /dev/null
+++ b/recipes/xz_utils/all/test_v1_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+ settings = "os", "arch", "compiler", "build_type"
+ generators = "cmake", "cmake_find_package"
+
+ 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)
From e52fc58dd587aa982ec09bd179fbada9dd2ae74b Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 16:03:39 +0200
Subject: [PATCH 02/11] typo
---
recipes/xz_utils/all/conanfile.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 0a87851360232..4cc6c6d7b4cab 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -99,7 +99,7 @@ def _build_msvc(self):
msvc_version = "vs2017"
else:
msvc_version = "vs2013"
- with chdir(os.path.join(self.source_folder, "windows", msvc_version)):
+ with chdir(self, os.path.join(self.source_folder, "windows", msvc_version)):
target = "liblzma_dll" if self.options.shared else "liblzma"
msbuild = MSBuild(self)
msbuild.build_type = self._effective_msbuild_type
From 4e40e8ad67eb2d53bbe43949d7201d08b9d8651e Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 16:21:51 +0200
Subject: [PATCH 03/11] refactor slightly
---
recipes/xz_utils/all/conanfile.py | 32 +++++++++++++++----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 4cc6c6d7b4cab..5e0e933afcbb9 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -71,8 +71,21 @@ def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
- def _apply_patches(self):
- if Version(self.version) == "5.2.4" and is_msvc(self):
+ def generate(self):
+ if is_msvc(self):
+ tc = MSBuildToolchain(self)
+ tc.generate()
+ else:
+ tc = AutotoolsToolchain(self)
+ tc.configure_args.append("--disable-doc")
+ if self.settings.build_type == "Debug":
+ tc.configure_args.append("--enable-debug")
+ tc.generate()
+ env = VirtualBuildEnv(self)
+ env.generate()
+
+ def _build_msvc(self):
+ if Version(self.version) == "5.2.4":
# Relax Windows SDK restriction
# Workaround is required only for 5.2.4 because since 5.2.5 WindowsTargetPlatformVersion is dropped from vcproj file
#
@@ -92,7 +105,6 @@ def _apply_patches(self):
windows_target_platform_version_old,
windows_target_platform_version_new)
- def _build_msvc(self):
# windows\INSTALL-MSVC.txt
if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) >= "15") or \
(self.settings.compiler == "msvc" and Version(self.settings.compiler) >= "191"):
@@ -106,21 +118,7 @@ def _build_msvc(self):
msbuild.platform = "Win32" if self.settings.arch == "x86" else msbuild.platform
msbuild.build("xz_win.sln", targets=[target])
- def generate(self):
- if is_msvc(self):
- tc = MSBuildToolchain(self)
- tc.generate()
- else:
- tc = AutotoolsToolchain(self)
- tc.configure_args.append("--disable-doc")
- if self.settings.build_type == "Debug":
- tc.configure_args.append("--enable-debug")
- tc.generate()
- env = VirtualBuildEnv(self)
- env.generate()
-
def build(self):
- self._apply_patches()
if is_msvc(self):
self._build_msvc()
else:
From 1458445b8cf21287d751241d8c042fac14e8a99f Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 17:11:30 +0200
Subject: [PATCH 04/11] fix MinGW build
DESTDIR manually injected due to https://github.com/conan-io/conan/issues/12153
---
recipes/xz_utils/all/conanfile.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 5e0e933afcbb9..3934c0a1a62f4 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -4,7 +4,7 @@
from conan.tools.files import chdir, collect_libs, copy, get, rename, replace_in_file, rm, rmdir, save
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
-from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain
+from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain, unix_path
from conan.tools.scm import Version
import os
import textwrap
@@ -146,7 +146,8 @@ def package(self):
else:
autotools = Autotools(self)
self.win_bash = True
- autotools.install()
+ # TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed
+ autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
self.win_bash = None
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
From 35d73fcf69428c0eafe3091dc3b5c0b740ea71b6 Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 17:58:52 +0200
Subject: [PATCH 05/11] workaround to update PlatformToolset in vcxproj files
---
recipes/xz_utils/all/conanfile.py | 57 ++++++++++++++++++++++++++-----
1 file changed, 49 insertions(+), 8 deletions(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 3934c0a1a62f4..4960f2534163d 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -1,7 +1,8 @@
from conan import ConanFile
+from conan.errors import ConanException
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.env import VirtualBuildEnv
-from conan.tools.files import chdir, collect_libs, copy, get, rename, replace_in_file, rm, rmdir, save
+from conan.tools.files import collect_libs, copy, get, rename, replace_in_file, rm, rmdir, save
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain, unix_path
@@ -9,7 +10,7 @@
import os
import textwrap
-required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2"
+required_conan_version = ">=1.52.0"
class XZUtils(ConanFile):
@@ -84,6 +85,39 @@ def generate(self):
env = VirtualBuildEnv(self)
env.generate()
+ def _fix_msvc_platform_toolset(self, vcxproj_file, old_toolset):
+ platform_toolset = {
+ "Visual Studio": {
+ "8": "v80",
+ "9": "v90",
+ "10": "v100",
+ "11": "v110",
+ "12": "v120",
+ "14": "v140",
+ "15": "v141",
+ "16": "v142",
+ "17": "v143",
+ },
+ "msvc": {
+ "170": "v110",
+ "180": "v120",
+ "190": "v140",
+ "191": "v141",
+ "192": "v142",
+ "193": "v143",
+ }
+ }.get(str(self.settings.compiler), {}).get(str(self.settings.compiler.version))
+ if not platform_toolset:
+ raise ConanException(
+ f"Unkown platform toolset for {self.settings.compiler} {self.settings.compiler.version}",
+ )
+ replace_in_file(
+ self,
+ vcxproj_file,
+ f"{old_toolset}",
+ f"{platform_toolset}",
+ )
+
def _build_msvc(self):
if Version(self.version) == "5.2.4":
# Relax Windows SDK restriction
@@ -109,14 +143,21 @@ def _build_msvc(self):
if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) >= "15") or \
(self.settings.compiler == "msvc" and Version(self.settings.compiler) >= "191"):
msvc_version = "vs2017"
+ old_toolset = "v141"
else:
msvc_version = "vs2013"
- with chdir(self, os.path.join(self.source_folder, "windows", msvc_version)):
- target = "liblzma_dll" if self.options.shared else "liblzma"
- msbuild = MSBuild(self)
- msbuild.build_type = self._effective_msbuild_type
- msbuild.platform = "Win32" if self.settings.arch == "x86" else msbuild.platform
- msbuild.build("xz_win.sln", targets=[target])
+ old_toolset = "v120"
+ build_script_folder = os.path.join(self.source_folder, "windows", msvc_version)
+
+ # TODO: replace by some conan helper function (https://github.com/conan-io/conan/issues/12155)?
+ self._fix_msvc_platform_toolset(os.path.join(build_script_folder, "liblzma.vcxproj"), old_toolset)
+ self._fix_msvc_platform_toolset(os.path.join(build_script_folder, "liblzma_dll.vcxproj"), old_toolset)
+
+ target = "liblzma_dll" if self.options.shared else "liblzma"
+ msbuild = MSBuild(self)
+ msbuild.build_type = self._effective_msbuild_type
+ msbuild.platform = "Win32" if self.settings.arch == "x86" else msbuild.platform
+ msbuild.build(os.path.join(build_script_folder, "xz_win.sln"), targets=[target])
def build(self):
if is_msvc(self):
From a868a2e538fc50b788ec7ac25f4775beb84110fc Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 18:02:25 +0200
Subject: [PATCH 06/11] fix install for compiler=msvc
---
recipes/xz_utils/all/conanfile.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 4960f2534163d..7452a9fa09452 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -176,7 +176,11 @@ def package(self):
copy(self, "*.h", src=inc_dir, dst=os.path.join(self.package_folder, "include"), keep_path=True)
arch = {"x86": "Win32", "x86_64": "x64"}.get(str(self.settings.arch))
target = "liblzma_dll" if self.options.shared else "liblzma"
- msvc_version = "vs2017" if Version(self.settings.compiler.version) >= "15" else "vs2013"
+ if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) >= "15") or \
+ (self.settings.compiler == "msvc" and Version(self.settings.compiler) >= "191"):
+ msvc_version = "vs2017"
+ else:
+ msvc_version = "vs2013"
bin_dir = os.path.join(self.source_folder, "windows", msvc_version,
self._effective_msbuild_type, arch, target)
copy(self, "*.lib", src=bin_dir, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
From c52cb536da5efee2ac41d9dcfbbcd02d65eef331 Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Tue, 20 Sep 2022 19:17:12 +0200
Subject: [PATCH 07/11] remove WindowsTargetPlatformVersion in 5.2.4
---
recipes/xz_utils/all/conanfile.py | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 7452a9fa09452..3d00e27e77ec9 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -122,22 +122,12 @@ def _build_msvc(self):
if Version(self.version) == "5.2.4":
# Relax Windows SDK restriction
# Workaround is required only for 5.2.4 because since 5.2.5 WindowsTargetPlatformVersion is dropped from vcproj file
- #
- # emulate VS2019+ meaning of WindowsTargetPlatformVersion == "10.0"
- # undocumented method, but officially recommended workaround by microsoft at at
# https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html
windows_target_platform_version_old = "10.0.15063.0"
- if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) == "15") or \
- (self.settings.compiler == "msvc" and Version(self.settings.compiler) == "191"):
- windows_target_platform_version_new = "$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))"
- else:
- windows_target_platform_version_new = "10.0"
replace_in_file(self, os.path.join(self.source_folder, "windows", "vs2017", "liblzma.vcxproj"),
- windows_target_platform_version_old,
- windows_target_platform_version_new)
+ windows_target_platform_version_old, "")
replace_in_file(self, os.path.join(self.source_folder, "windows", "vs2017", "liblzma_dll.vcxproj"),
- windows_target_platform_version_old,
- windows_target_platform_version_new)
+ windows_target_platform_version_old, "")
# windows\INSTALL-MSVC.txt
if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) >= "15") or \
From 83cf0d67f845b5f00e6b54447b38b79a9d01424a Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Wed, 21 Sep 2022 00:47:01 +0200
Subject: [PATCH 08/11] add ugly tricks for MSBuild
---
recipes/xz_utils/all/conanfile.py | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 3d00e27e77ec9..0ca56c86f79ed 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -5,7 +5,7 @@
from conan.tools.files import collect_libs, copy, get, rename, replace_in_file, rm, rmdir, save
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
-from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain, unix_path
+from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, MSBuild, MSBuildToolchain, unix_path
from conan.tools.scm import Version
import os
import textwrap
@@ -42,7 +42,11 @@ def _settings_build(self):
@property
def _effective_msbuild_type(self):
# treat "RelWithDebInfo" and "MinSizeRel" as "Release"
- return "Debug" if self.settings.build_type == "Debug" else "Release"
+ # there is no DebugMT configuration in upstream vcxproj, we patch Debug configuration afterwards
+ return "{}{}".format(
+ "Debug" if self.settings.build_type == "Debug" else "Release",
+ "MT" if is_msvc_static_runtime(self) and self.settings.build_type != "Debug" else "",
+ )
def config_options(self):
if self.settings.os == "Windows":
@@ -129,6 +133,10 @@ def _build_msvc(self):
replace_in_file(self, os.path.join(self.source_folder, "windows", "vs2017", "liblzma_dll.vcxproj"),
windows_target_platform_version_old, "")
+ # TODO: Find a way to inject conantoolchain.props content from MSBuildToolchain
+ # For the moment all the logic below is a big trick & doesn't honor custom cflags, cxxflags & ldflags from profile
+ # and arch different than x86 & x86_64
+
# windows\INSTALL-MSVC.txt
if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler) >= "15") or \
(self.settings.compiler == "msvc" and Version(self.settings.compiler) >= "191"):
@@ -140,8 +148,15 @@ def _build_msvc(self):
build_script_folder = os.path.join(self.source_folder, "windows", msvc_version)
# TODO: replace by some conan helper function (https://github.com/conan-io/conan/issues/12155)?
- self._fix_msvc_platform_toolset(os.path.join(build_script_folder, "liblzma.vcxproj"), old_toolset)
- self._fix_msvc_platform_toolset(os.path.join(build_script_folder, "liblzma_dll.vcxproj"), old_toolset)
+ liblzma_vcxproj = os.path.join(build_script_folder, "liblzma.vcxproj")
+ liblzma_dll_vcxproj = os.path.join(build_script_folder, "liblzma_dll.vcxproj")
+ self._fix_msvc_platform_toolset(liblzma_vcxproj, old_toolset)
+ self._fix_msvc_platform_toolset(liblzma_dll_vcxproj, old_toolset)
+
+ # Patch Debug configuration if runtime is MT since there is no DebugMT configuration in upstream vcxproj
+ if self.settings.build_type == "Debug" and is_msvc_static_runtime(self):
+ replace_in_file(self, liblzma_vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug")
+ replace_in_file(self, liblzma_dll_vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug")
target = "liblzma_dll" if self.options.shared else "liblzma"
msbuild = MSBuild(self)
From 4a2afde67e5bfb40e10700adc7ecebb623d9850a Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Wed, 21 Sep 2022 21:51:52 +0200
Subject: [PATCH 09/11] test custom CMake variables in conan generator
variables from https://cmake.org/cmake/help/latest/module/FindLibLZMA.html must be defined
LIBLZMA_HAS_AUTO_DECODER, LIBLZMA_HAS_EASY_ENCODER & LIBLZMA_HAS_LZMA_PRESET are not modeled for the moment
---
.../xz_utils/all/test_package/CMakeLists.txt | 19 +++++++++++++++++++
.../all/test_v1_package/CMakeLists.txt | 19 +++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/recipes/xz_utils/all/test_package/CMakeLists.txt b/recipes/xz_utils/all/test_package/CMakeLists.txt
index e2148d8333786..199c9d43f4f9d 100644
--- a/recipes/xz_utils/all/test_package/CMakeLists.txt
+++ b/recipes/xz_utils/all/test_package/CMakeLists.txt
@@ -5,3 +5,22 @@ find_package(LibLZMA REQUIRED)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE LibLZMA::LibLZMA)
+
+# Test whether variables from https://cmake.org/cmake/help/latest/module/FindLibLZMA.html
+# are properly defined in conan generators
+set(_custom_vars
+ LIBLZMA_FOUND
+ LibLZMA_INCLUDE_DIRS
+ LIBLZMA_LIBRARIES
+ LIBLZMA_VERSION_MAJOR
+ LIBLZMA_VERSION_MINOR
+ LIBLZMA_VERSION_PATCH
+ LIBLZMA_VERSION_STRING
+)
+foreach(_custom_var ${_custom_vars})
+ if(DEFINED _custom_var)
+ message(STATUS "${_custom_var}: ${${_custom_var}}")
+ else()
+ message(FATAL_ERROR "${_custom_var} not defined")
+ endif()
+endforeach()
diff --git a/recipes/xz_utils/all/test_v1_package/CMakeLists.txt b/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
index b56517fa8b604..6a00468605540 100644
--- a/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
+++ b/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
@@ -8,3 +8,22 @@ find_package(LibLZMA REQUIRED)
add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE LibLZMA::LibLZMA)
+
+# Test whether variables from https://cmake.org/cmake/help/latest/module/FindLibLZMA.html
+# are properly defined in conan generators
+set(_custom_vars
+ LIBLZMA_FOUND
+ LibLZMA_INCLUDE_DIRS
+ LIBLZMA_LIBRARIES
+ LIBLZMA_VERSION_MAJOR
+ LIBLZMA_VERSION_MINOR
+ LIBLZMA_VERSION_PATCH
+ LIBLZMA_VERSION_STRING
+)
+foreach(_custom_var ${_custom_vars})
+ if(DEFINED _custom_var)
+ message(STATUS "${_custom_var}: ${${_custom_var}}")
+ else()
+ message(FATAL_ERROR "${_custom_var} not defined")
+ endif()
+endforeach()
From 1f811f4b28f9beccedcea27f5fc43fdca44271b8 Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Wed, 21 Sep 2022 21:54:34 +0200
Subject: [PATCH 10/11] typo
---
recipes/xz_utils/all/test_package/CMakeLists.txt | 2 +-
recipes/xz_utils/all/test_v1_package/CMakeLists.txt | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/recipes/xz_utils/all/test_package/CMakeLists.txt b/recipes/xz_utils/all/test_package/CMakeLists.txt
index 199c9d43f4f9d..72a4496088dd7 100644
--- a/recipes/xz_utils/all/test_package/CMakeLists.txt
+++ b/recipes/xz_utils/all/test_package/CMakeLists.txt
@@ -10,7 +10,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE LibLZMA::LibLZMA)
# are properly defined in conan generators
set(_custom_vars
LIBLZMA_FOUND
- LibLZMA_INCLUDE_DIRS
+ LIBLZMA_INCLUDE_DIRS
LIBLZMA_LIBRARIES
LIBLZMA_VERSION_MAJOR
LIBLZMA_VERSION_MINOR
diff --git a/recipes/xz_utils/all/test_v1_package/CMakeLists.txt b/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
index 6a00468605540..971f2caf78d9a 100644
--- a/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
+++ b/recipes/xz_utils/all/test_v1_package/CMakeLists.txt
@@ -13,7 +13,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE LibLZMA::LibLZMA)
# are properly defined in conan generators
set(_custom_vars
LIBLZMA_FOUND
- LibLZMA_INCLUDE_DIRS
+ LIBLZMA_INCLUDE_DIRS
LIBLZMA_LIBRARIES
LIBLZMA_VERSION_MAJOR
LIBLZMA_VERSION_MINOR
From 45b063657d14323c8a87dcf0cdca5b91f403bb3d Mon Sep 17 00:00:00 2001
From: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
Date: Sun, 25 Sep 2022 09:35:34 +0200
Subject: [PATCH 11/11] set win_bash in build_requirements
---
recipes/xz_utils/all/conanfile.py | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/recipes/xz_utils/all/conanfile.py b/recipes/xz_utils/all/conanfile.py
index 0ca56c86f79ed..6c9f443898926 100644
--- a/recipes/xz_utils/all/conanfile.py
+++ b/recipes/xz_utils/all/conanfile.py
@@ -68,9 +68,10 @@ def layout(self):
basic_layout(self, src_folder="src")
def build_requirements(self):
- if self._settings_build.os == "Windows" and not is_msvc(self) and \
- not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool):
- self.tool_requires("msys2/cci.latest")
+ if self._settings_build.os == "Windows" and not is_msvc(self):
+ if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool):
+ self.tool_requires("msys2/cci.latest")
+ self.win_bash = True
def source(self):
get(self, **self.conan_data["sources"][self.version],
@@ -169,10 +170,8 @@ def build(self):
self._build_msvc()
else:
autotools = Autotools(self)
- self.win_bash = True
autotools.configure()
autotools.make()
- self.win_bash = None
def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
@@ -195,10 +194,8 @@ def package(self):
os.path.join(self.package_folder, "lib", "lzma.lib"))
else:
autotools = Autotools(self)
- self.win_bash = True
# TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed
autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
- self.win_bash = None
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))