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: relocatable shared lib on macOS + don't fail if baremetal not in settings.yml + modernize #9098

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions recipes/fmt/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

add_subdirectory("source_subfolder")
25 changes: 18 additions & 7 deletions recipes/fmt/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
Expand All @@ -12,9 +13,8 @@ class FmtConan(ConanFile):
topics = ("conan", "fmt", "format", "iostream", "printf")
url = "https://github.com/conan-io/conan-center-index"
license = "MIT"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"

settings = "os", "arch", "compiler", "build_type"
options = {
"header_only": [True, False],
"shared": [True, False],
Expand All @@ -30,6 +30,7 @@ class FmtConan(ConanFile):
"with_os_api": True,
}

generators = "cmake"
_cmake = None

@property
Expand All @@ -40,16 +41,25 @@ def _source_subfolder(self):
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"

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 config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if not self._has_with_os_api_option:
del self.options.with_os_api
elif self.settings.os == "baremetal":
elif str(self.settings.os) == "baremetal":
self.options.with_os_api = False

def configure(self):
Expand All @@ -61,9 +71,10 @@ def configure(self):
del self.options.fPIC

def validate(self):
if self.options.get_safe("shared") and self.settings.compiler == "Visual Studio" and \
"MT" in self.settings.compiler.runtime:
raise ConanInvalidConfiguration("Visual Studio build for shared library with MT runtime is not supported")
if self.options.get_safe("shared") and self._is_msvc and "MT" in msvc_runtime_flag(self):
raise ConanInvalidConfiguration(
"Visual Studio build for shared library with MT runtime is not supported"
)

def package_id(self):
if self.options.header_only:
Expand Down
4 changes: 2 additions & 2 deletions recipes/fmt/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.1.2)
project(test_package CXX)

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

find_package(fmt REQUIRED)
find_package(fmt REQUIRED CONFIG)

# TEST_PACKAGE #################################################################
add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
Expand Down
12 changes: 6 additions & 6 deletions recipes/fmt/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from conans import ConanFile, CMake, tools
import os


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

def build(self):
cmake = CMake(self)
Expand All @@ -13,6 +13,6 @@ def build(self):
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)
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)