Skip to content

Commit aab7ce2

Browse files
authored
Merge pull request #875 from madebr/univalue
Add univalue/1.0.5 recipe
2 parents cb06047 + 96abe70 commit aab7ce2

File tree

7 files changed

+256
-0
lines changed

7 files changed

+256
-0
lines changed

Diff for: recipes/univalue/all/conandata.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sources:
2+
"1.0.5":
3+
url: "https://github.com/jgarzik/univalue/archive/v1.0.5.tar.gz"
4+
sha256: "59eee225b078066c60277cab6dd93e74a0e7bed2be455db507eb39bd4f8e4319"
5+
patches:
6+
"1.0.5":
7+
- patch_file: "patches/0001-fix-windows.patch"
8+
base_path: "source_subfolder"

Diff for: recipes/univalue/all/conanfile.py

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
from conans import ConanFile, tools, AutoToolsBuildEnvironment
2+
from contextlib import contextmanager
3+
import os
4+
5+
6+
class UnivalueConan(ConanFile):
7+
name = "univalue"
8+
description = "High performance RAII C++ JSON library and universal value object class"
9+
topics = "conan", "univalue", "universal", "json", "encoding", "decoding"
10+
license = "MIT"
11+
homepage = "https://github.com/jgarzik/univalue"
12+
url = "https://github.com/conan-io/conan-center-index"
13+
exports_sources = "patches/**"
14+
settings = "os", "arch", "compiler", "build_type"
15+
options = {
16+
"shared": [True, False],
17+
"fPIC": [True, False],
18+
}
19+
default_options = {
20+
"shared": False,
21+
"fPIC": True,
22+
}
23+
24+
_autotools = None
25+
26+
@property
27+
def _source_subfolder(self):
28+
return "source_subfolder"
29+
30+
def config_options(self):
31+
if self.settings.os == "Windows":
32+
del self.options.fPIC
33+
34+
def configure(self):
35+
if self.options.shared:
36+
del self.options.fPIC
37+
38+
def build_requirements(self):
39+
self.build_requires("libtool/2.4.6")
40+
if tools.os_info.is_windows and "CONAN_BASH_PATH" not in os.environ and \
41+
tools.os_info.detect_windows_subsystem() != "msys2":
42+
self.build_requires("msys2/20190524")
43+
44+
def source(self):
45+
tools.get(**self.conan_data["sources"][self.version])
46+
os.rename("univalue-{}".format(self.version), self._source_subfolder)
47+
48+
def _configure_autotools(self):
49+
if self._autotools:
50+
return self._autotools
51+
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
52+
self._autotools.libs = []
53+
if self.settings.compiler == "Visual Studio":
54+
self._autotools.flags.append("-FS")
55+
self._autotools.cxx_flags.append("-EHsc")
56+
conf_args = []
57+
if self.options.shared:
58+
conf_args.extend(["--enable-shared", "--disable-static"])
59+
else:
60+
conf_args.extend(["--disable-shared", "--enable-static"])
61+
self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
62+
if self.settings.compiler == "Visual Studio":
63+
tools.replace_in_file("libtool", "-Wl,-DLL,-IMPLIB", "-link -DLL -link -DLL -link -IMPLIB")
64+
return self._autotools
65+
66+
def _patch_sources(self):
67+
for patch in self.conan_data["patches"][self.version]:
68+
tools.patch(**patch)
69+
70+
@contextmanager
71+
def _build_context(self):
72+
if self.settings.compiler == "Visual Studio":
73+
with tools.vcvars(self.settings):
74+
env = {
75+
"CC": "cl -nologo",
76+
"CXX": "cl -nologo",
77+
"CPP": "cl -nologo -EP",
78+
"LD": "link",
79+
"CXXLD": "link",
80+
"AR": "{} lib".format(tools.unix_path(self.deps_user_info["automake"].ar_lib)),
81+
"NM": "dumpbin -symbols",
82+
}
83+
with tools.environment_append(env):
84+
yield
85+
else:
86+
yield
87+
88+
def build(self):
89+
self._patch_sources()
90+
with tools.chdir(self._source_subfolder):
91+
self.run("{} --verbose --install --force".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows)
92+
with self._build_context():
93+
autotools = self._configure_autotools()
94+
autotools.make()
95+
96+
def package(self):
97+
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
98+
with self._build_context():
99+
autotools = self._configure_autotools()
100+
autotools.install()
101+
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
102+
os.unlink(os.path.join(self.package_folder, "lib", "libunivalue.la"))
103+
104+
def package_info(self):
105+
suffix = ".dll" if self.options.shared and self.settings.os == "Windows" else ""
106+
if self.settings.compiler == "Visual Studio":
107+
suffix += ".lib"
108+
self.cpp_info.libs = ["univalue{}".format(suffix)]
109+
if self.options.shared:
110+
self.cpp_info.defines = ["UNIVALUE_SHARED"]

