cmake_policy(VERSION 3.16)

find_program(AR65 NAMES ar65)
find_program(CC65 NAMES cc65)
find_program(CA65 NAMES ca65)
find_program(LD65 NAMES ld65)

set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm)
set(CC ${CC65})
set(CMAKE_ASM_COMPILER ${CA65})
set(CMAKE_ASM_LINKER ${LD65})
set(CMAKE_ASM_FLAGS "-W1 -t cx16")
set(CMAKE_ASM_LINK_FLAGS "-C cx16-asm.cfg -u __EXEHDR__")
set(CMAKE_STATIC_LIBRARY_SUFFIX_ASM ".lib")

set(CMAKE_AR ${AR65})
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")

set(CMAKE_ASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> r <TARGET> <OBJECTS> ")
set(CMAKE_ASM_LINK_EXECUTABLE
    "${LD65} -m map.txt <CMAKE_ASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES> cx16.lib")
