c++cmakeheader-filescliondevkitpro

Including directories for CLion inspections while using custom toolchain


I'm using CLion 2018.2 to write C/C++ code for a custom compiler toolchain which are not supported natively by CLion. I currently compile with make on the Terminal instead of building from within the IDE.

I have a custom include directory with header files which are not resolved/found by CLion since they are not part of the project. However, I want to get code inspection features for them. The headers are e.g. located at C:\devkitPro\wups\include.

I decided to use the include_directories() CMake command to improve CLion's ability to resolved code:

include_directories("C:\\devkitPro\\wups\\include")

Then I also modified the CMake include path:

set(CMAKE_INCLUDE_PATH "C:\\devkitPro\\wups\\include")

And also decided to link against the lib directory:

link_directories("C:\\devkitPro\\wups\\lib")

After doing all that, the headers still aren't resolved in CLion (but it still compiles using make of course). How can the header resolution be done with CLion or is it not possible, yet?


Solution

  • Depending on the configured toolchain in CLion, CMake expects a Windows or a WSL-style path. Inspections will work with the include_directories directive, e.g.

    # Add extra include directories
    if (WIN32) # When using a Windows compilation toolchain
        set(WUT "/c/devkitPro/wut/include")
        set(WUPS "/c/devkitPro/wups/include")
    else () # When using WSL as toolchain
        set(WUT "/mnt/c/devkitPro/wut/include")
        set(WUPS "/mnt/c/devkitPro/wups/include")
    endif ()
    include_directories(${WUT})
    include_directories(${WUPS})
    

    A more detailed written tutorial can be found in this pull request.