-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(cmake_wrapper) | ||
|
||
include(conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_subdirectory("source_subfolder") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sources: | ||
"0.17.0": | ||
sha256: "076b52edf888c01097010ad4299e3b2e7a72b60a41abbc65af364af1ed3c8dbe" | ||
url: "https://github.com/google/jsonnet/archive/v0.17.0.tar.gz" | ||
patches: | ||
"0.17.0": | ||
- patch_file: "patches/fix-core-static-lib.patch" | ||
base_path: "source_subfolder" | ||
- patch_file: "patches/fix-cpp-static-lib.patch" | ||
base_path: "source_subfolder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import glob | ||
from conans import ConanFile, CMake, tools | ||
|
||
|
||
class JsonnetConan(ConanFile): | ||
name = "jsonnet" | ||
version = "0.17.0" | ||
license = "Apache-2.0" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/google/jsonnet" | ||
description = "Jsonnet - The data templating language" | ||
topics = ("conan", "jsonnet") | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
generators = "cmake" | ||
exports_sources = ["CMakeLists.txt", "patches/*"] | ||
_cmake = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _build_subfolder(self): | ||
return "build_subfolder" | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = glob.glob(self.name + "-" + self.version)[0] | ||
os.rename(extracted_dir, self._source_subfolder) | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
if self.settings.compiler.cppstd: | ||
tools.check_min_cppstd(self, "11") | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def _configure_cmake(self): | ||
if self._cmake: | ||
return self._cmake | ||
self._cmake = CMake(self) | ||
self._cmake.definitions["BUILD_TESTS"] = False | ||
self._cmake.definitions["BUILD_STATIC_LIBS"] = not self.options["shared"] | ||
self._cmake.definitions["BUILD_JSONNET"] = False | ||
self._cmake.definitions["BUILD_JSONNETFMT"] = False | ||
self._cmake.configure(build_folder=self._build_subfolder, source_folder=self._source_subfolder) | ||
return self._cmake | ||
|
||
def build(self): | ||
if not self.options["shared"]: | ||
for patch in self.conan_data.get("patches", {}).get(self.version, []): | ||
tools.patch(**patch) | ||
cmake = self._configure_cmake() | ||
cmake.build() | ||
|
||
def package(self): | ||
self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||
cmake = self._configure_cmake() | ||
cmake.install() | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["jsonnet++", "jsonnet"] | ||
self.cpp_info.names["cmake_find_package"] = "jsonnet" | ||
self.cpp_info.names["cmake_find_package_multi"] = "jsonnet" | ||
self.cpp_info.names["pkg_config"] = "jsonnet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- a/core/CMakeLists.txt | ||
+++ b/core/CMakeLists.txt | ||
@@ -15,7 +15,8 @@ | ||
static_error.h | ||
string_utils.h | ||
unicode.h | ||
- vm.h) | ||
+ vm.h | ||
+ ../third_party/md5/md5.h) | ||
|
||
set(LIBJSONNET_SOURCE | ||
desugarer.cpp | ||
@@ -26,40 +27,44 @@ | ||
pass.cpp | ||
static_analysis.cpp | ||
string_utils.cpp | ||
- vm.cpp) | ||
+ vm.cpp | ||
+ ../third_party/md5/md5.cpp) | ||
|
||
-add_library(libjsonnet SHARED ${LIBJSONNET_HEADERS} ${LIBJSONNET_SOURCE}) | ||
-add_dependencies(libjsonnet md5 stdlib) | ||
-target_link_libraries(libjsonnet md5 nlohmann_json::nlohmann_json) | ||
- | ||
-file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h JSONNET_VERSION_DEF | ||
- REGEX "[#]define[ \t]+LIB_JSONNET_VERSION[ \t]+") | ||
-string(REGEX REPLACE ".*\"v([^\"]+)\".*" "\\1" JSONNET_VERSION ${JSONNET_VERSION_DEF}) | ||
-message("Extracted Jsonnet version: " ${JSONNET_VERSION}) | ||
- | ||
- | ||
-# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without | ||
-# this step the output would be |liblibjsonnet|. | ||
-set_target_properties(libjsonnet PROPERTIES OUTPUT_NAME jsonnet | ||
- VERSION "${JSONNET_VERSION}" | ||
- SOVERSION "0" | ||
- PUBLIC_HEADER "${LIB_HEADER}") | ||
-install(TARGETS libjsonnet | ||
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
-target_include_directories(libjsonnet INTERFACE | ||
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>) | ||
|
||
-if (BUILD_STATIC_LIBS) | ||
+if (NOT BUILD_STATIC_LIBS) | ||
+ add_library(libjsonnet SHARED ${LIBJSONNET_HEADERS} ${LIBJSONNET_SOURCE}) | ||
+ add_dependencies(libjsonnet stdlib) | ||
+ target_link_libraries(libjsonnet nlohmann_json::nlohmann_json) | ||
+ | ||
+ file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h JSONNET_VERSION_DEF | ||
+ REGEX "[#]define[ \t]+LIB_JSONNET_VERSION[ \t]+") | ||
+ string(REGEX REPLACE ".*\"v([^\"]+)\".*" "\\1" JSONNET_VERSION ${JSONNET_VERSION_DEF}) | ||
+ message("Extracted Jsonnet version: " ${JSONNET_VERSION}) | ||
+ | ||
+ | ||
+ # CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without | ||
+ # this step the output would be |liblibjsonnet|. | ||
+ set_target_properties(libjsonnet PROPERTIES OUTPUT_NAME jsonnet | ||
+ VERSION "${JSONNET_VERSION}" | ||
+ SOVERSION "0" | ||
+ PUBLIC_HEADER "${LIB_HEADER}") | ||
+ install(TARGETS libjsonnet | ||
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
+ target_include_directories(libjsonnet INTERFACE | ||
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>) | ||
+else() | ||
# Static library for jsonnet command-line tool. | ||
add_library(libjsonnet_static STATIC ${LIBJSONNET_SOURCE}) | ||
- add_dependencies(libjsonnet_static md5 stdlib) | ||
- target_link_libraries(libjsonnet_static md5 nlohmann_json::nlohmann_json) | ||
+ add_dependencies(libjsonnet_static stdlib) | ||
+ target_link_libraries(libjsonnet_static nlohmann_json::nlohmann_json) | ||
set_target_properties(libjsonnet_static PROPERTIES OUTPUT_NAME jsonnet) | ||
install(TARGETS libjsonnet_static DESTINATION "${CMAKE_INSTALL_LIBDIR}") | ||
target_include_directories(libjsonnet_static INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>) | ||
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h | ||
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/include) | ||
endif() | ||
|
||
if (BUILD_SHARED_BINARIES OR NOT BUILD_STATIC_LIBS) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- a/cpp/CMakeLists.txt | ||
+++ b/cpp/CMakeLists.txt | ||
@@ -8,24 +8,24 @@ | ||
libjsonnet++.cpp | ||
) | ||
|
||
-add_library(libjsonnet++ SHARED ${LIBJSONNETPP_HEADERS} ${LIBJSONNETPP_SOURCE}) | ||
-add_dependencies(libjsonnet++ jsonnet) | ||
-# target_link_libraries(libjsonnet libjsonnet) | ||
+if (NOT BUILD_STATIC_LIBS) | ||
+ add_library(libjsonnet++ SHARED ${LIBJSONNETPP_HEADERS} ${LIBJSONNETPP_SOURCE}) | ||
+ add_dependencies(libjsonnet++ jsonnet) | ||
+ # target_link_libraries(libjsonnet libjsonnet) | ||
|
||
-# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without | ||
-# this step the output would be |liblibjsonnet|. | ||
-set_target_properties(libjsonnet++ PROPERTIES OUTPUT_NAME jsonnet++ | ||
- VERSION "0.17.0" | ||
- SOVERSION "0" | ||
- PUBLIC_HEADER "${LIB_HEADER}") | ||
-install(TARGETS libjsonnet++ | ||
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
- PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
-target_include_directories(libjsonnet++ INTERFACE | ||
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>) | ||
- | ||
-if (BUILD_STATIC_LIBS) | ||
+ # CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without | ||
+ # this step the output would be |liblibjsonnet|. | ||
+ set_target_properties(libjsonnet++ PROPERTIES OUTPUT_NAME jsonnet++ | ||
+ VERSION "0.17.0" | ||
+ SOVERSION "0" | ||
+ PUBLIC_HEADER "${LIB_HEADER}") | ||
+ install(TARGETS libjsonnet++ | ||
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
+ target_include_directories(libjsonnet++ INTERFACE | ||
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>) | ||
+else() | ||
# Static library for jsonnet command-line tool. | ||
add_library(libjsonnet++_static STATIC ${LIBJSONNETPP_SOURCE}) | ||
add_dependencies(libjsonnet++_static jsonnet) | ||
@@ -34,6 +34,8 @@ | ||
install(TARGETS libjsonnet++_static DESTINATION "${CMAKE_INSTALL_LIBDIR}") | ||
target_include_directories(libjsonnet++_static INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>) | ||
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet++.h | ||
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/include) | ||
endif() | ||
|
||
if (BUILD_SHARED_BINARIES OR NOT BUILD_STATIC_LIBS) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
|
||
target_link_libraries(${PROJECT_NAME} CONAN_PKG::jsonnet) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <libjsonnet++.h> | ||
#include <libjsonnet.h> | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
// C++ library | ||
jsonnet::Jsonnet j; | ||
if (!j.init()) { | ||
return 1; | ||
} | ||
std::cout << jsonnet::Jsonnet::version() << "\n"; | ||
|
||
// C library | ||
struct JsonnetVm* vm = jsonnet_make(); | ||
jsonnet_max_stack(vm, 10); | ||
std::cout << jsonnet_version() << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.17.0": | ||
folder: all |