[CMake] CMake cross-compilation best practices

Johannes Stallkamp johannes.stallkamp at rub.de
Mon Nov 30 03:00:47 EST 2009


Hello Romain,

Romain CHANU schrieb:
> If I need to compile a library on both Linux and Windows, the best
> CMake practice would be to write toolchain files for Linux and
> Windows (cf. http://www.cmake.org/Wiki/CMake_Cross_Compiling)
>
> Is that correct?
Do you really want to cross-compile (i.e. build your Linux library on
Windows or vice versa) or do you just want to be able to compile your
platform-independent library natively on Linux or Windows but with the
same CMakeLists.txt ?
In the latter case, just go for it. Basically, your Windows
CMakeLists.txt should work just fine on Linux and vice versa. You
might need to adjust some paths if you use some 3rd party libraries or
use some compiler specific additional options. But you can implement
that just fine within the same CMakeLists.txt using IF( MSVC ) ....
ENDIF() (or other compiler/system-variables, see
http://www.itk.org/Wiki/CMake_Useful_Variables )

HTH
Johannes



More information about the CMake mailing list