Diff for: recipes/univalue/all/patches/0001-fix-windows.patch

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
--- configure.ac
2+
+++ configure.ac
3+
@@ -42,14 +42,14 @@
4+
AC_SUBST(LIBUNIVALUE_REVISION)
5+
AC_SUBST(LIBUNIVALUE_AGE)
6+
7+
-LT_INIT
8+
+LT_INIT([win32-dll])
9+
LT_LANG([C++])
10+
11+
-case $host in
12+
- *mingw*)
13+
- LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"
14+
- ;;
15+
-esac
16+
+#case $host in
17+
+# *mingw*)
18+
+# LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"
19+
+# ;;
20+
+#esac
21+
22+
BUILD_EXEEXT=
23+
case $build in
24+
diff -ur source/source_subfolder/Makefile.am source_modified/source_subfolder/Makefile.am
25+
--- Makefile.am
26+
+++ Makefile.am
27+
@@ -34,6 +34,8 @@
28+
@echo Updating $<
29+
$(AM_V_at)$(GENBIN) > lib/univalue_escapes.h
30+
31+
+if FALSE
32+
+
33+
noinst_PROGRAMS = $(TESTS) test/test_json
34+
35+
TEST_DATA_DIR=test
36+
@@ -58,6 +60,8 @@
37+
test_object_CXXFLAGS = -I$(top_srcdir)/include
38+
test_object_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
39+
40+
+endif
41+
+
42+
TEST_FILES = \
43+
$(TEST_DATA_DIR)/fail10.json \
44+
$(TEST_DATA_DIR)/fail11.json \
45+
--- include/univalue.h
46+
+++ include/univalue.h
47+
@@ -16,7 +16,19 @@
48+
49+
#include <utility> // std::pair
50+
51+
-class UniValue {
52+
+#ifdef _WIN32
53+
+# ifdef EXPORT_DLL
54+
+# define UNIVALUE_API __declspec(dllexport)
55+
+# elif defined(UNIVALUE_SHARED)
56+
+# define UNIVALUE_API __declspec(dllimport)
57+
+# endif
58+
+#endif
59+
+
60+
+#ifndef UNIVALUE_API
61+
+# define UNIVALUE_API
62+
+#endif
63+
+
64+
+UNIVALUE_API class UniValue {
65+
public:
66+
enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, };
67+
68+
@@ -262,9 +274,9 @@
69+
JTOK_STRING,
70+
};
71+
72+
-extern enum jtokentype getJsonToken(std::string& tokenVal,
73+
+UNIVALUE_API extern enum jtokentype getJsonToken(std::string& tokenVal,
74+
unsigned int& consumed, const char *raw, const char *end);
75+
-extern const char *uvTypeName(UniValue::VType t);
76+
+UNIVALUE_API extern const char *uvTypeName(UniValue::VType t);
77+
78+
static inline bool jsonTokenIsValue(enum jtokentype jtt)
79+
{
80+
@@ -299,8 +311,8 @@
81+
// not reached
82+
}
83+
84+
-extern const UniValue NullUniValue;
85+
+UNIVALUE_API extern const UniValue NullUniValue;
86+
87+
const UniValue& find_value( const UniValue& obj, const std::string& name);
88+
89+
#endif // __UNIVALUE_H__

Diff for: recipes/univalue/all/test_package/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package CXX)
3+
4+
5+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
6+
conan_basic_setup()
7+
8+
add_executable(${PROJECT_NAME} test_package.cpp)
9+
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

Diff for: recipes/univalue/all/test_package/conanfile.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
from conans import ConanFile, CMake, tools
3+
4+
class apriltagTestConan(ConanFile):
5+
settings = "os", "compiler", "build_type", "arch"
6+
generators = "cmake"
7+
8+
def build(self):
9+
cmake = CMake(self)
10+
cmake.configure()
11+
cmake.build()
12+
13+
def test(self):
14+
if not tools.cross_building(self.settings):
15+
bin_path = os.path.join("bin", "test_package")
16+
self.run(bin_path, run_environment=True)

Diff for: recipes/univalue/all/test_package/test_package.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "univalue.h"
2+
3+
#include <cstdlib>
4+
#include <iostream>
5+
6+
int main(int argc, char *argv[])
7+
{
8+
UniValue package1(UniValue::VOBJ);
9+
package1.pushKV("name", "univalue");
10+
package1.pushKV("number", 1337);
11+
package1.pushKV("double", 3.14);
12+
UniValue package2(UniValue::VOBJ);
13+
package2.pushKV("name", "boost");
14+
package2.pushKV("bool", true);
15+
UniValue parents(UniValue::VOBJ);
16+
parents.pushKV("p1", package1);
17+
parents.pushKV("p2", package2);
18+
19+
std::cout << parents.write(2);
20+
return EXIT_SUCCESS;
21+
}

Diff for: recipes/univalue/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"1.0.5":
3+
folder: all

0 commit comments

Comments
 (0)