Trying to make CLion working with CMake and Cocos2DX

I’ve read in a lot of topics that some ppl are trying to compile with cmake a clion, but I don’t know if someone has compiled successfully under Windows.

For making a point on this situation I want to enumerate my steps.
Maybe somebody can help with all these steps.

  1. Downloaded latest build: cocos2dx v3.6

  2. Downloaded MinGW from http://www.mingw.org/

  3. Downloaded also PKG Config and installed using this guide http://www.gaia-gis.it/spatialite-3.0.0-BETA/mingw_how_to.html

  4. Opened DOS Prompt and run setup.py

  5. Double checked if all external deps are ok (also using download-deps.py)

  6. Create a new project, the simple helloworld with:

    cocos new Test -p com.test.mytest -l cpp -d mydir

  7. Run CLion

  8. Settings up with MinGW Home, bundled CMake v3.2.2, bundled GDB 7.8 (the toolchains seems ok)

  9. I don’t know if in CMake options I have to set other.

  10. Selected Import Project from Sources

  11. Selected the top folder mydir the first one with CMakeLists.txt

  12. It starts to running the process, but suddenly it return this error:

**Error:Could NOT find GLEW (missing: GLEW_INCLUDE_DIR GLEW_LIBRARY)**
  1. Now I can edit the cache variable in CLion and manually set the paths, in this way I can manually set all the “include” and “prebuilt” library paths of the required external

  2. This externals requested are: chipmunk, freetype2, glfw3, jpeg, tinyxml2, webp, zlib, gles, mp3decoder, ogg, vorbis, openal

  3. And last but not least the unzip library, but this library seems to be old, infact I got an error for looking at this function unzGoToFirstFile2 that doesn’t exists in this library
    In the cocos2d-x-3.6 folder in CMakeLists.txt I can read this:

"Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS"

I can’t enable USE_PREBUILT_LIBS because I’m using MinGW, I’ve tried to download a recent version on minizip but it seems not to working.

So I’m stucked, even if I have manually set all the paths I’m blocked with unzip error.
The exact error is:

Error:Syntax error in cmake code at
  C:/Program Files (x86)/CLion 1.0.1/bin/cmake/share/cmake-3.2/Modules/CheckLibraryExists.cmake:49
when parsing string
  Looking for unzGoToFirstFile2 in C:\mydir\cocos2d\external\unzip
Invalid escape sequence \S

I thought it was an error of some paths that doesn’t work, but I’m using the standard helloworld templates.
I thought also that could be an error in pkg-config for finding the right package, infact I’ve tried to install it manually in mingw, but I don’t think this is the problem.

So please, if somebody can help me resolving this we can make compiling under Window with CLion possible :smile:

Thank you.

1 Like

I haven’t tried it on Windows.

I tried it on Mac and Linux (with cocos2d-x from github) and it works Ok.

1 Like

I want use clion,but get many error like Levis. please help us make it work.thank you!

Today I’ve tried installing MinGW W64 and configured CLion with this, even if I think that cmake, gcc and g++ are the same of mingw32.
Anyway no luck, same errors.

So I think the problem is mainly in CMakeLists.txt created by cocos team.

I’ve tried also to create a new project with a cmakelists created by CLion including all the scripts, but I think it’s not the correct way because CLion don’t know how to build and found various bad declarations.

I think it’s something to do with paths and some prebuilds not correctly working under windows.

@Levis

Cocos hasn’t prebuilded libraries for use with gcc (mingw, cygwin, msys etc…).

So to resolve this problem someone should make these steps:

  1. Install all dependencies. By hand, or with MSYS2 package manager as described in the wiki. List of required libraries to install for windows you can get from cocos sources (from the list of prebuilded libraries for MSVC). But look carefully to the versions of libraries. For ex MSYS2 contains chipmunk 7.0.0, but cocos works with 6.2.2, these libraries should be installed by hand.

  2. Test the cocos2d-x build itself (without any IDE). If you will use MSYS2, then you should install and use cmake from their package. Run it something like cmake -G"MSYS Makefiles" or cmake -GNinja, after build check that test executables actually runnable.

  3. Only after that you can try use CLion or something other…

Some posts (somethimes outdated, but may help):

Thank you @vovkasm for this infos.
I’ll try soon the setup with MSYS2 and leave a feedback.

Just to understand better, but in this way I have to create a CMakeLists.txt myself?

  1. Build the cocos2d-x with CMakeLists.txt from sources :slight_smile:
  2. For you project (after ensure that cocos builds normally) you can use CMakeLists.txt provided by the generated project (but I don’t test this…). I use my own CMakeLists.txt file (only for desktop platforms). I can share it by request.

I think I’ve made some progress, I’m reading the setup for QT creator that you linked

Installed MSYS2, with pacman installed:

mingw-w64-x86_64-cocos2d-x-git
mingw-w64-x86_64-qt-creator
mingw-w64-x86_64-cmake 

Then I tried to open the Cocos Project with generated CMakeLists.txt and tried to build.
I’ve manually edited CMakelists for including all my .cpp and .h files:

set(GAME_SRC
  Classes/AppDelegate.cpp
...
...
...
  ${PLATFORM_SPECIFIC_SRC}
)

set(GAME_HEADERS
  Classes/AppDelegate.h
...
...
...
  ${PLATFORM_SPECIFIC_HEADERS}
)

I got some errors and fixed installing these:

