Search code examples
iosmakefilecmaketheos

Can CMake Generate Theos Makefiles?


I've created an iOS project using Theos. Its Makefile format is very simple - basically just a list of source files and libraries/frameworks. All I would need CMake to do is update the source list and libraries in this file. Can CMake do this?

This is my current Makefile:

ARCHS=armv6
include $(THEOS_MAKE_PATH)/common.mk

APPLICATION_NAME = TestApp
TestApp_FILES = main.m gltest.cpp testAppDelegate.m ES1Renderer.m EAGLView.m
TestApp_FRAMEWORKS = UIKit CoreGraphics OpenGLES QuartzCore

include $(THEOS_MAKE_PATH)/application.mk

It seems to me that CMake can't generate anything that isn't a standard Unix Makefile, IDE project, etc. I have the feeling that I would need to write my own custom CMake toolchain file to do everything that Theos does for me.

It would be OK if CMake just dumped its source list into a text file, and then I would edit it from there using some other automation tool/script.


Solution

  • I was able to get CMake to generate the Makefile using the FILE(WRITE) command:

    file(WRITE ${MAKE_FILE}
         "ARCHS=" ${ARCHS} "\n"
         "APPLICATION_NAME = " ${PROJECT_NAME} "\n"
         ${PROJECT_NAME} "_FILES = " ${IOS_SOURCES} "\n"
         ${PROJECT_NAME} "_FRAMEWORKS = " ${FRAMEWORK_DEPS} "\n\n"
         "include ${THEOS_PATH}/makefiles/common.mk\n"
         "include ${THEOS_PATH}/makefiles/application.mk"
         )
    

    I also made an empty toolchain so that CMake didn't spend time configuring compilers for my system.

    set (CMAKE_SYSTEM_NAME Generic)
    
    # Just point to anything that exists. 
    # We don't need CMake to generate proper build files.
    set(CMAKE_C_COMPILER ${CMAKE_CURRENT_SOURCE_DIR})
    set(CMAKE_CXX_COMPILER ${CMAKE_CURRENT_SOURCE_DIR})
    
    # Skip the platform compiler checks
    set (CMAKE_CXX_COMPILER_WORKS TRUE)
    set (CMAKE_C_COMPILER_WORKS TRUE)