-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
libdeflate: conan v2 support #13759
libdeflate: conan v2 support #13759
Changes from 8 commits
2684107
435abaa
3bbfdfd
55331ad
6aef099
b818a05
9e722ef
27d82f5
b270ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from conan import ConanFile | ||
from conan.tools.microsoft import is_msvc | ||
from conan.tools.microsoft import is_msvc, VCVars, unix_path | ||
from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, chdir, rmdir, copy, rm | ||
from conan.tools.env import Environment | ||
from conans import MSBuild, AutoToolsBuildEnvironment, VisualStudioBuildEnvironment | ||
from conans.tools import vcvars, environment_append | ||
from conan.tools.env import VirtualBuildEnv | ||
from conan.tools.layout import basic_layout | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain | ||
import os | ||
|
||
required_conan_version = ">=1.52.0" | ||
|
@@ -26,10 +26,6 @@ class LibdeflateConan(ConanFile): | |
"fPIC": True, | ||
} | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _is_clangcl(self): | ||
return self.settings.compiler == "clang" and self.settings.os == "Windows" | ||
|
@@ -60,51 +56,67 @@ def configure(self): | |
except Exception: | ||
pass | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def build_requirements(self): | ||
if self._settings_build.os == "Windows" and not is_msvc(self): | ||
if "CONAN_BASH_PATH" not in Environment().vars(self, scope="build").keys(): | ||
self.win_bash = True | ||
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str): | ||
self.tool_requires("msys2/cci.latest") | ||
|
||
def source(self): | ||
get(self, **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 generate(self): | ||
env = VirtualBuildEnv(self) | ||
env.generate() | ||
|
||
if is_msvc(self) or self._is_clangcl: | ||
vc = VCVars(self) | ||
vc.generate() | ||
else: | ||
tc = AutotoolsToolchain(self) | ||
tc.generate() | ||
|
||
def _build_msvc(self): | ||
with chdir(self, self._source_subfolder): | ||
with vcvars(self), environment_append(VisualStudioBuildEnvironment(self).vars): | ||
target = "libdeflate.dll" if self.options.shared else "libdeflatestatic.lib" | ||
self.run("nmake /f Makefile.msc {}".format(target)) | ||
def _build_nmake(self): | ||
with chdir(self, self.source_folder): | ||
target = "libdeflate.dll" if self.options.shared else "libdeflatestatic.lib" | ||
self.run(f"nmake /f Makefile.msc {target}") | ||
|
||
def _build_make(self): | ||
autotools = AutoToolsBuildEnvironment(self, win_bash=(self._settings_build.os == "Windows")) | ||
with chdir(self, self._source_subfolder): | ||
autotools = Autotools(self) | ||
with chdir(self, self.source_folder): | ||
autotools.make() | ||
|
||
def build(self): | ||
apply_conandata_patches(self) | ||
if is_msvc(self) or self._is_clangcl: | ||
self._build_msvc() | ||
self._build_nmake() | ||
else: | ||
self._build_make() | ||
|
||
def _package_windows(self): | ||
self.copy("libdeflate.h", dst="include", src=self._source_subfolder) | ||
copy(self, "libdeflate.h", dst=os.path.join(self.package_folder, "include"), src=self.source_folder) | ||
if self.options.shared: | ||
self.copy("*deflate.lib", dst="lib", src=self._source_subfolder) | ||
self.copy("*deflate.dll", dst="bin", src=self._source_subfolder) | ||
copy(self, "*deflate.lib", dst=os.path.join(self.package_folder, "lib"), src=self.source_folder) | ||
copy(self, "*deflate.dll", dst=os.path.join(self.package_folder, "bin"), src=self.source_folder) | ||
else: | ||
self.copy("*deflatestatic.lib", dst="lib", src=self._source_subfolder) | ||
copy(self, "*deflatestatic.lib", dst=os.path.join(self.package_folder, "lib"), src=self.source_folder) | ||
|
||
def _package_make(self): | ||
autotools = AutoToolsBuildEnvironment(self, win_bash=(self._settings_build.os == "Windows")) | ||
with chdir(self, self._source_subfolder): | ||
autotools.install(args=["PREFIX={}".format(self.package_folder)]) | ||
autotools = Autotools(self) | ||
with chdir(self, self.source_folder): | ||
# TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed | ||
# Note that PREFIX=/ also appears to be required on Linux. | ||
autotools.install(args=["PREFIX=/", f"DESTDIR={unix_path(self, self.package_folder)}"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jwillikers @uilianries continuing from other comment, I get messages like:
Note it installs to /usr/local/lib and then, and I know autotools adds PREFIX=/ to configure calls, but it didn't seem to be done this time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, this is a Makefile project and not actually Autotools, right? AutotoolsToolchain passes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, dropped and just use PREFIX |
||
rmdir(self, os.path.join(self.package_folder, "bin")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rm(self, "*.a" if self.options.shared else "*.[so|dylib]*", os.path.join(self.package_folder, "lib") ) | ||
|
||
def package(self): | ||
copy(self, "COPYING", | ||
src=os.path.join(self.source_folder, self._source_subfolder), | ||
src=os.path.join(self.source_folder, self.source_folder), | ||
dst=os.path.join(self.package_folder, "licenses" | ||
)) | ||
if self.settings.os == "Windows": | ||
|
@@ -116,6 +128,6 @@ def package_info(self): | |
self.cpp_info.set_property("pkg_config_name", "libdeflate") | ||
prefix = "lib" if self.settings.os == "Windows" else "" | ||
suffix = "static" if self.settings.os == "Windows" and not self.options.shared else "" | ||
self.cpp_info.libs = ["{0}deflate{1}".format(prefix, suffix)] | ||
self.cpp_info.libs = [f"{prefix}deflate{suffix}"] | ||
if self.settings.os == "Windows" and self.options.shared: | ||
self.cpp_info.defines = ["LIBDEFLATE_DLL"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
find_package(libdeflate REQUIRED CONFIG) | ||
|
||
add_executable(test_package test_package.c) | ||
target_link_libraries(test_package PRIVATE libdeflate::libdeflate) | ||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE libdeflate::libdeflate) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "cmake", "cmake_find_package_multi" | ||
generators = "CMakeDeps", "CMakeToolchain", "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) | ||
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") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ | ||
${CMAKE_CURRENT_BINARY_DIR}/test_package/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
VirtualBuildEnv
automatically handle VCVars?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
https://docs.conan.io/en/latest/reference/conanfile/tools/microsoft.html?highlight=vcvars#msbuild
It only handles msbuild stuff. VirtualBuildEnv is more related to environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does building most packages work then, when I'm not in a Visual Studio Developer Command Prompt? I figured they would fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The msbuild helper does that step 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jwillikers one of the reasons I want to upgrade these recipes is so I can build everything in my git-bash-SDK-msys terminal on windows. And so far, the new recipes seem to be doing it well.