From f3e554f4e35d4c406536f8bd291cf0b90e20fe71 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Mon, 22 Aug 2022 06:58:24 -0500 Subject: [PATCH] (#12413) nlohmann_json: Add support for Conan V2 * nlohmann_json: Add support for Conan V2 * Fix cross_building call in test package * Use src directory for source folder in layout --- recipes/nlohmann_json/all/conanfile.py | 29 +++++++++++-------- .../all/test_package/CMakeLists.txt | 5 +--- .../all/test_package/conanfile.py | 18 ++++++++---- .../all/test_v1_package/CMakeLists.txt | 11 +++++++ .../all/test_v1_package/conanfile.py | 19 ++++++++++++ 5 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 recipes/nlohmann_json/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/nlohmann_json/all/test_v1_package/conanfile.py diff --git a/recipes/nlohmann_json/all/conanfile.py b/recipes/nlohmann_json/all/conanfile.py index 59dc57b95c..5bb517c095 100644 --- a/recipes/nlohmann_json/all/conanfile.py +++ b/recipes/nlohmann_json/all/conanfile.py @@ -1,32 +1,37 @@ -from conans import ConanFile, tools import os -required_conan_version = ">=1.33.0" +from conan import ConanFile +from conan.tools.files import copy, get +from conan.tools.layout import basic_layout + +required_conan_version = ">=1.50.0" class NlohmannJsonConan(ConanFile): name = "nlohmann_json" homepage = "https://github.com/nlohmann/json" description = "JSON for Modern C++ parser and generator." - topics = ("conan", "jsonformoderncpp", - "nlohmann_json", "json", "header-only") + topics = ("jsonformoderncpp", "nlohmann_json", "json", "header-only") url = "https://github.com/conan-io/conan-center-index" - no_copy_source = True license = "MIT" + settings = "os", "arch", "compiler", "build_type" + no_copy_source = True - @property - def _source_subfolder(self): - return "source_subfolder" + def layout(self): + basic_layout(self, src_folder="src") def package_id(self): - self.info.header_only() + self.info.clear() + + def generate(self): + pass 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(pattern="LICENSE*", src=self._source_subfolder, dst="licenses") - self.copy("*", src=os.path.join(self._source_subfolder, "include"), dst="include") + copy(self, "LICENSE*", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy(self, "*", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include")) def package_info(self): self.cpp_info.names["cmake_find_package"] = "nlohmann_json" diff --git a/recipes/nlohmann_json/all/test_package/CMakeLists.txt b/recipes/nlohmann_json/all/test_package/CMakeLists.txt index ed211c4db5..a0cd149e8a 100644 --- a/recipes/nlohmann_json/all/test_package/CMakeLists.txt +++ b/recipes/nlohmann_json/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(test_package) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(nlohmann_json REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) diff --git a/recipes/nlohmann_json/all/test_package/conanfile.py b/recipes/nlohmann_json/all/test_package/conanfile.py index 7e2dfe859b..87a7297528 100644 --- a/recipes/nlohmann_json/all/test_package/conanfile.py +++ b/recipes/nlohmann_json/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout + class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +21,5 @@ class TestPackageConan(ConanFile): cmake.build() def test(self): - if not tools.cross_building(self.settings): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun") diff --git a/recipes/nlohmann_json/all/test_v1_package/CMakeLists.txt b/recipes/nlohmann_json/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000..6eb158583c --- /dev/null +++ b/recipes/nlohmann_json/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.1.2) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(nlohmann_json REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +target_link_libraries(${PROJECT_NAME} nlohmann_json::nlohmann_json) +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11) diff --git a/recipes/nlohmann_json/all/test_v1_package/conanfile.py b/recipes/nlohmann_json/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000..37ada80898 --- /dev/null +++ b/recipes/nlohmann_json/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +import os + +from conan.tools.build import cross_building +from conans import ConanFile, CMake + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + 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)