It is currently Thu Dec 14, 2017 1:10 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Nov 28, 2014 8:12 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2982
Location: Tampere, Finland
Here's something I came up with a couple of days ago. I doubt it will be wildly popular, but I might as well throw it out there. :)

It's a toolchain file for cc65 (the C compiler and assembler) for CMake. CMake is a build system that can generate build instructions for other tools like Ninja and make (Makefiles). The benefit of using CMake over something like Makefiles is that the scripts are much easier to write, and much more cross-platform (CMake takes care of the platform differences, for the most part).

This thing can also handle implicit dependencies (if file A includes file B, when B changes, A will get recompiled) as long as the target build system supports make-style dependency files (Ninja does).

I recommend using Ninja together with this.

I did not test this very much, so there might be some problems, but it seems to work.

Code:
# CMake toolchain file for cc65
# This is largely a result of experimentation, so some things may be done
# suboptimally/wrong. Some compilation options/CMake features may not work.
# Some generators will also not work (like MSVS). Ninja and Makefiles have
# been tested to work.
# What is supported: C, assembly, static libraries

set( CMAKE_SYSTEM_NAME Generic )

macro( __compilerCc65 lang )
    set( CMAKE_${lang}_COMPILER cl65 )
    set( CMAKE_${lang}_COMPILER_ID cc65 )

    # We cannot run tests for the cc65 compiler, because of cross-compilation,
    # so force the compiler tests to passed.
    set( CMAKE_${lang}_COMPILER_ID_RUN TRUE )
    # Don't know if these are necessary.
    set( CMAKE_${lang}_COMPILER_ID_WORKS TRUE )
    set( CMAKE_${lang}_COMPILER_ID_FORCED TRUE )

    set( CMAKE_DEPFILE_FLAGS_${lang} "--create-dep <DEPFILE>")
    set( CMAKE_${lang}_VERBOSE_FLAG "-v" )
    set( CMAKE_${lang}_FLAGS_DEBUG_INIT "-g" )
endmacro()

__compilerCc65( C )
__compilerCc65( ASM )

set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm )

# \todo Not sure why CACHE is required here. Seems like something empties
#       this variable after this script has ran...
set( CMAKE_AR "ar65" CACHE PATH "archive" )

# \note Need to delete the old file first because ar65 can only add files
#       into an archive (or remove named files, but we don't know the names).
set( CMAKE_C_CREATE_STATIC_LIBRARY
    "<CMAKE_COMMAND> -E remove <TARGET> "
    "<CMAKE_AR> a <TARGET> <LINK_FLAGS> <OBJECTS>"
)
set( CMAKE_ASM_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY} )

An example CMakeLists.txt could be something like this:
Code:
cmake_minimum_required( VERSION 3.0 )

project( MyProject ASM )

set( sources
    test.s
    something-else.s
)

add_executable( MyExecutable ${sources} )

set_target_properties( MyExecutable
    PROPERTIES
        OUTPUT_NAME blah.nes
        COMPILE_FLAGS "-t none -v -g --cpu 6502x --asm-define NODEBUG"
        LINK_FLAGS "-t none -C ${CMAKE_CURRENT_SOURCE_DIR}/blah.cfg"
)

add_custom_command could be used to bring in asset processing commands and so on.

And to use the toolchain the spell is something like (last part depends on where your build directory is):
Code:
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=cc65-toolchain.cmake ..


EDIT: Modified the toolchain file slightly.

EDIT: Seems like dependency handling doesn't work with the Makefile generator, for whatever reason. CMake is simply not adding the "--create-dep" switch to the compilation. It works with Ninja, though.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group