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

fmt: conan v2 modernize #12847

Merged
merged 6 commits into from
Sep 15, 2022
Merged
Changes from 5 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
39 changes: 17 additions & 22 deletions recipes/fmt/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, apply_conandata_patches, copy, rmdir


required_conan_version = ">=1.50.0"
required_conan_version = ">=1.51.3"
prince-chrismc marked this conversation as resolved.
Show resolved Hide resolved


class FmtConan(ConanFile):
Expand All @@ -16,8 +15,6 @@ class FmtConan(ConanFile):
topics = ("fmt", "format", "iostream", "printf")
url = "https://github.com/conan-io/conan-center-index"
license = "MIT"
exports_sources = "patches/*"

settings = "os", "arch", "compiler", "build_type"
options = {
"header_only": [True, False],
Expand All @@ -38,6 +35,10 @@ class FmtConan(ConanFile):
def _has_with_os_api_option(self):
return Version(str(self.version)) >= "7.0.0"

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, patch["patch_file"], src=self.recipe_folder, dst=self.export_sources_folder)

def generate(self):
if not self.options.header_only:
tc = CMakeToolchain(self)
Expand Down Expand Up @@ -75,7 +76,8 @@ def package_id(self):
del self.info.options.with_fmt_alias

def source(self):
get(self, **self.conan_data["sources"][str(self.version)], strip_root=True)
get(self, **self.conan_data["sources"][str(self.version)],
destination=self.source_folder, strip_root=True)

def build(self):
apply_conandata_patches(self)
Expand All @@ -97,37 +99,30 @@ def package(self):
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "fmt"
self.cpp_info.names["cmake_find_package_multi"] = "fmt"
self.cpp_info.names["pkg_config"] = "fmt"

target = "fmt-header-only" if self.options.header_only else "fmt"
self.cpp_info.set_property("cmake_target_name", "fmt::{}".format(target))
self.cpp_info.set_property("cmake_file_name", "fmt")
self.cpp_info.set_property("cmake_target_name", f"fmt::{target}")
self.cpp_info.set_property("pkg_config_name", "fmt")

# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["_fmt"].includedirs.extend(["include"])
if self.options.with_fmt_alias:
self.cpp_info.components["_fmt"].defines.append("FMT_STRING_ALIAS=1")

if self.options.header_only:
self.cpp_info.components["_fmt"].defines.append("FMT_HEADER_ONLY=1")
if self.options.with_fmt_alias:
self.cpp_info.components["_fmt"].defines.append("FMT_STRING_ALIAS=1")
else:
postfix = "d" if self.settings.build_type == "Debug" else ""
libname = "fmt" + postfix
self.cpp_info.components["_fmt"].libs = [libname]
if self.settings.os == "Linux":
self.cpp_info.components["_fmt"].system_libs.extend(["m"])
# FIXME: remove when Conan 1.50 is used in c3i and update the Conan required version
# from that version components don't have empty libdirs by default
self.cpp_info.components["_fmt"].libdirs.extend(["lib"])
self.cpp_info.components["_fmt"].bindirs.extend(["bin"])
if self.options.with_fmt_alias:
self.cpp_info.components["_fmt"].defines.append("FMT_STRING_ALIAS=1")
if self.options.shared:
self.cpp_info.components["_fmt"].defines.append("FMT_SHARED")

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "fmt"
self.cpp_info.names["cmake_find_package_multi"] = "fmt"
self.cpp_info.names["pkg_config"] = "fmt"
self.cpp_info.components["_fmt"].names["cmake_find_package"] = target
self.cpp_info.components["_fmt"].names["cmake_find_package_multi"] = target
self.cpp_info.components["_fmt"].set_property("cmake_target_name", "fmt::{}".format(target))
# FIXME: Remove as soon as Conan client provide a hotfix. See conan-io/conan-center-index#12149
self.cpp_info.components["_fmt"].builddirs = [""]
self.cpp_info.components["_fmt"].set_property("cmake_target_name", f"fmt::{target}")