New project creating with cocos v4 (cmake for everything)

@kerryk you can modify it your self, it just adds one line. Not too complex.

v4->v3 why need it?

We discuss this before and i thought you kind of agreed but let me repeat )

  1. Every of our projects is very complex. It’not just cocos. We have build settings, phases, embeded frameworks, pods with 15+ items, linker flags, header paths, user header paths, preprocessor macros, capabilities, fastlane setup, watch target, stickers target, mac targets, custom mac targets for helper staff etc. It’s really hard to move all those for all projects and not miss something. And each project is unique. All other SDK are added to existing projects easily with some easy way. Why with cocos we have to migrate the whole project to it? It makes more sense for us to learn v4->v3 and maybe write a script to do it for us to all projects.

  2. Each project has feature branches. Some have 2-3 of them. Making such a big change would probably break our merging ability too.

I don’t disagree with v3->v4 ) But lets also give the same love to v4->v3 for those complicated projects.

@kerry let me make it more clear. About v4->v3, did you mean that you already have an project that using cocos2d-x v3, then you want to upgrade engine to v4. Is it right? If so, then @coulsonwang’s PR does the thing, it will generate Xcode project only include engine codes, you just need to use it to replace the v3’s engine Xcode project.

yes exactly that! ))) i need just engine code, no cmake not nothing in it. and then i remove old v3 from existing project, replace with new v4, add manually any cocos framework/user header paths etc and all good! -> this shouldnt take longer than 10min max ideally. And all is left is to fix breaking API changes issues and bring back custom cocos modifications.

@kerryk add guide about how to use cmake and cocoapods.

Thanks @coulsonwang this is very kidn of you :slight_smile: will give it a shot as soon as im allcoated some time but looks like all is clear. will let you know!

Looking forward to this, it will be a life-saver!

We’re also on v3 and have a lot of project-specific setup, build phases, dependencies and custom makefiles on Android making it not easy to move over to a new v4 project.

Have you tried @coulsonwang’s guide?

I didn’t see this actually, thanks.
I’ll try it out once v4 reaches a release version

not yet, we are highly focused on ios 13 release. ) I hope that as soon as this is done, i can re-focus on v4 instructions test. will keep you up to date.

Hi! I am trying your guide but i am a bit stuck with cocos2d.h not found. What i did:

  1. I had working cocos2d-x 3.17 project.
  2. I removed reference to cocos2d_libs and removed the cocos2d folder completely from project directory.
  3. I checked out cocos2d-x v4 branch inside my project directory and run all necessary command and cmake.
  4. I linked v4 generated project with existing v3.17 project and added cocos2d dependency and link with libraries. (screenshot)
  5. i added cocos directory as search path. (screenshot)

I know i have not did all the steps yet for the external libraries etc, but i think up to what i did, the cocos2d.h should have been found.

Any ideas what i am doing wrong? )

EDIT: ok solved my own issue, User Header Search Paths must be said on Target and not Project. Maybe make that clear in guide )

I have spotted 2 issues with the guide.

  1. Tiff does not exist. So we dont need to add it in Other Linker Flags. your_v4_path/cocos2d-x/external/tiff/prebuilt/ios/libtiff.a

  2. If you try to add “-framework Metal” in other linker flags as specified by guide, it does not work. Maybe you mean add Metal.framework in Frameworks, Libraries and Embedded Content?

And a noob question about CMake. If i overwrite cocos2d-x source files, when CMake runs, does it overwrite my chagnes? Any way to disable CMake? I dont need it anymore now that project is added.

@coulsonwang please take a look.

CMake only take effects if you modify CMakeLists.txt. If you don’t want to use CMake, then you don’t have to modify CMakeListx.txt and don’t use cmake, you should modify the Xcode files yourself.

Ok thanks. And another issue i faced with CMake, if i change the original cocos2d-x folder path, CMake keeps creating files in the old path. Is this something that can be fixed? Maybe some path to be updated somewhere? This is also really troublesome in case i give someone or the project if project is in git and each guy has its own path. We need to set it as a path relative to project. I can provide video demonstrating the issue if needed.

Yep, please provide a video or some picture. I don’t quite understand the issue.

@kerryk you can define library or header search paths at the project level, then use $(inherited) in the target build settings to use these search paths in the search paths of the project targets.

If -framework Metal no works, you can reference step 7, add the Metal.framework to Link Binary With Libraries section.

corresponding updates

@coulsonwang f you try to add -framework Metal other linker flags, it will go to next line because of space. Here is video demostrating the issue. I use xcode 11. In case im doing everything correct, i suggest we update v3->v4 doc.

https://discuss.cocos2d-x.org/uploads/default/original/3X/9/c/9c259112474a054b66d1155f914728b146a20925.mov

@zhangxm here is the video showing the cmake/xcode issue.

  1. I run cmake command.
  2. I rename cocos2d-x folder. This is equivalent as moving it to a different path in case you move your project or git clone at new path.
  3. I open cocos2d_libs xcode project.
  4. After 1-2 seconds, the cocos2d-x folder is re-created with some contents in it.

https://discuss.cocos2d-x.org/uploads/default/original/3X/8/d/8d69910d9711f280c14b877f6dd71f085292e738.mov

What’s happen to this? how it does’t work?

@coulsonwang don’t know, maybe it’s xCode 11 only issue ) I tested on Xcode Version 11.0 (11A420a). Anw your workaround of using Link Binary with Libraries works just fine so update guide to use that one.