CLion ignores `include_directories()` when cross-compiling with toolchain
I recently acquired a license to work on some cross-compilation projects. I have recently been writing some LCD driving code in C, which I have been compiling for the Raspberry Pi Pico (with its SDK and toolchain), as well as compiling code for the PIC16F877A (with the SDCC compiler and my own toolchain and platform files).
The issue is, CLion's IntelliSense seems to completely ignore whatever directories I add with `include_direcotries(...)` and `target_include_directories(...)` when using my toolchain file (cross-compiling with SDCC). I.e. the headers included in my source files show up in red.
The following is my root `CMakeLists.txt`
cmake_minimum_required(VERSION 3.10)
project(led_driver C)
set(CMAKE_VERBOSE_MAKEFILE 1)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -V")
set(SDCC_INCLUDES
/usr/local/share/sdcc/include
/usr/local/share/sdcc/include/pic14
/usr/local/share/sdcc/non-free/include/pic14)
include_directories(${SDCC_INCLUDES})
add_executable(led_driver main.c)
target_include_directories(led_driver PUBLIC external/include)
target_compile_definitions(led_driver PUBLIC __SDCC_PIC16F877A)
My toolchain file is the following:
# No OS so we need this
set(CMAKE_SYSTEM_NAME SDCC_PIC)
# root
set(CMAKE_SYSROOT "/usr/local/share/sdcc")
# assume that this is in your PATH
set(CMAKE_C_COMPILER_ID SDCC)
set(CMAKE_C_COMPILER sdcc)
# assume the default installation
set(CMAKE_FIND_ROOT_PATH usr/share/sdcc)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
My SDCC_PIC.cmake file is the following:
message("!!! Running my modules")
# gputils compiles to .o files
set(CMAKE_C_OUTPUT_EXTENSION ".o")
set(CMAKE_ASM_OUTPUT_EXTENSION ".o")
# PIC16F877A specific
set(CMAKE_C_FLAGS "-mpic14") # Processor family
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -p16f877a") # Processor model
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --use-non-free") # Microchip headers
set(SDCC_SYSTEM_INCLUDES
/usr/local/share/sdcc/include
/usr/local/share/sdcc/include/pic14)
include_directories(${SDCC_SYSTEM_INCLUDES})
It is worth noting that the CMake project itself compiles just fine when running manually. Even when building with CMake, it also compiles just fine. The only thing that doesn't work properly is IntelliSense in CLion.
It is also worth noting that, when I do not use `-DCMAKE_TOOLCHAIN_FILE` to use my system's default compilers, all the includes work just fine in CLion (I.e. the headers are found by IntelliSense).
I also have seen bugs where CMake does not include directories under `/usr/`, so for the purposes of testing, I copied those SDCC system headers under the project in the directory `external/include`. Both the `/usr/local/share/include/*` and the `external/include` headers ARE NOT found by CLion.
Is this a bug? Is there a workaround for this issue? Other IDE's have no problem with this (tried the same project on Visual Studio and VS Code on Windows).
My version is 203.7148.70, and I added a bug to track this. I am duplicating this information here to see if anyone in the community has come across this before.
Please sign in to leave a comment.