Cross-platform build under Windows targeting Linux using CMake

Your understanding of CMake is correct... it will determine how to create the build system you request (or is default for the platform you are currently on) based on rules in your CMakeLists.txt file. However, this won't necessarily help you compile for linux on a windows machine if you don't have something installed that can target linux.

To compile targeting linux, you will need to use a linux compiler. The link posted by @stjin tells you how to install one on cygwin. Then, to set up your CMake build, do this in the terminal:

CC=gcc-linux CXX=g++-linux cmake . [options]

This will tell CMake to locate the special linux targeted compilers. Hopefuly, after compiling with these compilers you will be able to run on linux.


You will want to look here: cmake-toolchains(7) if you do cross compiling. However, I would suggest that you install a Linux VM like virtual box on your windows machine and build naively on Linux. It will compile much faster and you will not have to worry about cross compiling. You can mount the windows disk from the linux VM so you can share the same source tree. The linux VM will compile much faster than gcc running under windows.