Sorry for my gaps in responding to this... life is busy at the moment! But I think I can help.
I think creating a shell script that does what you want is the right approach, and you can tell CMake to run it automatically every time your application is built. The general approach is something like this:
Code:
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/<MyApplication>_with_mods.dsk
COMMAND <path to your script here plus any arguments>
DEPENDS <MyApplication>_APPL
COMMENT "Creating disk image with MOD files"
)
add_custom_target(create_mod_file_disk_image ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/<MyApplication>.dsk)
add_dependencies(<MyApplication> create_mod_file_disk_image)
Replace any instance of
<MyApplication> with the name of your project that you pass into add_application. That tells CMake the disk image generated by your script is dependent on the disk image created by Retro68 (and
<MyApplication>_APPL is the name of the task that generates it), and that the entire project is dependent on this new task you're defining that calls your script and generates your disk image, and so that should run your script every time you build.
I recommend setting up your script so that it takes as one of its arguments the path of the disk image you want to generate, so that you can define it in your CMake file and make sure it's consistent, since CMake needs to know it's full path in order for all of this to work.
You can take a look at
add_application.cmake in Retro68's toolchain directory to see what
add_application does and how it sets everything up.
I think CMake is not the easiest build system to learn, and in spite of being an experienced developer I struggled with it and bounced off of it for years. I wish a better designed one with more clear syntax won out in the end. But at least CMake is very capable.
As for detecting when you're compiling with Retro68....
There's a number of options. You check the compiler is gcc or clang with
#ifdef __GNUC__, which both compilers will define. If you need to check for clang specifically, you can look for
__clang__.
You can also check if the current compiler is CodeWarrior (assuming you're using that on a classic mac) with
#if (defined __MWERKS__ || defined __CWCC__). I think (but am not 100% sure) you can detect Think C / Symantec's compiler by looking for
THINK_C. And I think MPW is
MPW_C.
You can also just add this to your CMake file:
Code:
add_compile_definitions(RETRO_68)
and then use
#ifdef RETRO_68
Hopefully that gets you what you need!