diff --git a/conan/.gitignore b/conan/.gitignore new file mode 100644 index 000000000..6eed1dafa --- /dev/null +++ b/conan/.gitignore @@ -0,0 +1,4 @@ +test_package/build +*.pyc +conanbuildinfo.cmake +conaninfo.txt \ No newline at end of file diff --git a/conan/build.py b/conan/build.py new file mode 100644 index 000000000..8fda4c182 --- /dev/null +++ b/conan/build.py @@ -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() \ No newline at end of file diff --git a/conan/conanfile.py b/conan/conanfile.py new file mode 100644 index 000000000..7cd84c3ea --- /dev/null +++ b/conan/conanfile.py @@ -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) \ No newline at end of file diff --git a/conan/test_package/.gitignore b/conan/test_package/.gitignore new file mode 100644 index 000000000..cc8f50ad6 --- /dev/null +++ b/conan/test_package/.gitignore @@ -0,0 +1,2 @@ +build/ +conanfile.pyc \ No newline at end of file diff --git a/conan/test_package/CMakeLists.txt b/conan/test_package/CMakeLists.txt new file mode 100644 index 000000000..23997824f --- /dev/null +++ b/conan/test_package/CMakeLists.txt @@ -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}) \ No newline at end of file diff --git a/conan/test_package/conanfile.py b/conan/test_package/conanfile.py new file mode 100644 index 000000000..993290f8a --- /dev/null +++ b/conan/test_package/conanfile.py @@ -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/" 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) \ No newline at end of file diff --git a/conan/test_package/example.cpp b/conan/test_package/example.cpp new file mode 100644 index 000000000..6c7ebccc7 --- /dev/null +++ b/conan/test_package/example.cpp @@ -0,0 +1,16 @@ +#include "json.hpp" +#include + +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; + } +} \ No newline at end of file