Search code examples
ccross-platformmakefilecmakemultiplatform

CMake multiple toolchains and target platforms


I am changing from plain make to CMake as a build system for a project. The project is supposed to run on different embedded Linux systems each with its own toolchain and also has quite a few different configuration options per target (e.g. different preprocessor definitions and some sources included/excluded). It is also supposed to work on desktop Linux and some GUI modules have to run on Windows.

Now, CMake has its CMAKE_TOOLCHAIN_FILE option that can be used to factor out the toolchain and compiler specific stuff of each embedded platform (desktop Linux and Windows should not need one).

I guess putting stuff other than the one listed on the CMake Wiki inside the toolchain file is not a good idea.

I am thinking about creating some CMake variables that can be edited by the cmake gui tool and then simply using if/elseif to determine the right setup.

Does anyone have a better or more elegant suggestion?


Solution

  • I figured instead of using long if/elseif/else blocks I could simply have

    include(flags-${CONFIGURATION_NAME}.cmake)
    

    in my CMakeLists.txt and the specific flags for each configuration would then simply be listed on the appropriate flags file.