Created
June 29, 2023 09:46
-
-
Save gabonator/ec0ca3bde56542b427c8561aa0a78e83 to your computer and use it in GitHub Desktop.
google test cross compile minimal setup with cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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