mingw64/mingw-w64-x86_64-openal 1.16.0-2
mingw64/mingw-w64-x86_64-libvorbis 1.3.4-1
mingw64/mingw-w64-x86_64-glfw 3.1-1

Then I installed also the older version of chipmunk, because I got some errors in CCPhysicsBody.obj, manually downloading this:

mingw-w64-x86_64-chipmunk-6.2.1-1-any.pkg.tar.xz

Putting in MSYS2\var\cache\pacman\pkg and then installed with pacman -U

The compiling process continues for 70-80% of all cocos libs, some little warning but nothing special.

Now I’m stucked at this:

\myapp\cocos2d\cocos\platform\desktop\CCGLViewImpl-desktop.h:32: error: glfw3.h: No such file or directory
     #include "glfw3.h"

This header file is located here:

\myapp\cocos2d\external\glfw3\include\win32

But I think that path was not found correctly.

Could be a problem in CMakeLists? Maybe some FindPackages functions doesn’t work properly.

From the guide written by @Martell he uses this custom: https://github.com/martell/cpp-template-default/blob/master/CMakeLists.txt

It’s quite different from the recent CMakeLists generated by cocos2dx 3.6, I don’t know if yours CMakeLists will go better, I’m just discovering this new world :stuck_out_tongue:

BTW: I Forgot to say that Run CMake is ok, without errors.

Ok maybe I’ve done another progress.

When I run CMake I’ve not seen that pkg-config was not installed.

So I run:

pacman -S mingw64/mingw-w64-x86_64-pkg-config

And now it found GLFW3.

Now it’s continuing building, I’ll keep you updated…

@Levis

  1. Paths inside the \myapp\cocos2d\external folder should not be found. It’s because these libraries built with MSVC compiler. But you will use GCC compiler (mingw is a port of GCC that can generate windows executables) with other object files format.

  2. glfw3 should be found somewhere inside msys folders. If not, something is wrong, but I can’t say what specifically from the information you provided.

  3. Cocos CMakeLists.txt files print the information about found libraries and paths when you run cmake tool. Can you see where its found GLFW (or not found)?

When I found some spare time (in a day or two), I try test cocos with MSYS2 again (I stop doing that after upgrading chipmunk pacakge).
Also I will try to prepare the sample project that we use in our team.

Ah, ok :smile:

Really thank you, maybe today I’ll try to finish this build :stuck_out_tongue:
If so I’ll keep the community updated, writing the last steps for building also in CLion… (ahhh long way :smile: )

Anyway really thank you for answering me.

Now the build seems ok, but during linking libs got this:

In my project I’m using rapidjson, but I don’t know if it’s related to this or to other things, now I’ll try to rebuild all with an helloworld project maybe it’s simpler and I don’t get this error.

Checked also if it was tinyxml2 prob, I’ve installed this:
mingw64/mingw-w64-x86_64-tinyxml2 2.2.0-1

I’ve tried also with a standard helloworld project, and got this:

Maybe something else I’ve forgot to install?

Tried to reinstall from zero all with msys2 and all libs i686, so not x64.
After all the build and compile I got the same identical error as shown above.

For now I give up, no other ideas :frowning:

Hello. I’m newbie in cocos2d programming. I coming from as3 development and always used Intellij Idea IDE. And I became very happy when discovered that post about making cocos2d work with CLion. It is very sad for me that it doesn’t work yet, but you did good job. I’m very appreciated for all you have done.

I’m a newbie in C++ (and in English too :smile: ) and I found the following solution. You can include tinyxml2.cpp and tinyxml2.h in CMakeLists.txt

elseif ( WIN32 )
set(PLATFORM_SPECIFIC_SRC
  proj.win32/main.cpp
  Classes/tinyxml2.cpp
)
set(PLATFORM_SPECIFIC_HEADERS
  proj.win32/main.h
  Classes/tinyxml2.h
  proj.win32/resource.h
)
endif()

mingw doesn’t have _get_wpgmptr so you can do this in CCFileUtils-win32.cpp

static void _checkPath()
{
    if (0 == s_resourcePath.length())
    {
        /*WCHAR *pUtf16ExePath = nullptr;
        _get_wpgmptr(&pUtf16ExePath);

        // We need only directory part without exe
        WCHAR *pUtf16DirEnd = wcsrchr(pUtf16ExePath, L'\\');

        char utf8ExeDir[CC_MAX_PATH] = { 0 };
        int nNum = WideCharToMultiByte(CP_UTF8, 0, pUtf16ExePath, pUtf16DirEnd-pUtf16ExePath+1, utf8ExeDir, sizeof(utf8ExeDir), nullptr, nullptr);

        s_resourcePath = convertPathFormatToUnixStyle(utf8ExeDir);*/

        s_resourcePath = YOUR_PATH_TO_RESOURCES_DIR;
    }
}

for Clion something like this “c:/Users/[USERNAME]/.clion10/system/cmake/generated/be9fed93/be9fed93/Debug/bin/Resources/”

It’s awful, but it works for me.

Thank you @romsvm I’ll try as soon as possible this solution!

Ok now I’ve solved almost all the problems.

Thanks @romsvm for the suggestion on tinyxml and resources!

I’ve only some little problems when I use resources in subfolders, maybe some other tweaks and I think it is ok.

I have written a little guide with all the steps, when this last step is resolved I’ll make a post, so also other ppl can compile with CLion!! YEAH! :smile:

Debug works too!!!