Skip to content
Merged
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
32 changes: 4 additions & 28 deletions recipes/yaml-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rmdir, save
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rmdir
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os
import textwrap

required_conan_version = ">=1.53.0"
required_conan_version = ">=2.1"


class YamlCppConan(ConanFile):
Expand Down Expand Up @@ -61,6 +60,8 @@ def generate(self):
tc.variables["YAML_CPP_BUILD_TOOLS"] = False
tc.variables["YAML_CPP_INSTALL"] = True
tc.variables["YAML_BUILD_SHARED_LIBS"] = self.options.shared
if Version(self.version) <= "0.8.0": # pylint: disable=conan-condition-evals-to-constant
tc.cache_variables["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5" # CMake 4 support
if is_msvc(self):
tc.variables["YAML_MSVC_SHARED_RT"] = not is_msvc_static_runtime(self)
tc.preprocessor_definitions["_NOEXCEPT"] = "noexcept"
Expand All @@ -81,27 +82,6 @@ def package(self):
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"yaml-cpp": "yaml-cpp::yaml-cpp"}
)

def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""")
save(self, module_file, content)

@property
def _module_file_rel_path(self):
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", "yaml-cpp")
self.cpp_info.set_property("cmake_target_name", "yaml-cpp::yaml-cpp")
Expand All @@ -118,7 +98,3 @@ def package_info(self):
else:
if not self.options.shared:
self.cpp_info.defines.append("YAML_CPP_STATIC_DEFINE")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
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]