assemblycmakecross-platform6502commodore

How to set up a CMake cross-assembling toolchain for 6502 CPU (C64)?


I'm trying to set up a, as re-usable as possible, cmake build system for a Commodore 64/6502 cross-assembler called TMPx.

My questions are:

Other than that, other advices and suggestions are greatly appreciated.

(Here's my git repo with the files below)

My ./CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 3.14)
set(CMAKE_SYSTEM_NAME "C64")
set(CMAKE_SYSTEM_PROCESSOR 6502)

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/cmake")
#TODO: Try to move this into one of the cmake/ modules..
SET(CMAKE_ASM_TMPX_COMPILER "${CMAKE_BINARY_DIR}/tools/TMPx_v1.1.0-STYLE/linux-x86_64/tmpx")

PROJECT(test001 ASM_TMPX)

By following this guide from the CMake wiki I've so far got the following cmake modules close to done and semi-working:

./cmake/CMakeASM_TMPXInformation.cmake:

SET(ASM_DIALECT "_TMPX")

SET(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS ms;s;asm)


#Set any default arguments here
#TODO: remove the nasm args
IF(UNIX)
    SET(CMAKE_ASM_TMPX_COMPILER_ARG1 "-f elf")
ELSE(UNIX)
    SET(CMAKE_ASM_TMPX_COMPILER_ARG1 "-f win32")
ENDIF(UNIX)

# This section exists to override the one in CMakeASMInformation.cmake
# (the default Information file). This removes the <FLAGS>
# thing so that your C compiler flags that have been set via
# set_target_properties don't get passed to TMPx and confuse it.
IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT)

    #TODO: Change nasm args to correct tmpx arguments
    SET(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> -o <OBJECT> <SOURCE>")

ENDIF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT)

INCLUDE(CMakeASMInformation)
SET(ASM_DIALECT)

./cmake/CMakeDetermineASM_TMPXCompiler.cmake:

SET(ASM_DIALECT "_TMPX")

IF(UNIX)
    SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}tmpx)
ENDIF()

# TODO: Properly determine exen for other host platforms
# (The Windows exe would be 'TMPx.exe' but possibly 'tmpx.exe' or 'TMPX.EXE')

INCLUDE(CMakeDetermineASMCompiler)

SET(ASM_DIALECT)

./cmake/CMakeTestASM_TMPXCompiler.cmake:

###
# From original template:
# This file is used by EnableLanguage in cmGlobalGenerator to
# determine that the selected ASM-ATT "compiler" works.
# For assembler this can only check whether the compiler has been found,
# because otherwise there would have to be a separate assembler source file
# for each assembler on every architecture.
###

set(ASM_DIALECT "_TMPX")
include(CMakeTestASMCompiler)
set(ASM_DIALECT)

./cmake/Platform/C64.cmake:

MESSAGE("-¤# Building for Commodore 64 platform! #¤-")

#this does not seem to work
#SET(CMAKE_ASM_TMPX_COMPILER "${CMAKE_BINARY_DIR}/tools/TMPx_v1.1.0-STYLE/linux-x86_64/tmpx")

set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)

Solution

  • After checking a bit closer using CMake's 'MESSAGE()' commands, I think i've got at least the answer to my first question ; ./cmake/CMakeDetermineASM_TMPXCompiler.cmake is the first thing to be run (and only at the very first 'cmake .') when e.g

    PROJECT(test001 ASM_TMPX) #asm_tmpx denoting the <lang>_<dialect>
    

    is set in the ./CMakeLists.txt

    In my case, the run order at 'cmake .' appears to be:

    1. ./cmake/CMakeDetermineLANG_DIALECTCompiler.cmake (runs only at initial 'cmake .')
    2. ./cmake/Platform/CMAKE_SYSTEM_NAME.cmake (runs at every 'cmake .')

      Note: This relies on e.g SET(CMAKE_SYSTEM_NAME "C64") having been set in CMakeLists.txt; CMake will then look for e.g ./cmake/Platform/C64.cmake

    3. ./cmake/CMakeLANG_DIALECTInformation.cmake (runs at every 'cmake .')

    4. ./cmake/CMakeTestLANG_DIALECTCompiler.cmake (runs only at initial 'cmake .')

    So i'm guessing CMakeDetermineLANG_DIALECTCompiler.cmake is where any and all detection of the location of the assembler executable , and any extraction of assembler version, it's commandline arguments, etc. etc., could and would need to be performed.