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 with new cmake toolchain #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 0 additions & 7 deletions recipes/fmt/all/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions recipes/fmt/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ 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"
"6.1.0":
- patch_file: "patches/fix-mingw-msvc2015-export-assert-fail-6.1.0.patch"
base_path: "source_subfolder"
78 changes: 39 additions & 39 deletions recipes/fmt/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.layout import cmake_layout

required_conan_version = ">=1.33.0"


class FmtConan(ConanFile):
name = "fmt"
homepage = "https://github.com/fmtlib/fmt"
description = "A safe and fast alternative to printf and IOStreams."
topics = ("conan", "fmt", "format", "iostream", "printf")
url = "https://github.com/conan-io/conan-center-index"
topics = ("fmt", "format", "iostream", "printf")
url = "https://github.com/conan-io/conan-center-index/"
license = "MIT"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
exports_sources = ["patches/**"]
settings = "os", "compiler", "build_type", "arch"
options = {
"header_only": [True, False],
Expand All @@ -30,16 +32,6 @@ class FmtConan(ConanFile):
"with_os_api": True,
}

_cmake = None

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

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

@property
def _has_with_os_api_option(self):
return tools.Version(self.version) >= "7.0.0"
Expand Down Expand Up @@ -71,44 +63,52 @@ 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"
tools.get(**self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def layout(self):
cmake_layout(self)

def generate(self):
cmake_toolchain = CMakeToolchain(self)

cmake_toolchain.variables["FMT_DOC"] = False
cmake_toolchain.variables["FMT_TEST"] = False
cmake_toolchain.variables["FMT_INSTALL"] = True
cmake_toolchain.variables["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
cmake_toolchain.variables["FMT_OS"] = self.options.with_os_api

cmake_toolchain.generate()

def _patch_sources(self):
with tools.chdir(self.folders.base_source):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch, base_path=self.source_folder)

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
self._patch_sources()

if not self.options.header_only:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE.rst", dst="licenses", src=self._source_subfolder)
self.copy("LICENSE.rst", dst="licenses")
if self.options.header_only:
self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
self.copy("*.h", dst="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"))

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"
self.cpp_info.set_property("cmake_find_package", "fmt")
self.cpp_info.set_property("cmake_find_package_multi", "fmt")
self.cpp_info.set_property("pkg_config", "fmt")
if self.options.header_only:
self.cpp_info.components["fmt-header-only"].defines.append("FMT_HEADER_ONLY=1")
if self.options.with_fmt_alias:
Expand Down
19 changes: 14 additions & 5 deletions recipes/fmt/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import os
from conans import ConanFile, CMake, tools

from conans import ConanFile, tools
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.layout import cmake_layout


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake_find_package", "cmake"
generators = "CMakeDeps", "CMakeToolchain", "PkgConfigDeps", "VirtualRunEnv"

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.settings):
self.run(os.path.join("bin","test_package"), run_environment=True)
self.run(os.path.join("bin","test_ranges"), run_environment=True)
# FIXME: Very ugly interface to get the current test executable path
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(cmd, env=["conanrunenv"])

cmd = os.path.join(self.cpp.build.bindirs[0], "test_ranges")
self.run(cmd, env=["conanrunenv"])
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1.2)
project(test_package CXX)

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

find_package(fmt REQUIRED)

# TEST_PACKAGE #################################################################
Expand Down