New project creating with cocos v4 (cmake for everything)

New project creating with cocos v4 (cmake for everything)
0

As far, as I understand the v4 (metal) branch correct, we all need to switch to cmake (even for iOS/mac development), because the xcodeproj aren’t included and we need to generate them -> https://github.com/cocos2d/cocos2d-x/tree/v4/cmake

This makes an update from v3 to v4 more complex, but I understand the idea behind it. The problem is, that I use (Firebase) pods and need to find a way to include them into CMakeList.txt, so that they are also included into the generated xworkspace.

Does anyone have a small tutorial how to do it? I update the cocos2d folder (from github) within my project on a regular basis, so I can test it against my code. The current breaking change blocks this, but I want to get back to the way I build the game.

Ideas are welcome. Maybe someone crossed this bridge already.

From what I’ve read, you should be able to install the pods after you generate the xcode project file, so that at least allows you to create a script to do this.

Have you tried it out? A lot of the bugs were reported (and some fixed) with cocoapods related to path and invalid field issues with cmake generated projects, like here and here, but it seems that it does work for others. The posts in those github issues show examples of usage, and it shouldn’t be any different with Cocos2d-x (hopefully).

I tried a lot, still no luck. Waiting for a solution!

We will take a look too.

Is your problem about firebase cpp sdk?
If yes, than I created issues:



You can support me:)

I think i had the exact same issues with adding firebase through cmake for ios

For existing projects, we cant just replace old cocos2d directory with new?

1 Like

There are changes in the game side files, like CMakeLists.txt, files in the proj.android folder etc. You should generate a new cocos project, then compare the files to your own and merge in the relevant changes.

Does this apply to android version? I use only ios version. It would be nice if cocos2d-x team can provide a nice video of how we can add new cocos in existing 3.17 game. We should spent our time on testing instead of trying to fix issues and run )

I remember that with alpha version of metal cocos, i could just replace old files with new and it worked.

Oh I thought you meant you’re going from v3 to v4. I don’t recall much of a difference between v4 beta releases on the game side, but you really should still compare the files. It only takes a few seconds to open up a file in a text editor and do a visual file to file comparison between old and new, and there aren’t that many files to check.

I am going from v3 to v4. I currently have 3.15

If you create a new project, the xcodeproj does not exists and you have to create it with cmake. If you want to use this everytime it’s really time consuming.

And if you use external pods, it’s even worse.

We use a looot of pods, especially ad networks. sounds like a nightmare )

Yes, but once you use CMake for v3 and v4, that becomes a non-issue though, right? The reason is CMakeLists.txt will contain all the dependencies, and that is used to generate your project files. There won’t be any need to do a file comparison on project files, since they no longer exist, and everything is in the CMakeLists.txt (well with the exception of proj.android, where you should still check if any of the files have changed).

Regarding the pods, isn’t it possible to create a script to handle the installation of the pods after CMake creates the xcode project?

I know, that v4 is a breaking update and at an early stage - but we need a better documentation for migration into v4 or many of old engine users are lost with cmake (especially iOS/macOS, because Android is already on cmake - don’t know about Windows).

// cc @slackmoehrle How can we support the cocos team for that?

I’m 100% sure there are differences in the CMakeLists.txt between v3 and v4, since I have this section at the bottom of my file to support both v3 and v4 (something changed regarding resources etc):

get_target_property(COCOS2D_X_VERSION cocos2d VERSION)
message("Cocos2d Version ${COCOS2D_X_VERSION}")

if (COCOS2D_X_VERSION VERSION_GREATER 3.17.1)
    if(APPLE)
        set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
        if(MACOSX)
            set_target_properties(${APP_NAME} PROPERTIES
                                  MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist"
                                  )
        elseif(IOS)
            cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
            set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
            set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "")
            set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer")
        endif()
    elseif(WINDOWS)
        cocos_copy_target_dll(${APP_NAME})
    endif()

    if(LINUX OR WINDOWS)
        set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources")
        cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
    endif()
else()
    if(APPLE)
        set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
        if(MACOSX)
            set_target_properties(${APP_NAME} PROPERTIES
                                  MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist"
                                  )
        elseif(IOS)
            cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
            set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
        endif()
    elseif(WINDOWS)
        cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_RES_DIR}/..)
    endif()

    if(LINUX OR WINDOWS)
        cocos_copy_res(COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
    endif()
endif()

Windows is even easier than Android. I have this in a batch file that I check into source control with my project:

IF EXIST .\win32build\ GOTO STARTUPDATE
mkdir win32build
:STARTUPDATE
cd .\win32build
cmake .. -G"Visual Studio 16 2019" -Tv142 -A Win32
@REM cmake .. -G"Visual Studio 15 2017" -Tv141

I just run the batch file after checking out of source control, it creates the win32build folder, and inside it you’ll find the project solution file to open up in Visual Studio. Done.

I’ve done the same for the xcode project, and you can even test it using the cpp-tests. If you want to see how it all works, go into /tests/cpp-tests/, create a build folder, go into it, and run the CMake project generation for mac/ios, then open that project in Xcode and run it. It should work.

For Android I do nothing. It just works. And also for developing with CLion, I only open the CMakeList file. Sadly iOS/macOS is more complicated.

yes to be honest i never used cmake ) usually we download cocos project, run download-deps, then run setup.py and then we generate new runnable project using cocos command.