Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ if(CMAKE_VERSION VERSION_GREATER "3.25")
# Print specific properties for specific targets
cmake_print_properties(
TARGETS
to_c_array
stdlib_h
jsonnet_obj_static
jsonnet_obj_shared
Expand Down
12 changes: 5 additions & 7 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
add_executable(to_c_array EXCLUDE_FROM_ALL to_c_array.cpp)
configure_target_cc_props(to_c_array)

add_custom_command(
COMMENT "Packing std.jsonnet into std.jsonnet.h"
COMMAND
to_c_array
"${CMAKE_CURRENT_SOURCE_DIR}/std.jsonnet"
"${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h"
"${CMAKE_COMMAND}"
"-DINPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/std.jsonnet"
"-DOUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h"
-P "${CMAKE_CURRENT_SOURCE_DIR}/pack_std_jsonnet.cmake"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h"
MAIN_DEPENDENCY std.jsonnet
DEPENDS to_c_array)
DEPENDS pack_std_jsonnet.cmake)

add_library(stdlib_h INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h")
target_include_directories(stdlib_h INTERFACE "${CMAKE_CURRENT_BINARY_DIR}")
8 changes: 8 additions & 0 deletions stdlib/pack_std_jsonnet.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Usage: cmake -DINPUT_FILE=<in> -DOUTPUT_FILE=<out> -P pack_std_jsonnet.cmake
#
# Writes the bytes of INPUT_FILE to OUTPUT_FILE as a comma-separated list of
# hex literals followed by a terminating 0, for use inside a C array
# initializer.
file(READ "${INPUT_FILE}" std_hex HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," std_bytes "${std_hex}")
file(WRITE "${OUTPUT_FILE}" "${std_bytes}0")
Loading