How to specify a compiler in CMake?

后端 未结 5 1498
粉色の甜心
粉色の甜心 2020-12-03 02:50

I would like to use the IAR compiler. I noticed CMake has already have a bunch of files about this compiler:

https://github.com/jevinskie/cmake/blob/master/Modules/C

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 03:27

    If you don't want to use your PC's standard compiler, you have to give CMake the path to the compiler. You do this via environment variables, a toolchain file or direct definitions in the CMake command line (see e.g. CMake Error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found).

    Putting the compiler's name/path into your CMakeLists.txt would stop your project from being cross-platform.

    CMake does check for the compiler ids by compiling special C/C++ files. So no need to manually include from Module/Compiler or Module/Platform.

    This will be automatically done by CMake based on its compiler and platform checks.

    References

    • CMake: In which Order are Files parsed (Cache, Toolchain, …)?
    • CMake GitLab Commit: Add support files for C, C++ and ASM for the IAR toolchain.

提交回复
热议问题