diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-01-08 23:01:06 +0100 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-01-08 23:01:06 +0100 |
commit | 29acda971adc34e2085d8d3749aff3d898144a70 (patch) | |
tree | ba71b079397a8de8c8fa60ffbcc1513263c05d33 /cmake | |
download | sameboy-thumbnailer-29acda971adc34e2085d8d3749aff3d898144a70.tar.gz sameboy-thumbnailer-29acda971adc34e2085d8d3749aff3d898144a70.zip |
initial commit
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FileEmbed.cmake | 12 | ||||
-rw-r--r-- | cmake/FindSameBoy.cmake | 32 | ||||
-rw-r--r-- | cmake/FindSameBoyBootRom.cmake | 54 | ||||
-rw-r--r-- | cmake/FindSameBoyTemplate.cmake | 27 |
4 files changed, 125 insertions, 0 deletions
diff --git a/cmake/FileEmbed.cmake b/cmake/FileEmbed.cmake new file mode 100644 index 0000000..8547f6a --- /dev/null +++ b/cmake/FileEmbed.cmake @@ -0,0 +1,12 @@ +get_filename_component(bin_name ${bin_in} NAME) +string(REGEX REPLACE "\\.| |-" "_" bin_name ${bin_name}) + +set(c_out ${bin_name}.c) + +file(READ ${bin_in} filedata HEX) + +message(${c_out}) + +string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata}) + +file(WRITE ${c_out} "#include <stddef.h>\n#include <stdint.h>\nconst uint8_t ${bin_name}[] = {${filedata}};\nconst size_t ${bin_name}_size = sizeof(${bin_name});\n") diff --git a/cmake/FindSameBoy.cmake b/cmake/FindSameBoy.cmake new file mode 100644 index 0000000..8fa0986 --- /dev/null +++ b/cmake/FindSameBoy.cmake @@ -0,0 +1,32 @@ +# +# SameBoy +# SAMEBOY_PATH +# SAMEBOY_INCLUDE_DIRS +# SAMEBOY_LIBRARIES +# SAMEBOY_CFLAGS + +if(SAMEBOY_PATH) + return() +endif() + +set(SAMEBOY_PATH ${PROJECT_SOURCE_DIR}/deps/SameBoy) +if(NOT EXISTS ${SAMEBOY_PATH}/README.md) + message(FATAL_ERROR "Unable to find SameBoy.\n Make sure to run `git submodule update --init --recursive`") +endif() + + +option(SAMEBOY_STATIC "" ON) + +file(GLOB SAMEBOY_CORE_SOURCES ${SAMEBOY_PATH}/Core/*.c) + +add_compile_definitions(GB_INTERNAL) +add_compile_definitions(GB_VERSION="lib") +if(SAMEBOY_STATIC) + add_library(SameBoy STATIC ${SAMEBOY_CORE_SOURCES}) +else() + add_library(SameBoy SHARED ${SAMEBOY_CORE_SOURCES}) +endif() + +set(SAMEBOY_INCLUDE_DIRS ${SAMEBOY_PATH}) +set(SAMEBOY_LIBRARIES SameBoy) +set(SAMEBOY_CFLAGS)
\ No newline at end of file diff --git a/cmake/FindSameBoyBootRom.cmake b/cmake/FindSameBoyBootRom.cmake new file mode 100644 index 0000000..81c9da0 --- /dev/null +++ b/cmake/FindSameBoyBootRom.cmake @@ -0,0 +1,54 @@ +# +# SAMEBOY_BOOTROM_SOURCES + +find_package(SameBoy REQUIRED) +set(SAMEBOY_BOOTROM_PATH ${SAMEBOY_PATH}/BootROMs) + +set(SAMEBOY_BOOTROM_VERSION "cgb_boot" CACHE STRING "") +set(SAMEBOY_BOOTROM_SIZE "2304" CACHE STRING "") + +add_executable(pb12 ${SAMEBOY_BOOTROM_PATH}/pb12.c) + +find_program(RGBASM rgbasm REQUIRED) +find_program(RBLINK rgblink REQUIRED) +find_program(RGBGFX rgbgfx REQUIRED) + +# custom build step +add_custom_command( + OUTPUT SameBoyLogo.pb12 + COMMAND + ${RGBGFX} -h -u -o SameBoyLogo.2bpp ${SAMEBOY_BOOTROM_PATH}/SameBoyLogo.png + COMMAND + pb12 < SameBoyLogo.2bpp > SameBoyLogo.pb12 + MAIN_DEPENDENCY ${SAMEBOY_BOOTROM_PATH}/SameBoyLogo.png + DEPENDS pb12 + VERBATIM +) + +add_custom_command( + OUTPUT ${SAMEBOY_BOOTROM_VERSION}.bin + COMMAND + ${RGBASM} -o ${SAMEBOY_BOOTROM_VERSION}.tmp ${SAMEBOY_BOOTROM_PATH}/${SAMEBOY_BOOTROM_VERSION}.asm + COMMAND + ${RBLINK} -o ${SAMEBOY_BOOTROM_VERSION}.tmp2 ${SAMEBOY_BOOTROM_VERSION}.tmp + COMMAND + dd if=${SAMEBOY_BOOTROM_VERSION}.tmp2 of=${SAMEBOY_BOOTROM_VERSION}.bin count=1 bs=${SAMEBOY_BOOTROM_SIZE} + DEPENDS SameBoyLogo.pb12 + VERBATIM +) + +add_custom_target(sameboy_bootrom DEPENDS ${SAMEBOY_BOOTROM_VERSION}.bin) + +add_custom_command( + OUTPUT ${SAMEBOY_BOOTROM_VERSION}_bin.c + COMMAND ${CMAKE_COMMAND} + "-Dbin_in=${SAMEBOY_BOOTROM_VERSION}.bin" + -P ${CMAKE_SOURCE_DIR}/cmake/FileEmbed.cmake + DEPENDS ${SAMEBOY_BOOTROM_VERSION}.bin + VERBATIM +) + +list(APPEND + SAMEBOY_BOOTROM_SOURCES + ${SAMEBOY_BOOTROM_VERSION}_bin.c +) diff --git a/cmake/FindSameBoyTemplate.cmake b/cmake/FindSameBoyTemplate.cmake new file mode 100644 index 0000000..4769295 --- /dev/null +++ b/cmake/FindSameBoyTemplate.cmake @@ -0,0 +1,27 @@ +# +# SAMEBOY_TEMPLATE_SOURCES + +find_package(SameBoy REQUIRED) +set(SAMEBOY_QUICKLOOK_PATH ${SAMEBOY_PATH}/QuickLook) + +list(APPEND + TEMPLATE_LIST + CartridgeTemplate + ColorCartridgeTemplate + UniversalCartridgeTemplate +) + +foreach(TEMPLATE_FILE ${TEMPLATE_LIST}) + add_custom_command( + OUTPUT ${TEMPLATE_FILE}_png.c + COMMAND ${CMAKE_COMMAND} + "-Dbin_in=${SAMEBOY_QUICKLOOK_PATH}/${TEMPLATE_FILE}.png" + -P ${CMAKE_SOURCE_DIR}/cmake/FileEmbed.cmake + ) + list(APPEND + SAMEBOY_TEMPLATE_SOURCES + ${TEMPLATE_FILE}_png.c + ) +endforeach() + +add_custom_target(sameboy_template DEPENDS ${SAMEBOY_TEMPLATE_SOURCES}) |