CMake GUI to generate iOS project

Hey,

Has anyone sucessfully used cmake for Xcode to generate ios? (with the CMake GUI tool)
I’ve tried to use the guide and added CMAKE_TOOLCHAIN_FILE=…/cmake/ios.toolchain.cmake
I’ve also tried to just directly add the path to the ios.toolchain.cmake in the engine folder. but it seems like it always creates a Mac project. Can anyone help me ?

Btw is it already possible to have both Mac and ios targets in a cmake generated project, as far as I’ve seen there it wasn’t possible in the V3 branch few months ago, but maybe this has changed over the time?

Thanks!

@drelaptop can help. @drelaptop do we need more docs?

for may last question about mac and ios in one project, probably still not possible:


for the last question, I think you are right, because the cmake official have replied:

It’s not possible and likely never will be. CMake’s code model supports only one target platform per build tree. Things like find_library find only one result file.

and no further response for this issue.


Today using the latest v3 branch, execute:

cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake

I can generated iOS project success, after executing this cmd, we will see the log like

Toolchain using default iOS SDK: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk
...
-- using toolchain file: /Users/laptop/2d-x/cmake/ios.toolchain.cmake
...
-- CMAKE_BUILD_TYPE: Debug
-- It appears you are cross compiling for IOS with AppleClang
...

What’s the logs like when you generated iOS project on CMake GUI? @Sleicreider .

could you try to use cmd line to generated iOS project. if success by cmd line, but failed on CMake GUI, I will thought some wrong operation existed.

docs have shown the mainly feature about how to use cmake for cocos2d-x at website

http://cocos2d-x.org/docs/cocos2d-x/en/installation/CMake-Guide.html

as for some developer want to custom the cmake script, he or she can refer to the cmake official docs, we use no
special feature different from the cmake official. so I think we didn’t need to write more docs about cmake for now. @slackmoehrle

Ok. If there are more I can help.

I think cmake with iOS need more tutorial.
It’s not friendly to use.

For example:

Add cocos2dx prebuilt project to another exist project

I don’t have idea to fix this error, after I trying to add ios-build project to another project.

Did you compile the prebuilts? Using cmake or cocos command?

No.
I only use this to create cocos2dx prebuilt project.

cmake … -GXcode -DCMAKE_TOOLCHAIN_FILE=…/cmake/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR

After add prebuilt project to another project, use Xcode run button to build.

You need to use cmake to compile though if you used cmake to build the libs, no?

If you use prebuilt libs created before, you need add this option in another project

 -DUSE_COCOS_PREBUILT=ON

Docs at cocos2d-x/cmake/README.md said


Example

This is an example of building c++ libs once, and use them in different c++ projects.

cmake ...... -DGEN_COCOS_PREBUILT=ON

Change option GEN_COCOS_PREBUILT and use instead USE_COCOS_PREBUILT to use prebuilt in the same project

cmake ...... -DGEN_COCOS_PREBUILT=OFF -DUSE_COCOS_PREBUILT=ON
make TemplateCpp
open bin/TemplateCpp.app

Add -DUSE_COCOS_PREBUILT=ON to use prebuilt libs in another cmake build.

cmake ...... -DUSE_COCOS_PREBUILT=ON
make TemplateCpp
open bin/TemplateCpp.app

Finally I create a new project with cmake prebuilt project.

This is how I do:

1.create new project "PrebuiltTest"

10

2.use terimal : cd PrebuiltTest
3.use terimal : mkdir build && cd build
4.use terimal : cmake .. -G Xcode -DIOS_PLATFORM=SIMULATOR -DCMAKE_TOOLCHAIN_FILE=../../cocos2d-x/cmake/ios.toolchain.cmake -DGEN_COCOS_PREBUILT=ON
5.build the Xcode project

6.after finish build, use terimal : cmake .. -DGEN_COCOS_PREBUILT=OFF -DUSE_COCOS_PREBUILT=ON

@drelaptop I think this is what the tutorial I needed.

2 Likes

Congratulations and thanks for sharing this with us, GEN_COCOS_PREBUILT / USE_COCOS_PREBUILT are the key to use prebuilt libraries, you have gotten them.

Awesome. Let me make sure we document this.

1 Like

Please make it quick.

I’ll see what I can do :slight_smile:

1 Like

I’ve tried this again.
This time i managed get the toolchain running with the cmake gui, by adding the toolchain file in the configure step for cross compilation.

I still have some issues with the required code signing since it doesn’t seem to find my provisioning profile in the Library profile cache path and I somehow can’t find a cmake option for automatic manage signing (which i would use for the non cmake project)

if(IOS)

    set(SIGN_ID "iOS Developer")
    set(TEAM_ID "myteamid")

    #https://stackoverflow.com/questions/40664125/cmake-and-code-signing-in-xcode-8-for-ios-projects

    SET_XCODE_PROPERTY(${APP_NAME} CODE_SIGN_IDENTITY ${SIGN_ID})
    SET_XCODE_PROPERTY(${APP_NAME} DEVELOPMENT_TEAM ${TEAM_ID})
    SET_XCODE_PROPERTY(${APP_NAME} PROVISIONING_PROFILE_SPECIFIER "xxxxxxxx")


endif()

This above seems not to work for the provisioning profile, therefore I currently have to manually tick Automatic signing everytime I execute cmake, which is really annoying. If anyone has knows how to handle the code signing stuff please help :slight_smile:

Additionally I have some issues with adding external frameworks like SDKBOX to the project via cmake.
I’ve tried to play around with t target_link_libraries but it somehow doesn’t find the .framework.

Let me know if anyone has any idea of those 2 issues.

@drelaptop might have ideas and we could document.

firstly, you need find_library to found the libs, and then link it. you can refer to this file, it found system libs for cocos2d.

https://github.com/cocos2d/cocos2d-x/blob/v3/cmake/Modules/CocosConfigDepend.cmake

didn’t know it clear for now, may research it next.