CLion cmake behavior is different from systems CLI cmake


Im trying to cross compile my cmake project with Clion IDE. Toolchain file is third party project and connected thru "CMakeLists.txt"

CMake successfuly initializes from powershell, with next output:

-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: G:/Toolchains/XC8/2.35/bin/xc8-cc.exe - skipped
-- Configuring done
-- Generating done
-- Build files have been written to: H:/Learn/XC8_Cmake/build

When im trying to reload CMake project from CLion, im get next output:

"C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_MAKE_PROGRAM=C:\ProgramData\chocolatey\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=.external/cmake-microchip/toolchain.cmake -G Ninja H:\Learn\XC8_Cmake
-- Configuring done
-- Generating done
-- Build files have been written to: H:/Learn/XC8_Cmake/build

Cannot get compiler information:
    Compiler exited with error code 1: G:\Toolchains\XC8\2.35\bin\xc8-cc.exe -xc -isystem./include -mcpu=18F97J60 --nofallback -Wpedantic -O0 -fpch-preprocess -v -dD -E
    ::: warning: (1428) "-xc" is not supported; this feature will be ignored
    ::: warning: (2044) unrecognized option "-fpch-preprocess"
    ::: warning: (2044) unrecognized option "-dD"
[Failed to reload]

Project builds fine, but all dependencies is missed in IDE. It doesnt see "system headers" and specific pragmas.


cmake_minimum_required(VERSION 3.3)

set(CMAKE_TOOLCHAIN_FILE external/cmake-microchip/toolchain.cmake)

# set the default MCU model

project(xc8-cmake C)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic")


Why im getting addtitional flags with Clion Cmake? How can i remove it? Seems compiler check is skipped at CLI initialization, how can i skip it in IDE? How i can force IDE to see system includes?

Comment actions Permalink


The thing is that our code-insight features depend on various information that we get from the compiler: system includes, standard defines, compiler features, and so on. To get this information we go directly to the compiler. And therefore CLion can work correctly and stably only with supported compilers.

The XC8 compiler is not supported in CLion directly, but can be used with the help of the "Custom Compiler" feature. Please take a look at the following materials:

Comment actions Permalink

It's not possible to disable this. CLion needs to get various information from the compiler and it's its way to do this.

The only way to work with the XC8 compiler in CLion is to create a configuration file with its description in YAML format as described in the documentation I shared previously.

Comment actions Permalink

I have some partial success with that. But one question left: 



In custom-compiler.yaml is defined?


Comment actions Permalink

It's taken from the paths to the compilers, specified either in `File | Settings | Build, Execution, Deployment | Toolchains`, or in in your Makefile, or in the CMake profile settings.


Please sign in to leave a comment.