mirror of
https://github.com/conan-io/conan-center-index.git
synced 2025-08-12 09:22:50 +00:00
(#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
This commit is contained in:
@@ -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"
|
||||
|
@@ -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)
|
||||
|
@@ -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")
|
||||
|
11
recipes/nlohmann_json/all/test_v1_package/CMakeLists.txt
Normal file
11
recipes/nlohmann_json/all/test_v1_package/CMakeLists.txt
Normal file
@@ -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)
|
19
recipes/nlohmann_json/all/test_v1_package/conanfile.py
Normal file
19
recipes/nlohmann_json/all/test_v1_package/conanfile.py
Normal file
@@ -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)
|
Reference in New Issue
Block a user