CLion cmake behavior is different from systems CLI cmake

Answered

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.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)

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

# set the default MCU model
set(MICROCHIP_MCU PIC18F97J60)

project(xc8-cmake C)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic")
set(CMAKE_C_FLAGS_DEBUG "-O0")
set(CMAKE_C_FLAGS_RELEASE "-O0")

include_directories(......)
add_executable(......)

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?

4 comments
Comment actions Permalink

Hello!

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:

https://www.jetbrains.com/help/clion/custom-compilers.html
https://blog.jetbrains.com/clion/2021/10/clion-2021-3-eap-custom-compiler/
https://github.com/JetBrains/clion-custom-defined-compiler-examples

0
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.

0
Comment actions Permalink

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

Where

${compiler-exe-dir}

In custom-compiler.yaml is defined?

 

0
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.

0

Please sign in to leave a comment.