Home | Documentation | Atomic Chat | Github

Platform-specific build using only cpp api


Hi guys.
I have been searching for some good alternative to cocos2d-x (working with it is a mess sometimes) in case of transparent c++ development, and AGE looks really cool. Actually I have a very thin framework in c++ for game logic implementation (ecs approach + some helpers) and I want to use it for all core game logic and AGE for all other things (scene graph, networking, ui, etc). The main point is I can create cmake based project with AGE as static library and be happy with development under linux. But I totally have no idea how to ship it to some android/ios device. Atomic editor do it automatically using some internal magic. So could you tell please, can I reuse that logic somehow to install my app on the mobile devices? Or maybe there’s a dedicated approach for such things? Thank you a lot!


Okay, do you at least have plans for something like that?
There’re some thoughts about it in Just Code roadmap. Actually the way how it is handled in cocos2d-x is not very convenient. Just imagine you are making cross-platform game. All core game logic is implemented in cpp. Each platform has its own dev environment (xcode, android studio, visual studio, make), and if you want to keep all platforms compilable, you should add new files (remove unused files) to each platform-specific project files, configure compilation flags N times and so on. Instead there should be better to have some project generator for each platform, so you can configure source files/directories, header search paths, resources directory and others, and it will generate full project for each ide (like cmake does, but it cannot handle all actual platforms with their specific stuff, like android). I’m working in one gamedev studio, we make mobile games for ios/android/win mobile mostly, we have such tool, it can generate projects for iOS, tvOS, android studio, visual studio and cmake. I can say that it is absolutely awesome when you can just type ./build_tool apple ios development debug, and it will generate iOS project (for example). Maybe I can help you with this task a bit.
@JoshEngebretson AFAIK you have some experience in this field (link), and I’m sure you have some thoughts about it.
What do you think guys?
Thank you!


At least for android you are supposed to crosscompile. It produces apk which you can ship. Follow these instructions to set up android build in c+±only project:

  1. Get Android.cmake toolchain from Urho3D and put it to ${CMAKE_SOURCE_DIR}/CMake.
  2. Get android build files and put it to your CMAKE_SOURCE_DIR/Android.
  3. Put macro i wrote somewhere in your CMake build scripts:
    if (NOT ANDROID)
        message(ERROR "Can not add android target in non-android build.")
    endif ()

    cmake_parse_arguments(PARAM "" "DEBUG;TARGET;SOURCE_DIR" "RESOURCE_DIRS" ${ARGN})
    # Target output

    # Copy gdbserver
    if (PARAM_DEBUG)
        string(REPLACE "armeabi" "arm" NDK_ANDROID_ABI "${ANDROID_ABI}")
        file(COPY ${ANDROID_NDK}/prebuilt/android-${NDK_ANDROID_ABI}/gdbserver/gdbserver DESTINATION ${LIBRARY_OUTPUT_DIRECTORY})
    endif ()

    # Link game assets in android assets dir
        get_filename_component(BASENAME "${I}" NAME)
        symlink(${I} ${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/assets/${BASENAME})
    endforeach ()

    # Link build files and dirs except for assets
    foreach (I ${ANDROID_BUILD_FILES})
    endforeach ()
    # Link android-exclusive assets if any
    foreach (I ${ANDROID_BUILD_FILES})
        symlink("${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/assets/${I}" "${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/assets/${I}")
    endforeach ()

    list(APPEND SOURCE_FILES "${CMAKE_SOURCE_DIR}/dep/AtomicGameEngine/Source/ThirdParty/SDL/src/main/android/SDL_android_main.c")
    add_library(Blocktastic SHARED ${SOURCE_FILES})
    add_custom_command(TARGET ${PARAM_TARGET}
        COMMAND "${ANDROID_SDK}/tools/android" ARGS update project -p .
        COMMAND ant ARGS debug
        COMMAND "${ANDROID_SDK}/platform-tools/adb" ARGS install -r "${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/bin/${CMAKE_PROJECT_NAME}-debug.apk"
        COMMENT "Building android apk"

  1. Make sure ANDROID_SDK and ANDROID_NDK environment variables point to SDK and NDK (i use NDK v13b).
  2. Setup your android target (main game executable):
        TARGET Blocktastic
        SOURCE_DIR Android
        DEBUG "${DEBUG}"
else ()
    add_executable (Blocktastic ${APPLICATION_SYSTEM} ${SOURCE_FILES})
endif ()
  1. Run cmake with -DANDROID=1 -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_ABI=armeabi -DCMAKE_TOOLCHAIN_FILE=CMake/Android.cmake and build it.

If you have it all done right after building your project it should be sent to connected device as well. If you do not wish to have built application uploaded to device remove add_custom_command() from end of the macro.