Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I compile this project with CMake? #49

Open
enigmatichaptics opened this issue Jun 23, 2023 · 0 comments
Open

How do I compile this project with CMake? #49

enigmatichaptics opened this issue Jun 23, 2023 · 0 comments

Comments

@enigmatichaptics
Copy link

Hi there. I'm new to Arduino and trying to use your mocking library as part of a suite of gtest framework tests.

My CMakeLists.txt file looks like this:

cmake_minimum_required(VERSION 3.14) # version can be different
project(TestProject) #name of your project
# Set compilation flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=1")
include(CTest)
include(FetchContent)
# Set a flag indicating whether building with CMake
set(BUILD_WITH_CMAKE TRUE)
# Conditionally include the appropriate headers based on BUILD_WITH_CMAKE
if(BUILD_WITH_CMAKE)
  add_compile_definitions(BUILD_WITH_CMAKE)
  include_directories(${CMAKE_CURRENT_BINARY_DIR}/_deps/arduinofake-src/src)
endif()

enable_testing()
FetchContent_Declare(
  googletest
  # Specify the commit you depend on and update it regularly.
  URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# Fetch ArduinoFake library
FetchContent_Declare(
    ArduinoFake
    GIT_REPOSITORY https://github.com/FabioBatSilva/ArduinoFake.git
    GIT_TAG cf9c596b73ffe7e7cf39faeb550bbef8598edb98
)
FetchContent_MakeAvailable(ArduinoFake)

# Now simply link against gtest or gtest_main as needed. Eg
add_executable(mytests mytests.cpp)
target_link_libraries(mytests gtest)
add_test(NAME example_test COMMAND mytests)

I had no issues running make before adding the ArduinoFake stuff, but am now getting the error:

[100%] Linking CXX executable main-d.exe
lto-wrapper.exe: warning: using serial compilation of 2 LTRANS jobs
lto-wrapper.exe: note: see the '-flto' option documentation for more information
lto1.exe: error: two or more sections for .gnu.lto__ZN10SerialTest19test_extends_streamEv.4317.e9bafa65
(null):0: confused by earlier errors, bailing out
lto-wrapper.exe: fatal error: C:\msys64\mingw64\bin\g++.exe returned 1 exit status
compilation terminated.
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status

I'm not sure what I'm doing wrong or if I'm using the library wrong. Would anyone be willing to help me out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant