This commit is contained in:
Vincent Thiery 2017-06-16 17:24:17 +00:00 committed by GitHub
commit ebb7d6dd1e
7 changed files with 81 additions and 0 deletions

4
conan/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
test_package/build
*.pyc
conanbuildinfo.cmake
conaninfo.txt

7
conan/build.py Normal file
View File

@ -0,0 +1,7 @@
from conan.packager import ConanMultiPackager
if __name__ == "__main__":
builder = ConanMultiPackager(username="nlohmann", channel="stable")
builder.add_common_builds(pure_c=False)
builder.run()

21
conan/conanfile.py Normal file
View File

@ -0,0 +1,21 @@
from conans import ConanFile
from conans.tools import download
class JsonForModernCppConan(ConanFile):
name = "jsonformoderncpp"
version = "2.1.1"
license = "MIT"
url = "https://github.com/nlohmann/json"
author = "Niels Lohmann (mail@nlohmann.me)"
settings = None
options = {"path": "ANY"}
default_options = "path="
def source(self):
download("https://github.com/nlohmann/json/releases/download/v%s/json.hpp" % self.version, "json.hpp")
def package(self):
header_dir = "include"
if self.options.path != "":
header_dir += "/" + str(self.options.path)
self.copy("*.hpp", dst=header_dir)

2
conan/test_package/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build/
conanfile.pyc

View File

@ -0,0 +1,9 @@
project(PackageTest CXX)
cmake_minimum_required(VERSION 3.0)
add_compile_options(-std=c++11)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})

View File

@ -0,0 +1,22 @@
from conans import ConanFile, CMake
import os
version = "2.1.1"
channel = os.getenv("CONAN_CHANNEL", "stable")
username = os.getenv("CONAN_USERNAME", "nlohmann")
class JsonForModernCppTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = "jsonformoderncpp/%s@%s/%s" % (version, username, channel)
generators = "cmake"
def build(self):
cmake = CMake(self.settings)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is in "test_package"
cmake.configure(self, source_dir=self.conanfile_directory, build_dir="./")
cmake.build(self)
def test(self):
os.chdir("bin")
self.run(".%sexample" % os.sep)

View File

@ -0,0 +1,16 @@
#include "json.hpp"
#include <iostream>
using nlohmann::json;
int main()
{
const json myJson = {
{ "Hello", "World" }
};
for (auto it{ myJson.cbegin() }; it != myJson.cend(); ++it)
{
std::cout << it.key() << " " << it.value() << std::endl;
}
}