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.
https://cmake.org/cmake/help/v3.14/module/ExternalProject.html
https://www.vinnie.work/blog/2020-11-17-cmake-eval
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/gtest_main.cc
[==========] 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)
<skip>
[----------] 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:
add_executable(${CMAKE_PROJECT_NAME}
mock_arduino/Arduino.h
mock_arduino/wiring_private.h
mock_arduino/avr/interrupt.h
mock_arduino/mock_arduino.cpp mock_arduino/mock_arduino.h
ut.cpp
)
I tried the “Add to CMake Project” but no joy there.
It seems that CLion does not recognize ExternalProject.
Any recommendations?
请先登录再写评论。