bx: Add bin2c and cmake macro

This commit is contained in:
Sandy Carter
2023-01-08 09:40:51 -05:00
committed by Sandy
parent e9b0bb3b6c
commit 99537daccd
7 changed files with 128 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ if(@CMAKE_CROSSCOMPILING@)
endif()
endmacro()
_bgfx_crosscompile_use_host_tool(bin2c)
_bgfx_crosscompile_use_host_tool(shaderc)
_bgfx_crosscompile_use_host_tool(texturec)
_bgfx_crosscompile_use_host_tool(texturev)

View File

@@ -1,3 +1,64 @@
# _bgfx_bin2c_parse(
# INPUT_FILE filename
# OUTPUT_FILE filename
# ARRAY_NAME name
# )
# Usage: bin2c -f <in> -o <out> -n <name>
function(_bgfx_bin2c_parse ARG_OUT)
set(options "")
set(oneValueArgs INPUT_FILE;OUTPUT_FILE;ARRAY_NAME)
set(multiValueArgs "")
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
set(CLI "")
# -f
if(ARG_INPUT_FILE)
list(APPEND CLI "-f" "${ARG_INPUT_FILE}")
else()
message(SEND_ERROR "Call to _bgfx_bin2c_parse() must have an INPUT_FILE")
endif()
# -o
if(ARG_OUTPUT_FILE)
list(APPEND CLI "-o" "${ARG_OUTPUT_FILE}")
else()
message(SEND_ERROR "Call to _bgfx_bin2c_parse() must have an OUTPUT_FILE")
endif()
# -n
if(ARG_ARRAY_NAME)
list(APPEND CLI "-n" "${ARG_ARRAY_NAME}")
else()
message(SEND_ERROR "Call to _bgfx_bin2c_parse() must have an ARRAY_NAME")
endif()
set(${ARG_OUT} ${CLI} PARENT_SCOPE)
endfunction()
# bgfx_compile_binary_to_header(
# INPUT_FILE filename
# OUTPUT_FILE filename
# ARRAY_NAME name
# )
#
function(bgfx_compile_binary_to_header)
set(options "")
set(oneValueArgs INPUT_FILE;OUTPUT_FILE;ARRAY_NAME)
set(multiValueArgs "")
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
_bgfx_bin2c_parse(
CLI
INPUT_FILE ${ARG_INPUT_FILE}
OUTPUT_FILE ${ARG_OUTPUT_FILE}
ARRAY_NAME ${ARG_ARRAY_NAME}
)
add_custom_command(
OUTPUT ${ARG_OUTPUT_FILE} #
COMMAND bgfx::bin2c ${CLI} #
MAIN_DEPENDENCY ${ARG_INPUT_FILE} #
)
endfunction()
# _bgfx_shaderc_parse(
# FILE filename
# OUTPUT filename

View File

@@ -9,3 +9,7 @@
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
include(bx.cmake)
if(BGFX_BUILD_TOOLS)
include(bin2c.cmake)
endif()

21
cmake/bx/bin2c.cmake Normal file
View File

@@ -0,0 +1,21 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
add_executable(bin2c)
# Grab the bin2c source files
file(GLOB_RECURSE BIN2C_SOURCES #
${BX_DIR}/tools/bin2c/*.cpp #
${BX_DIR}/tools/bin2c/*.h #
)
target_sources(bin2c PRIVATE ${BIN2C_SOURCES})
target_link_libraries(bin2c PRIVATE bx)
set_target_properties(bin2c PROPERTIES FOLDER "bgfx/tools")