Skip to content

Commit

Permalink
(#12847) fmt: conan v2 modernize
Browse files Browse the repository at this point in the history
* fmt: conan v2 modernize

* Update conanfile.py

* Update conanfile.py

* Update recipes/fmt/all/conanfile.py

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* Code review

* Code review

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
  • Loading branch information
Chris Mc and SpaceIm authored Sep 15, 2022
1 parent 5d82e07 commit 328bff8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
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"


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}")
1 change: 1 addition & 0 deletions recipes/fmt/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)
Expand Down

0 comments on commit 328bff8

Please sign in to comment.