Skip to content

Commit

Permalink
fmt for 2.0 (#13)
Browse files Browse the repository at this point in the history
* add fmt for 2.0

* safe rm

* remove names

* add definition

* fix

* names back

* remove export_sources

* add exports_sources
  • Loading branch information
czoido committed Mar 15, 2022
1 parent 2525ea2 commit 5708ca4
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 189 deletions.
7 changes: 0 additions & 7 deletions recipes/fmt/all/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion recipes/fmt/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ sources:
patches:
"5.3.0":
- patch_file: "patches/fix-install-5.3.0.patch"
base_path: "source_subfolder"
# "6.0.0":
# - patch_file: "patches/fix-install-6.0.0.patch"
# base_path: "source_subfolder"
Expand Down
104 changes: 50 additions & 54 deletions recipes/fmt/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import shutil

from conan import ConanFile
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, apply_conandata_patches
from conan.tools.microsoft.visual import is_msvc, msvc_runtime_flag
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.43.0"

Expand All @@ -13,6 +18,7 @@ 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 = {
Expand All @@ -30,29 +36,23 @@ class FmtConan(ConanFile):
"with_os_api": True,
}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

@property
def _has_with_os_api_option(self):
return tools.Version(self.version) >= "7.0.0"
return Version(str(self.version)) >= "7.0.0"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
def generate(self):
if not self.options.header_only:
tc = CMakeToolchain(self)
tc.variables["FMT_DOC"] = False
tc.variables["FMT_TEST"] = False
tc.variables["FMT_INSTALL"] = True
tc.variables["FMT_LIB_DIR"] = "lib"
if self._has_with_os_api_option:
tc.variables["FMT_OS"] = self.options.with_os_api
tc.generate()

def layout(self):
cmake_layout(self)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -63,15 +63,18 @@ def config_options(self):
self.options.with_os_api = False

def configure(self):
if self.options.header_only:
del self.options.fPIC
del self.options.shared
del self.options.with_os_api
elif self.options.shared:
del self.options.fPIC
try:
if self.options.header_only:
del self.options.fPIC
del self.options.shared
del self.options.with_os_api
elif self.options.shared:
del self.options.fPIC
except Exception:
pass

def validate(self):
if self.options.get_safe("shared") and self._is_msvc and "MT" in msvc_runtime_flag(self):
if self.options.get_safe("shared") and is_msvc(self) and "MT" in msvc_runtime_flag(self):
raise ConanInvalidConfiguration(
"Visual Studio build for shared library with MT runtime is not supported"
)
Expand All @@ -83,39 +86,32 @@ def package_id(self):
del self.info.options.with_fmt_alias

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["FMT_DOC"] = False
self._cmake.definitions["FMT_TEST"] = False
self._cmake.definitions["FMT_INSTALL"] = True
self._cmake.definitions["FMT_LIB_DIR"] = "lib"
if self._has_with_os_api_option:
self._cmake.definitions["FMT_OS"] = self.options.with_os_api
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
get(self, **self.conan_data["sources"][str(self.version)], destination=self.source_folder, strip_root=True)

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
if not self.options.header_only:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

@staticmethod
def _rm_folder(folder):
try:
shutil.rmtree(folder)
except Exception:
pass

def package(self):
self.copy("LICENSE.rst", dst="licenses", src=self._source_subfolder)
copy(self, "LICENSE.rst", self.source_folder, os.path.join(self.package_folder, "licenses"))
if self.options.header_only:
self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
copy(self, "*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
else:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
self._rm_folder(os.path.join(self.package_folder, "lib", "cmake"))
self._rm_folder(os.path.join(self.package_folder, "lib", "pkgconfig"))
self._rm_folder(os.path.join(self.package_folder, "res"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "fmt"
Expand Down
22 changes: 0 additions & 22 deletions recipes/fmt/all/test_cmakedeps/CMakeLists.txt

This file was deleted.

29 changes: 0 additions & 29 deletions recipes/fmt/all/test_cmakedeps/conanfile.py

This file was deleted.

55 changes: 0 additions & 55 deletions recipes/fmt/all/test_cmakedeps/test_package.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions recipes/fmt/all/test_cmakedeps/test_ranges.cpp

This file was deleted.

3 changes: 0 additions & 3 deletions recipes/fmt/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(fmt REQUIRED CONFIG)

# TEST_PACKAGE #################################################################
Expand Down
28 changes: 21 additions & 7 deletions recipes/fmt/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
from conans import ConanFile, CMake, tools
import os
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.build import cross_building as tools_cross_building
from conan.tools.layout import cmake_layout

required_conan_version = ">=1.43.0"

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps"

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["FMT_HEADER_ONLY"] = self.dependencies["fmt"].options.header_only
tc.generate()

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.definitions["FMT_HEADER_ONLY"] = self.options["fmt"].header_only
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
self.run(os.path.join("bin", "test_package"), run_environment=True)
self.run(os.path.join("bin", "test_ranges"), run_environment=True)
if not tools_cross_building(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"))
self.run(os.path.join(self.cpp.build.bindirs[0], "test_ranges"))

0 comments on commit 5708ca4

Please sign in to comment.