diff --git a/recipes/cityhash/all/conanfile.py b/recipes/cityhash/all/conanfile.py index 35e373369c7eb..2459b5205cee1 100644 --- a/recipes/cityhash/all/conanfile.py +++ b/recipes/cityhash/all/conanfile.py @@ -1,10 +1,15 @@ -from conans import ConanFile, AutoToolsBuildEnvironment, tools -from conans.errors import ConanInvalidConfiguration -from contextlib import contextmanager -import functools +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.apple import fix_apple_shared_install_name +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import copy, get, rm, rmdir +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc, unix_path +from conan.tools.scm import Version import os -required_conan_version = ">=1.33.0" +required_conan_version = ">=1.54.0" class CityhashConan(ConanFile): @@ -25,14 +30,6 @@ class CityhashConan(ConanFile): "fPIC": True, } - @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) @@ -47,69 +44,63 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + basic_layout(self, src_folder="src") def validate(self): - if self._is_msvc and self.options.shared: + if is_msvc(self) and self.options.shared: raise ConanInvalidConfiguration("cityhash does not support shared builds with Visual Studio") def build_requirements(self): - self.build_requires("libtool/2.4.6") - if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): - self.build_requires("msys2/cci.latest") + self.tool_requires("libtool/2.4.7") + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) - - @contextmanager - def _build_context(self): - if self._is_msvc: - with tools.vcvars(self): - env = { - "CC": "cl -nologo", - "CXX": "cl -nologo", - "LD": "link -nologo", - "AR": "{} lib".format(tools.unix_path(self._user_info_build["automake"].ar_lib)), - } - with tools.environment_append(env): - yield - else: - yield - - @functools.lru_cache(1) - def _configure_autotools(self): - autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - autotools.libs = [] - yes_no = lambda v: "yes" if v else "no" - args = [ - "--enable-static={}".format(yes_no(not self.options.shared)), - "--enable-shared={}".format(yes_no(self.options.shared)), - ] - if self._is_msvc: - autotools.cxx_flags.append("-EHsc") - if not (self.settings.compiler == "Visual Studio" and \ - tools.Version(self.settings.compiler.version) < "12"): - autotools.flags.append("-FS") - autotools.configure(configure_dir=self._source_subfolder, args=args) - return autotools + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + + tc = AutotoolsToolchain(self) + if is_msvc(self): + tc.extra_cxxflags.append("-EHsc") + if (str(self.settings.compiler) == "Visual Studio" and Version(self.settings.compiler.version) >= "12") or \ + (str(self.settings.compiler) == "msvc" and Version(self.settings.compiler.version) >= "180"): + tc.extra_cflags.append("-FS") + tc.extra_cxxflags.append("-FS") + env = tc.environment() + if is_msvc(self): + ar_wrapper = unix_path(self, self._user_info_build["automake"].ar_lib) + env.define("CC", "cl -nologo") + env.define("CXX", "cl -nologo") + env.define("LD", "link -nologo") + env.define("AR", f"{ar_wrapper} lib") + env.define("NM", "dumpbin -symbols") + env.define("OBJDUMP", ":") + env.define("RANLIB", ":") + env.define("STRIP", ":") + tc.generate(env) def build(self): - with tools.chdir(self._source_subfolder): - self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows) - # relocatable shared lib on macOS - tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name @rpath/") - with self._build_context(): - autotools = self._configure_autotools() - autotools.make() + autotools = Autotools(self) + autotools.autoreconf() + autotools.configure() + autotools.make() def package(self): - self.copy("COPYING", dst="licenses", src=self._source_subfolder) - with self._build_context(): - autotools = self._configure_autotools() - autotools.install() - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") - tools.rmdir(os.path.join(self.package_folder, "share")) + copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + autotools = Autotools(self) + autotools.install() + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "share")) + fix_apple_shared_install_name(self) def package_info(self): self.cpp_info.libs = ["cityhash"] diff --git a/recipes/cityhash/all/test_package/CMakeLists.txt b/recipes/cityhash/all/test_package/CMakeLists.txt index 895a4298a7cae..9fbe304115d9e 100644 --- a/recipes/cityhash/all/test_package/CMakeLists.txt +++ b/recipes/cityhash/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +project(test_package LANGUAGES CXX) find_package(cityhash REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} cityhash::cityhash) +target_link_libraries(${PROJECT_NAME} PRIVATE cityhash::cityhash) diff --git a/recipes/cityhash/all/test_package/conanfile.py b/recipes/cityhash/all/test_package/conanfile.py index 38f4483872d47..0a6bc68712d90 100644 --- a/recipes/cityhash/all/test_package/conanfile.py +++ b/recipes/cityhash/all/test_package/conanfile.py @@ -1,10 +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", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + 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) @@ -12,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/cityhash/all/test_v1_package/CMakeLists.txt b/recipes/cityhash/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/cityhash/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/cityhash/all/test_v1_package/conanfile.py b/recipes/cityhash/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/cityhash/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_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)