build: don't use xxd in cmake
This commit is contained in:
parent
13a36efbef
commit
35df587d9c
1 changed files with 10 additions and 13 deletions
|
@ -4,20 +4,18 @@ set(SERVER_ASSETS
|
|||
completion.js
|
||||
json-schema-to-grammar.mjs
|
||||
)
|
||||
set(SERVER_ASSETS_HPP "")
|
||||
foreach(asset ${SERVER_ASSETS})
|
||||
list(APPEND SERVER_ASSETS_HPP "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp")
|
||||
# Portable equivalent of `cd public && xxd -i ${asset} ../${asset}.hpp`
|
||||
set(input "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}")
|
||||
set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp")
|
||||
|
||||
string(REGEX REPLACE "\\.| |-" "_" name "${asset}")
|
||||
file(READ "${input}" data HEX)
|
||||
string(LENGTH ${data} hex_len)
|
||||
math(EXPR len "${hex_len} / 2")
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," data ${data})
|
||||
file(WRITE "${output}" "unsigned char ${name}[] = {${data}};\nunsigned int ${name}_len = ${len};\n")
|
||||
endforeach()
|
||||
foreach(asset ${SERVER_ASSETS})
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp"
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/public"
|
||||
COMMAND xxd -i "${asset}" "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}"
|
||||
VERBATIM
|
||||
)
|
||||
endforeach()
|
||||
add_custom_target(generate_server_assets ALL DEPENDS ${SERVER_ASSETS_HPP})
|
||||
|
||||
set(TARGET server)
|
||||
option(LLAMA_SERVER_VERBOSE "Build verbose logging option for Server" ON)
|
||||
|
@ -28,7 +26,6 @@ add_executable(${TARGET}
|
|||
utils.hpp
|
||||
httplib.h
|
||||
)
|
||||
add_dependencies(${TARGET} generate_server_assets)
|
||||
install(TARGETS ${TARGET} RUNTIME)
|
||||
target_compile_definitions(${TARGET} PRIVATE
|
||||
SERVER_VERBOSE=$<BOOL:${LLAMA_SERVER_VERBOSE}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue