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

msgpack-cxx: add version 5.0.0, support conan v2 #15237

Merged
merged 2 commits into from
Jan 27, 2023
Merged
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
3 changes: 3 additions & 0 deletions recipes/msgpack-cxx/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"5.0.0":
url: "https://github.com/msgpack/msgpack-c/archive/cpp-5.0.0.tar.gz"
sha256: "bd6b8e255f0a62cf8f50f1d292f979ac8ea9a4aa121938679d6f419d6df70ea3"
"4.1.3":
url: "https://github.com/msgpack/msgpack-c/archive/cpp-4.1.3.tar.gz"
sha256: "fd0a685656f11b8aa09ed33bcbdcad3105d25d0034ca3dba9fe957623a42d253"
Expand Down
80 changes: 43 additions & 37 deletions recipes/msgpack-cxx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.files import get, copy, save
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os
import textwrap

required_conan_version = ">=1.43.0"

required_conan_version = ">=1.53.0"

class MsgpackCXXConan(ConanFile):
name = "msgpack-cxx"
description = "The official C++ library for MessagePack"
license = "BSL-1.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/msgpack/msgpack-c"
topics = ("msgpack", "message-pack", "serialization")
license = "BSL-1.0"
no_copy_source = True

settings = "os", "compiler", "build_type", "arch"
topics = ("msgpack", "message-pack", "serialization", "header-only")
settings = "os", "arch", "compiler", "build_type"
options = {
"use_boost": [True, False],
}
default_options = {
"use_boost": True
"use_boost": True,
}


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

@property
def _build_subfolder(self):
return "build_subfolder"
no_copy_source = True

def configure_options(self):
# No boost was added in 4.1.0
if tools.Version(self.version) < "4.1.0":
# No boost was added since 4.1.0
if Version(self.version) < "4.1.0":
del self.options.use_boost

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
if self.options.get_safe("use_boost", True):
self.requires("boost/1.78.0")
self.requires("boost/1.81.0")

def package_id(self):
self.info.header_only()
self.info.clear()

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

def package(self):
self.copy("LICENSE_1_0.txt", dst="licenses", src=self._source_subfolder)
self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
self.copy("*.hpp", dst="include", src=os.path.join(self._source_subfolder, "include"))
copy(self, pattern="LICENSE_1_0.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)
copy(
self,
pattern="*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"msgpackc-cxx": "msgpackc-cxx::msgpackc-cxx"}
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
Expand All @@ -67,28 +69,32 @@ def _create_cmake_module_alias_targets(module_file, targets):
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)
save(self, module_file, content)

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file_rel_path(self):
return os.path.join(self._module_subfolder,
"conan-official-{}-targets.cmake".format(self.name))
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "msgpack")
self.cpp_info.set_property("cmake_target_name", "msgpackc-cxx")

self.cpp_info.libdirs = []
self.cpp_info.bindirs = []

if Version(self.version) >= "4.1.0" and not self.options.use_boost:
self.cpp_info.defines.append("MSGPACK_NO_BOOST")
else:
self.cpp_info.requires.append("boost::headers")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "msgpack"
self.cpp_info.filenames["cmake_find_package_multi"] = "msgpack"
self.cpp_info.names["cmake_find_package"] = "msgpackc-cxx"
self.cpp_info.names["cmake_find_package_multi"] = "msgpackc-cxx"
self.cpp_info.builddirs.append(self._module_subfolder)
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]

if tools.Version(self.version) >= "4.1.0" and not self.options.use_boost:
self.cpp_info.defines.append("MSGPACK_NO_BOOST")
9 changes: 3 additions & 6 deletions recipes/msgpack-cxx/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(msgpack REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} msgpackc-cxx)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
21 changes: 15 additions & 6 deletions recipes/msgpack-cxx/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

def layout(self):
cmake_layout(self)

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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_cpp_path = os.path.join("bin", "test_package")
self.run(bin_cpp_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/msgpack-cxx/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
18 changes: 18 additions & 0 deletions recipes/msgpack-cxx/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 2 additions & 0 deletions recipes/msgpack-cxx/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"5.0.0":
folder: all
"4.1.3":
folder: all
"4.1.2":
Expand Down