Skip to content

Commit

Permalink
Add conanfile, build and test_package
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Thiery committed Jun 14, 2017
1 parent fd4a0ec commit b6b1c44
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_package/build
*.pyc
conanbuildinfo.cmake
conaninfo.txt
7 changes: 7 additions & 0 deletions conan/build.py
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from conans import ConanFile
from conans.tools import download

class StatsdClient(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 changes: 2 additions & 0 deletions conan/test_package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
conanfile.pyc
9 changes: 9 additions & 0 deletions conan/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
22 changes: 22 additions & 0 deletions conan/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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 RxcppTestConan(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)
16 changes: 16 additions & 0 deletions conan/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit b6b1c44

Please sign in to comment.