I'm trying to set compiler for my gtest in my cmake.
I use FetchContent to get the gtest code first.
To change the compiler in FetchContent I set CMAKE_CXX_COMPILER (answered here: https://cmake.org/pipermail/cmake/2019-March/069206.html)
set(CMAKE_CXX_COMPILER "/usr/bin/arm-linux-gnueabihf-g++" CACHE INTERNAL "")
########################################
# Fetch gtests
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/release-1.11.0.zip
)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
########################################
The first cmake build succeed (when there is no CMakeCache.txt). But the second one fails:
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/arm-linux-gnueabihf-g++
After that error message cmake start itself again, and fails because it doesn't get any cmake parameters:
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at src/CMakeLists.txt:36 (message):
Please provide spi mode. -DSPI_MODE=[mock, asic]
-- Configuring incomplete, errors occurred!
See also "/work/build/arm/cmake/CMakeFiles/CMakeOutput.log".
What is the proper way of setting a gtest compiler?
I solved it by setting the compiler from the cmake run command instead:
cmake -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ ..