2020-09-08 18:37:17 +08:00
|
|
|
# Copyright 2020 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
2022-01-28 17:47:32 +08:00
|
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
2020-09-08 18:37:17 +08:00
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2023-05-11 22:50:03 +08:00
|
|
|
cmake_minimum_required(VERSION 3.13..3.26)
|
2022-04-21 16:14:48 +08:00
|
|
|
|
2020-09-08 18:37:17 +08:00
|
|
|
project(jsonnet-sapi C CXX)
|
2022-04-21 16:14:48 +08:00
|
|
|
include(CTest)
|
2022-05-31 22:29:23 +08:00
|
|
|
include(GoogleTest)
|
2020-09-08 18:37:17 +08:00
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
|
2022-02-02 17:09:26 +08:00
|
|
|
if(NOT TARGET sapi::sapi)
|
|
|
|
set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
|
|
|
|
add_subdirectory("${SAPI_ROOT}"
|
|
|
|
"${CMAKE_BINARY_DIR}/sandboxed-api-build"
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
endif()
|
2020-09-08 18:37:17 +08:00
|
|
|
|
2022-01-27 17:34:16 +08:00
|
|
|
FetchContent_Declare(jsonnet
|
|
|
|
GIT_REPOSITORY https://github.com/google/jsonnet.git
|
|
|
|
GIT_TAG v0.18.0 # 2021-12-21
|
|
|
|
)
|
2022-04-29 17:13:32 +08:00
|
|
|
set(BUILD_TESTS OFF CACHE BOOL "" FORCE) # Do not build jsonnet tests
|
2022-01-27 17:34:16 +08:00
|
|
|
FetchContent_MakeAvailable(jsonnet)
|
|
|
|
create_directory_symlink("${jsonnet_SOURCE_DIR}"
|
|
|
|
"${PROJECT_BINARY_DIR}/jsonnet")
|
|
|
|
|
2022-02-02 17:09:26 +08:00
|
|
|
configure_file("${jsonnet_SOURCE_DIR}/cmd/jsonnet.cpp"
|
|
|
|
"${PROJECT_BINARY_DIR}/gen_files/jsonnet.cpp" COPYONLY)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${PROJECT_BINARY_DIR}/gen_files/write_helper.cc"
|
|
|
|
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/gen_files"
|
|
|
|
COMMAND patch -o write_helper.cc
|
|
|
|
< "${PROJECT_SOURCE_DIR}/jsonnet.patch" > /dev/null
|
|
|
|
)
|
|
|
|
|
|
|
|
add_library(jsonnet_helper STATIC
|
|
|
|
"${PROJECT_BINARY_DIR}/gen_files/write_helper.cc"
|
|
|
|
"${jsonnet_SOURCE_DIR}/cmd/utils.cpp"
|
|
|
|
"${jsonnet_SOURCE_DIR}/cmd/utils.h"
|
|
|
|
jsonnet_helper.cc
|
|
|
|
jsonnet_helper.h
|
|
|
|
)
|
|
|
|
add_library(sapi_contrib::jsonnet_helper ALIAS jsonnet_helper)
|
|
|
|
target_include_directories(jsonnet_helper PUBLIC
|
|
|
|
"${PROJECT_BINARY_DIR}"
|
|
|
|
"${PROJECT_BINARY_DIR}/gen_files"
|
|
|
|
"${SAPI_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
target_link_libraries(jsonnet_helper
|
|
|
|
libjsonnet_for_binaries
|
|
|
|
)
|
2022-01-27 17:34:16 +08:00
|
|
|
|
2020-09-08 18:37:17 +08:00
|
|
|
add_sapi_library(jsonnet_sapi
|
2022-01-24 21:12:30 +08:00
|
|
|
FUNCTIONS c_free_input
|
2020-09-08 18:37:17 +08:00
|
|
|
c_jsonnet_destroy
|
2022-01-24 21:12:30 +08:00
|
|
|
c_jsonnet_evaluate_snippet
|
2020-09-10 18:19:06 +08:00
|
|
|
c_jsonnet_evaluate_snippet_multi
|
2020-09-10 21:27:22 +08:00
|
|
|
c_jsonnet_evaluate_snippet_stream
|
2020-09-10 23:42:00 +08:00
|
|
|
c_jsonnet_fmt_snippet
|
2022-01-24 21:12:30 +08:00
|
|
|
c_jsonnet_make
|
|
|
|
c_jsonnet_realloc
|
|
|
|
c_read_input
|
|
|
|
c_write_multi_output_files
|
|
|
|
c_write_output_file
|
|
|
|
c_write_output_stream
|
2020-09-08 18:37:17 +08:00
|
|
|
INPUTS jsonnet_helper.h
|
|
|
|
LIBRARY jsonnet_helper
|
|
|
|
LIBRARY_NAME Jsonnet
|
|
|
|
NAMESPACE ""
|
|
|
|
)
|
2022-02-02 17:09:26 +08:00
|
|
|
add_library(sapi_contrib::jsonnet ALIAS jsonnet_sapi)
|
2020-09-08 18:37:17 +08:00
|
|
|
target_include_directories(jsonnet_sapi INTERFACE
|
|
|
|
"${PROJECT_BINARY_DIR}"
|
|
|
|
)
|
2022-02-02 17:09:26 +08:00
|
|
|
target_link_libraries(jsonnet_sapi PUBLIC
|
|
|
|
sapi_contrib::jsonnet_helper
|
|
|
|
)
|
2020-09-08 18:37:17 +08:00
|
|
|
|
2022-04-21 16:17:08 +08:00
|
|
|
if(SAPI_BUILD_EXAMPLES)
|
2022-02-02 17:09:26 +08:00
|
|
|
add_subdirectory(examples)
|
|
|
|
endif()
|
2020-09-16 22:43:42 +08:00
|
|
|
|
2022-04-21 16:17:08 +08:00
|
|
|
if(BUILD_TESTING AND SAPI_BUILD_TESTING)
|
2022-01-27 20:59:14 +08:00
|
|
|
# Create directories so the tests will be able to access them
|
2022-01-27 21:29:02 +08:00
|
|
|
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/tests_input"
|
|
|
|
"${PROJECT_BINARY_DIR}/tests_output"
|
|
|
|
"${PROJECT_BINARY_DIR}/tests_expected_output")
|
2022-01-27 20:59:14 +08:00
|
|
|
|
|
|
|
add_custom_target(test_preparation ALL
|
|
|
|
COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes/*
|
2022-01-27 21:29:02 +08:00
|
|
|
${PROJECT_BINARY_DIR}/tests_input
|
2022-01-27 20:59:14 +08:00
|
|
|
COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes_expected_output/*
|
2022-01-27 21:29:02 +08:00
|
|
|
${PROJECT_BINARY_DIR}/tests_expected_output
|
2022-01-27 20:59:14 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(jsonnet_tests
|
|
|
|
jsonnet_tests.cc
|
|
|
|
)
|
|
|
|
target_include_directories(jsonnet_tests PUBLIC
|
2022-02-02 17:09:26 +08:00
|
|
|
"${PROJECT_SOURCE_DIR}"
|
2022-01-27 20:59:14 +08:00
|
|
|
)
|
|
|
|
target_link_libraries(jsonnet_tests
|
2022-02-02 17:09:26 +08:00
|
|
|
sapi_contrib::jsonnet
|
2022-01-27 20:59:14 +08:00
|
|
|
sapi::test_main
|
|
|
|
)
|
|
|
|
gtest_discover_tests(jsonnet_tests)
|
2022-01-27 17:34:16 +08:00
|
|
|
endif()
|