Skip to content

Instantly share code, notes, and snippets.

@gabonator
Created June 29, 2023 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabonator/ec0ca3bde56542b427c8561aa0a78e83 to your computer and use it in GitHub Desktop.
Save gabonator/ec0ca3bde56542b427c8561aa0a78e83 to your computer and use it in GitHub Desktop.
google test cross compile minimal setup with cmake
cat > main.cpp <<- EOM
#include <gtest/gtest.h>
TEST(group, name)
{
printf("Hello!\n");
}
EOM
cat > CMakeLists.txt <<- EOM
cmake_minimum_required(VERSION 3.14)
project(isa_gtests)
include(FetchContent)
FetchContent_Declare(googletest URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.zip)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(tests main.cpp)
target_link_libraries(tests gtest_main)
include(GoogleTest)
gtest_discover_tests(tests)
EOM
cat > toolchain.txt <<- EOM
set(TOOLCHAIN_PATH "")
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}g++${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_LINKER ${TOOLCHAIN_PATH}ld${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_CXX_FLAGS "-O2")
set(CMAKE_CROSSCOMPILING_EMULATOR "${TOOLCHAIN_PATH}qemu")
EOM
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=toolchain.txt
cmake --build build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment