Retro68/cmake/add_application.cmake
2015-10-08 22:44:18 +02:00

120 lines
3.5 KiB
CMake

include(CMakeParseArguments)
cmake_policy(PUSH)
cmake_policy(SET CMP0012 NEW)
function(add_application name)
set(options DEBUGBREAK CONSOLE CARBON CLASSIC)
set(oneValueArgs TYPE CREATOR)
set(multiValueArgs FILES MAKEAPPL_ARGS)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
list(APPEND ARGS_FILES ${ARGS_UNPARSED_ARGUMENTS})
set(REZ_FLAGS)
if(CMAKE_SYSTEM_NAME MATCHES RetroPPC OR CMAKE_SYSTEM_NAME MATCHES RetroCarbon)
if((CMAKE_SYSTEM_NAME MATCHES RetroCarbon OR ARGS_CARBON) AND NOT ARGS_CLASSIC)
set(REZ_FLAGS -DTARGET_API_MAC_CARBON=1)
endif()
endif()
set(files)
set(rsrc_files)
set(rez_files)
foreach(f ${ARGS_FILES})
if(${f} MATCHES "\\.r$")
add_custom_command(
OUTPUT ${f}.rsrc.bin
COMMAND ${REZ} ${REZ_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${f} -I ${REZ_INCLUDE_PATH} -o ${f}.rsrc.bin
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${f})
list(APPEND rsrc_files "${CMAKE_CURRENT_BINARY_DIR}/${f}.rsrc.bin")
list(APPEND rez_files "${f}")
elseif(${f} MATCHES "\\.rsrc$")
list(APPEND rsrc_files "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
elseif(${f} MATCHES "\\.rsrc.bin$")
list(APPEND rsrc_files "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
else()
list(APPEND files "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
endif()
endforeach()
add_executable(${name} ${files} ${rez_files})
if(${ARGS_DEBUGBREAK})
list(APPEND ARGS_MAKEAPPL_ARGS -b)
endif()
if(${ARGS_CONSOLE})
target_link_libraries(${name} RetroConsole)
# RetroConsole library uses C++:
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
endif()
foreach(f ${rsrc_files})
list(APPEND ARGS_MAKEAPPL_ARGS "${f}")
endforeach()
if(NOT ARGS_TYPE)
set(ARGS_TYPE "APPL")
endif()
if(NOT ARGS_CREATOR)
set(ARGS_CREATOR "????")
endif()
if(TARGET libretro)
set_target_properties(${name} PROPERTIES LINK_DEPENDS libretro)
endif(TARGET libretro)
if(CMAKE_SYSTEM_NAME MATCHES Retro68)
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.flt)
add_custom_command(
OUTPUT ${name}.bin ${name}.APPL ${name}.dsk
COMMAND ${REZ} ${REZ_FLAGS}
${REZ_TEMPLATES_PATH}/Retro68APPL.r
-I${REZ_INCLUDE_PATH}
-DFLT_FILE_NAME="\\"${name}.flt\\""
-o "${name}.bin" --cc "${name}.dsk" --cc "${name}.APPL"
-t ${ARGS_TYPE} -c ${ARGS_CREATOR}
${ARGS_MAKEAPPL_ARGS}
DEPENDS ${name} ${rsrc_files})
add_custom_target(${name}_APPL ALL DEPENDS ${name}.bin)
elseif(CMAKE_SYSTEM_NAME MATCHES RetroPPC OR CMAKE_SYSTEM_NAME MATCHES RetroCarbon)
if((CMAKE_SYSTEM_NAME MATCHES RetroCarbon OR ARGS_CARBON) AND NOT ARGS_CLASSIC)
set(REZ_TEMPLATE "${REZ_TEMPLATES_PATH}/RetroCarbonAPPL.r")
target_compile_definitions(${name} PUBLIC -DTARGET_API_MAC_CARBON=1)
target_link_libraries(${name} -carbon)
else()
set(REZ_TEMPLATE "${REZ_TEMPLATES_PATH}/RetroPPCAPPL.r")
endif()
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.xcoff)
add_custom_command(
OUTPUT ${name}.pef
COMMAND ${MAKE_PEF} "${name}.xcoff" -o "${name}.pef"
DEPENDS ${name})
add_custom_command(
OUTPUT ${name}.bin ${name}.APPL ${name}.dsk
COMMAND ${REZ}
${REZ_FLAGS}
${REZ_TEMPLATE}
-I${REZ_INCLUDE_PATH}
-DCFRAG_NAME="\\"${name}\\""
-o "${name}.bin" --cc "${name}.dsk" --cc "${name}.APPL"
-t ${ARGS_TYPE} -c ${ARGS_CREATOR}
--data ${name}.pef
${ARGS_MAKEAPPL_ARGS}
DEPENDS ${name}.pef ${rsrc_files})
add_custom_target(${name}_APPL ALL DEPENDS ${name}.bin)
endif()
endfunction()
cmake_policy(POP)