[CMake] About multiple toolchains support in big project

刘松 liusong at zerozero.cn
Fri Apr 28 06:51:42 EDT 2017


Hi CMake experts,

I want to use CMake build system for large projects, which will uses different toolchains.

Let’s take one simple example:

There are two project, one is using the arm cross toolchain, another one is using the dsp toolchain.


cmake_projects/
├── CMakeLists.txt
├── arm_project
│   └── CMakeLists.txt
├── arm_project2
│   └── CMakeLists.txt
├── dsp_project
│   └── CMakeLists.txt
└── dsp_project2
    └── CMakeLists.txt


Inside the cmake_projects/CMakeLists.txt:

add_subdirectory(arm_project)

add_subdirectory(arm_project2)

add_subdirectory(dsp_project)

add_subdirectory(dsp_project2)


Then, I want to build it:

mkdir build
cd build && cmake -DCMAKE_TOOLCHAIN_FILE=<which_toolchain> ../


You know that the CMAKE_TOOLCHAIN_FILE needs to be specified along with cmake command line, so in above example what’s the <which_toolchain> should be ?

Yes, there might be another solution:


cmake_projects/
├── CMakeLists.txt
├── arm
│   └── CMakeLists.txt
├── dsp
│   └── CMakeLists.txt

├── arm_project
│   └── CMakeLists.txt
├── arm_project2
│   └── CMakeLists.txt
├── dsp_project
│   └── CMakeLists.txt
└── dsp_project2
    └── CMakeLists.txt


so that inside arm/CMakeLists.txt


add_subdirectory(arm_project)
add_subdirectory(arm_project2)


and inside dsp/CMakeLists.txt


add_subdirectory(dsp_project)
add_subdirectory(dsp_project2)


Then, build it with

mkdir build_arm
cd build_arm && cmake -DCMAKE_TOOLCHAIN_FILE=<arm_toolchain_now> ../arm

mkdir build_dsp
cd build_dsp && cmake -DCMAKE_TOOLCHAIN_FILE=<dsp_toolchain_now> ../dsp


But this way I need to sperate the arm and dsp build folder structure, but logically I need to keep the build folder structure as same as source code.

Or, let developer don’t be aware of the toolchain difference it’s just choosing the right one…

But if it’s supporting specifying the CMAKE_TOOLCHAIN_FILE inside the CMakeLists.txt, it might solving this problem.

Any suggestions or ideas ? Thanks in advanced.

Thanks,
Song
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170428/d2274747/attachment-0001.html>


More information about the CMake mailing list