[CMake] MinGW Makefiles generator and -j

Bill Hoffman bill.hoffman at kitware.com
Sun Apr 27 10:25:18 EDT 2008


Daniel wrote:
> I am currently using the NMake generator when compiling in Windows with 
> MSVC, but I would like to use the MinGW generator so that I can use its 
> -j switch.  I am able to build everything with MinGW but the -j switch 
> doesn't seem to do anything.
> 
> I made a simple test application with the following files:
> 
> CMakeLists.txt
> =====================
> project (parallel)
> 
> add_executable (helloDemo main.cxx a_demo.cxx b_demo.cxx c_demo.cxx 
> d_demo.cxx e_demo.cxx f_demo.cxx g_demo.cxx h_demo.cxx)
> =====================
> 
> main.cxx
> =====================
> int main(int argc, char* argv[])
> {
>     return 0;
> }
> =====================
> 
> a_demo.cxx -- h_demo.cxx (just so it take a second to compile)
> =====================
> #include <cstdio>
> =====================
> 
> Then I ran cmake like this, I found that I needed to add these 
> definitions to get it to use MSVC.  This is with mingw make
> cmake -G "MinGW Makefiles" .. -DCMAKE_MAKE_PROGRAM=make 
> -DCMAKE_C_COMPILER="C:/Program Files/Microsoft Visual Studio 
> 8/VC/bin/cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/Microsoft Visual 
> Studio 8/VC/bin/cl.exe"
> 
> But when I run 'make -j4' it doesn't run in parallel.
> 
> If I configure like this (cygwin make):
> cmake -G "Unix Makefiles" .. -DCMAKE_C_COMPILER="C:/Program 
> Files/Microsoft Visual Studio 8/VC/bin/cl.exe" 
> -DCMAKE_CXX_COMPILER="C:/Program Files/Microsoft Visual Studio 
> 8/VC/bin/cl.exe" -DCMAKE_MAKE_PROGRAM=C:/cygwin/bin/make
> 
> Then when I run 'make -j4' it does run in parallel.
> 
> I should add that I tested my copy of mingw make to be sure it worked 
> properly with the -j option by creating a Makefile by hand that had 
> sleep statements.
> 
> I also tried to use the Unix Makefiles generator for my real project but 
> I got:
> PCHeader/CMakeFiles/PCHeader.dir/build.make:44: *** target pattern 
> contains no `%'.  Stop.
> make[1]: *** [PCHeader/CMakeFiles/PCHeader.dir/all] Error 2
> make: *** [all] Error 2
> 

I use gmake with MSVC and use the "Unix Makefile" generator.  I use a 
modified cygwin make that can be found here: 
http://www.cmake.org/files/cygwin/make.exe

So, install the basic cygwin with or without make.  Then put the above 
make into /usr/bin.  Then setup your environment for MSVC (vcvars.bat 
stuff).   Then use the "Unix Makefile" generator.  The -j will work 
then.  I think gmake only uses the -j if it has a unix shell, and it 
does not work from the dos shell.

-Bill




More information about the CMake mailing list