Clion and CMake for an Arduino project with GTest cross-compilations.

I have an Arduino project that I can compile with CMake & avr-gcc. Clion recognizes the header locations etc. and hightlights everything in the source files great.

I'm trying to add GTest to this project. Cmake has the limitation that it can only use one compiler. But there are ways using ExternalProject to get around it.

And I got it to work. Still some issues, but the GTest unit tests compile and run correctly.

$ cmake-build-debug/host/ut/ut 
Running main() from /build/googletest-j5yxiC/googletest-1.10.0/googletest/src/
[==========] Running 9 tests from 6 test suites.
[----------] Global test environment set-up.
[----------] 1 test from pulser_info
[ RUN      ] pulser_info.init
[       OK ] pulser_info.init (0 ms)
[----------] 1 test from pulser_info (0 ms total)
[----------] Global test environment tear-down
[==========] 9 tests from 6 test suites ran. (1 ms total)
[  PASSED  ] 9 tests.

But Clion doesn't seem to recognize any of this and so it does not highlight source code correctly. It says “This file does not belong to any project target; code insight features might not work properly” but the code is in the ut/CMakeLists.txt:

        mock_arduino/mock_arduino.cpp mock_arduino/mock_arduino.h

I tried the “Add to CMake Project” but no joy there.

It seems that CLion does not recognize ExternalProject.
Any recommendations?