diff --git a/recipes/cityhash/all/conandata.yml b/recipes/cityhash/all/conandata.yml new file mode 100644 index 0000000000000..77c6f2317b0e8 --- /dev/null +++ b/recipes/cityhash/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "cci.20130801": + url: "https://github.com/google/cityhash/archive/8af9b8c2b889d80c22d6bc26ba0df1afb79a30db.zip" + sha256: "3524f5ed43143974a29fddeeece29c8b6348f05db08dd180452da01a2837ddce" diff --git a/recipes/cityhash/all/conanfile.py b/recipes/cityhash/all/conanfile.py new file mode 100644 index 0000000000000..65c01cf4ae22b --- /dev/null +++ b/recipes/cityhash/all/conanfile.py @@ -0,0 +1,101 @@ +from conans import ConanFile, AutoToolsBuildEnvironment, tools +from conans.errors import ConanInvalidConfiguration +from contextlib import contextmanager +import os + +required_conan_version = ">=1.33.0" + + +class CityhashConan(ConanFile): + name = "cityhash" + description = "CityHash, a family of hash functions for strings." + license = "MIT" + topics = ("conan", "cityhash", "hash") + homepage = "https://github.com/google/cityhash" + url = "https://github.com/conan-io/conan-center-index" + + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + _autotools = None + + @property + def _source_subfolder(self): + return "source_subfolder" + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + del self.options.fPIC + + def validate(self): + if self.settings.compiler == "Visual Studio" 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 tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH"): + self.build_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.settings.compiler == "Visual Studio": + with tools.vcvars(self.settings): + env = { + "CC": "cl -nologo", + "CXX": "cl -nologo", + "LD": "link -nologo", + "AR": "{} lib".format(tools.unix_path(self.deps_user_info["automake"].ar_lib)), + } + with tools.environment_append(env): + yield + else: + yield + + def _configure_autotools(self): + if self._autotools: + return self._autotools + self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) + self._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.settings.compiler == "Visual Studio": + self._autotools.cxx_flags.append("-EHsc") + self._autotools.flags.append("-FS") + self._autotools.configure(configure_dir=self._source_subfolder, args=args) + return self._autotools + + def build(self): + with tools.chdir(self._source_subfolder): + self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows) + with self._build_context(): + autotools = self._configure_autotools() + 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")) + + 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 new file mode 100644 index 0000000000000..196188113685c --- /dev/null +++ b/recipes/cityhash/all/test_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() + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/cityhash/all/test_package/conanfile.py b/recipes/cityhash/all/test_package/conanfile.py new file mode 100644 index 0000000000000..5216332f39f5c --- /dev/null +++ b/recipes/cityhash/all/test_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" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/cityhash/all/test_package/test_package.cpp b/recipes/cityhash/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..158134bbe3214 --- /dev/null +++ b/recipes/cityhash/all/test_package/test_package.cpp @@ -0,0 +1,8 @@ +#include + +#include + +int main() { + std::cout << CityHash64("conan-center-index", 18) << std::endl; + return 0; +} diff --git a/recipes/cityhash/config.yml b/recipes/cityhash/config.yml new file mode 100644 index 0000000000000..489bded5765de --- /dev/null +++ b/recipes/cityhash/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20130801": + folder: all