all repos — mgba @ a263d4718fbf84ce17142edc7b81c6f27f97bfb5

mGBA Game Boy Advance Emulator

src/platform/3ds/CMakeLists.txt (view raw)

  1set(USE_VFS_3DS ON CACHE BOOL "Use 3DS-specific file support")
  2mark_as_advanced(USE_VFS_3DS)
  3
  4find_program(3DSLINK 3dslink)
  5find_program(3DSXTOOL 3dsxtool)
  6find_program(BANNERTOOL bannertool)
  7find_program(MAKEROM makerom)
  8find_program(PICASSO picasso)
  9find_program(RAW2C raw2c)
 10find_program(TEX3DS tex3ds)
 11set(STRIP "${cross_prefix_path}strip" CACHE INTERNAL "symbol stripper")
 12
 13set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format" PARENT_SCOPE)
 14set(OS_DEFINES _GNU_SOURCE COLOR_16_BIT COLOR_5_6_5 FIXED_ROM_BUFFER IOAPI_NO_64)
 15
 16include_directories(${CMAKE_CURRENT_BINARY_DIR})
 17if(${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
 18	list(APPEND OS_LIB citro3dd ctrud)
 19else()
 20	list(APPEND OS_LIB citro3d ctru)
 21endif()
 22file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/3ds-*.c ${CMAKE_CURRENT_SOURCE_DIR}/ctru-heap.c ${CMAKE_CURRENT_SOURCE_DIR}/socket.c)
 23set(OS_SRC ${OS_SRC} PARENT_SCOPE)
 24set(OS_LIB ${OS_LIB} PARENT_SCOPE)
 25source_group("3DS-specific code" FILES ${OS_SRC})
 26
 27if(USE_VFS_3DS)
 28	list(APPEND OS_DEFINES USE_VFS_3DS)
 29else()
 30	list(APPEND OS_DEFINES USE_VFS_FILE)
 31	list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
 32endif()
 33set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE)
 34set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE)
 35
 36list(APPEND GUI_SRC
 37	${CMAKE_CURRENT_BINARY_DIR}/icons.c
 38	${CMAKE_CURRENT_BINARY_DIR}/uishader.c
 39	${CMAKE_CURRENT_BINARY_DIR}/uishader.h
 40	${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin.h
 41
 42	${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c
 43	${CMAKE_CURRENT_SOURCE_DIR}/ctr-gpu.c
 44	${CMAKE_CURRENT_SOURCE_DIR}/ctr-gpu.h)
 45
 46set_source_files_properties(
 47	${CMAKE_CURRENT_BINARY_DIR}/icons.c
 48	${CMAKE_CURRENT_BINARY_DIR}/uishader.c
 49	${CMAKE_CURRENT_BINARY_DIR}/uishader.h
 50	${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin.h
 51	PROPERTIES GENERATED ON)
 52
 53add_executable(${BINARY_NAME}.elf ${GUI_SRC} main.c)
 54set_target_properties(${BINARY_NAME}.elf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 55target_link_libraries(${BINARY_NAME}.elf ${BINARY_NAME} ${M_LIBRARY} ${OS_LIB})
 56
 57add_custom_command(OUTPUT ${BINARY_NAME}.smdh
 58                   COMMAND ${BANNERTOOL} makesmdh -s "${PROJECT_NAME}" -l "${SUMMARY}" -p "endrift" -i ${CMAKE_SOURCE_DIR}/res/mgba-48.png -o ${BINARY_NAME}.smdh
 59                   DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba-48.png)
 60
 61add_custom_command(OUTPUT ${BINARY_NAME}.xml
 62                   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/hbl.xml ${BINARY_NAME}.xml
 63                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/hbl.xml)
 64
 65add_custom_command(OUTPUT ${BINARY_NAME}.bnr
 66                   COMMAND ${BANNERTOOL} makebanner -ci ${CMAKE_CURRENT_SOURCE_DIR}/banner.cgfx -a ${CMAKE_CURRENT_SOURCE_DIR}/bios.wav -o ${BINARY_NAME}.bnr
 67                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/banner.cgfx ${CMAKE_CURRENT_SOURCE_DIR}/bios.wav)
 68
 69# tex3ds binaries as of 2.0.1-3 crash if you try to do this
 70#add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/icons.t3x
 71#                   COMMAND ${TEX3DS} -f rgb5551 -o icons.t3x ${CMAKE_SOURCE_DIR}/res/icons.png
 72#                   MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/res/icons.png
 73#                   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 74
 75add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/icons.c
 76                   COMMAND ${RAW2C} ${CMAKE_CURRENT_SOURCE_DIR}/icons.t3x
 77                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/icons.t3x)
 78
 79add_custom_command(
 80	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin ${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin.h
 81	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/uishader.v.pica ${CMAKE_CURRENT_SOURCE_DIR}/uishader.g.pica
 82	COMMAND ${PICASSO}
 83		-o ${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin
 84		-h ${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin.h
 85		${CMAKE_CURRENT_SOURCE_DIR}/uishader.v.pica
 86		${CMAKE_CURRENT_SOURCE_DIR}/uishader.g.pica
 87	COMMENT "picasso uishader.shbin")
 88
 89add_custom_command(
 90	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/uishader.c ${CMAKE_CURRENT_BINARY_DIR}/uishader.h
 91	MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin
 92	COMMAND ${RAW2C} ${CMAKE_CURRENT_BINARY_DIR}/uishader.shbin
 93	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 94	COMMENT "raw2c uishader.shbin")
 95
 96add_custom_command(OUTPUT ${BINARY_NAME}.3dsx
 97                   COMMAND ${3DSXTOOL} ${BINARY_NAME}.elf ${BINARY_NAME}.3dsx --smdh=${BINARY_NAME}.smdh
 98                   DEPENDS ${BINARY_NAME}.elf ${BINARY_NAME}.smdh ${BINARY_NAME}.xml)
 99add_custom_target(${BINARY_NAME}.3dsx ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.3dsx)
100
101add_custom_command(OUTPUT ${BINARY_NAME}.cia
102                   COMMAND ${STRIP} -o ${BINARY_NAME}-stripped.elf ${BINARY_NAME}.elf
103                   COMMAND ${MAKEROM} -f cia -o ${BINARY_NAME}.cia -rsf cia.rsf -target t -exefslogo -elf ${BINARY_NAME}-stripped.elf -icon ${BINARY_NAME}.smdh -banner ${BINARY_NAME}.bnr -major ${LIB_VERSION_MAJOR} -minor ${LIB_VERSION_MINOR} -micro ${LIB_VERSION_PATCH}
104                   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cia.rsf ${BINARY_NAME}.elf ${BINARY_NAME}.smdh ${BINARY_NAME}.bnr)
105add_custom_target(${BINARY_NAME}.cia ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.cia)
106
107add_custom_target(run ${3DSLINK} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.3dsx
108                  DEPENDS ${BINARY_NAME}.3dsx)
109
110add_custom_target(install-cia stat -f '0 00000001 %016Xz' '${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.cia' | xxd -r | cat -- - '${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.cia' | nc $ENV{N3DS_IP} 5000
111                  DEPENDS ${BINARY_NAME}.cia)
112
113if(BUILD_PERF)
114	add_custom_target(${BINARY_NAME}-perf.3dsx ALL
115	                  ${3DSXTOOL} ../${BINARY_NAME}-perf ${BINARY_NAME}-perf.3dsx --smdh=${BINARY_NAME}.smdh
116	                  DEPENDS ${BINARY_NAME}-perf ${BINARY_NAME}.smdh)
117	install(FILES
118		    ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}-perf.3dsx
119		    DESTINATION . COMPONENT ${BINARY_NAME}-perf)
120endif()
121
122configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cia.rsf.in ${CMAKE_CURRENT_BINARY_DIR}/cia.rsf)
123
124install(TARGETS ${BINARY_NAME}.elf DESTINATION . COMPONENT ${BINARY_NAME}-dbg)
125install(FILES
126	    ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.3dsx
127	    ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.smdh
128	    ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.xml
129	    DESTINATION 3dsx COMPONENT ${BINARY_NAME}-3ds)
130install(FILES
131	    ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.cia
132	    DESTINATION cia COMPONENT ${BINARY_NAME}-3ds)