
Cmake linux tutorial full#
Typically, local toolchains have symbolic links that omit triple in binary name: we use gcc instead of the full name x86_64-linux-gnu-gcc. Toolchain name usually contains the so-called target triple, which is in the form of - or in a longer form -, e.g. When we cross-compile to another platform, we have to specify completely different toolchain both in terms of name and location of the binaries.

By default, this value is the same as CMAKE_HOST_SYSTEM_NAME, which means that we are building for local platform (no cross-compilation).
Cmake linux tutorial windows#
On major operating systems this is set to the Linux, Windows or Darwin (MacOS) value.

After successful detection, CMake stores info about the current toolchain in the following variables: Of course, you may try to set it to something completely rubbish, but CMake will usually verify if the given compiler is usable. If you manually set CC or CXX to different values, then CMake will use these new settings as default compilers.

They define what is the default compiler in the system. The answer is simple: it checks the CC and CXX environment variables. But how does CMake know which compiler to use? After all, you can have multiple toolchains installed in your system. Here you can see, that I’m using arm-none-linux-gnueabihf-gcc 9.2.1 C compiler and arm-none-linux-gnueabihf-g++ 9.2.1 C++ compiler. Check for working CXX compiler: /opt/toolchains/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ - works Check for working CXX compiler: /opt/toolchains/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ Check for working C compiler: /opt/toolchains/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc - works Check for working C compiler: /opt/toolchains/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc The CXX compiler identification is GNU 9.2.1 The C compiler identification is GNU 9.2.1 Found assembler: /opt/toolchains/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc Below you can find sample output from one of my projects: - The ASM compiler identification is GNU If you run CMake in the console (or in IDE which shows CMake output) you can usually see, that in the beginning there are some log messages reporting what is the detected compiler. Before we can switch to cross-compilation, it is crucial to understand how CMake handles compiler detection, how we can extract information about current toolchain and what is the target platform.
