[CMake] cmake and MinGW - resolution

Bill Hoffman bill.hoffman at kitware.com
Thu Feb 28 12:05:30 EST 2013


On 2/28/2013 11:56 AM, Donald Robinson wrote:
> Thanks to Bill Hoffmann and Alan Irwin for helping work through this
> MinGW problem. As it turns out, the problem in my CMakeLists.txt file
> wasn’t the residual presence of a CMakeFiles directory or a
> CMakeCache.txt file, or the command-line, which is correctly:
>
>     Cmake –G “MinGW Makefiles”
>
> Mea culpa. The source of the problem was due to the fact that the my
> parent CMakeLists.txt file dynamically creates and then processes a set
> of child CMakeLists.txt files. After creating them, those files (each in
> a subdirectory) are run using the following loop in the parent file:
>
>     foreach(toProcess ${dirsToProcess})
>
>      execute_process(COMMAND cmake CMakeLists.txt WORKING_DIRECTORY
> ${toProcess})
>
>     endforeach(toProcess)
>
> Although the parent was happily running with the MinGW flags, these
> child processes were not. I should have noticed this immediately. The
> solution is to embed the MinGW flag within that loop. Doing that, the
> build proceeds normally.
>
>     foreach(toProcess ${dirsToProcess})
>
>       execute_process(COMMAND cmake –G “MinGW Makefiles” CMakeLists.txt
> WORKING_DIRECTORY ${toProcess})
>
>     endforeach(toProcess)
>
> The general solution will be to build this out a bit more for different
> platforms.
>


You want to use the CMAKE_GENERATOR variable:
http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_GENERATOR

  cmake –G ${CMAKE_GENERATOR}

That should work cross platform.

You may also want to look into external project instead of what you are 
doing...

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#module:ExternalProject
http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html

-Bill



More information about the CMake mailing list