Multithreaded compile on Windows

I’d ask someplace that supports Visual Studio or msbuild.

I’m having an issue getting a multithreaded compile to work on Windows. I’ve checked out the 3.13.1 tag from github and everything compiles successfully, it’s just that it only ever uses one thread to do it and it takes forever.

I’ve tried adding the /MP option to the .vcxproj files with no success. Also built directly with msbuild using /m to no avail. Can anyone provide some assistance with this?

Maybe I can make my question simpler, do other people here compile on Windows and have multithreaded compiling working?

I assume from your dismissive response it’s expected that it just works out of the box, or you don’t know what multithreaded compiling is.

It’s not dismissive. You are asking about a 3rd part tool. We write a game engine. Build settings for projects are best asked on Microsoft forums. Now, if you meant to say you can use multithreaded compiling in other projects but NOT with Cocos2d-x projects, then I can ask our engineering team to take a look, but it will be a low priority for them.

Let’s not be snarky in our replies. It doesn’t help.

Ok, any snarkiness aside I still think my question is valid and could be answered here for the following reasons.

  • Cocos2dx ships with CMake and provided configuration which is used to generate project files to facilitate compilation
  • The project files are the very place where options for multithreaded compiling must be set
  • Multithreaded compilation is the norm and would be expected to work for default generated project files
  • There are (I assume) a significant number of people who build on Windows and would have information on whether or not this works

I’m not looking to be spoonfed, I just want to know at a minimum if it works for others by default or not. Beyond this my assumption was there was a CMake parameter that I was failing to pass in or something basic like that.

There is a lot of work being done with CMake now in our GitHub repo. @drelaptop is working on this. I will ping him and ask him to review this thread.

Much appreciated. I’ll also continue to look into this and if I work out a solution I’ll update this thread :slight_smile:

this PR solved cmake support win32 and prebuilt libs, multithreaded compile also supported, set option is

# multi thread compile option
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

when compiling I can see the monitor like this, multithreaded compile works well:
msvc%20compile

this discuss is the cmake progress, PR 18683 will be merged in next week if everything goes well, and cmake have many changes in recently, I will appreciate if you would like to try to use the cmake build and give your feedback

Thanks! That’s some great info, I’ll give that a go and provide any relevant feedback.

I’ve had a go at this and had success adding the suggested cmake SET line to cmake/modules/SetCompilerOptions.cmake. This has enabled multithreaded compiling and it’s now working, although the /m msbuild option fails to regulate the number of jobs. I know that /MP and /m are for slightly different things so it might be correct.

As a suggestion it would be good to expose a flags cmake option at the command line so custom flags could be added easily. e.g.
cmake -DMY_CXX_FLAGS="/MP"
then in SetCompilerOptions.cmake
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} ${MY_CXX_FLAGS”)

@drelaptop, I pulled down the version from your PR but I got stuck building with the build complaining I didn’t have the vs2010 build tools installed, but I think this error is also present on the HEAD of v3 too. This doesn’t happen on 3.13.1 so there must’ve been some changes made in the meantime.

thanks for your suggestion, I will consider to add this feature in the next cmake changes

I tested the cmake build on win32 with Visual Studio 2017 Installed using tools 140/141, no errors occurred except TemplateLua project. what’s your build tools version and VS version, and could you give the error log?

this is I tested

cmake ..\cocos2d-x\ -T v140
cmake --build .
cmake ..\cocos2d-x\ -T v141
cmake --build .