### Sample CMakeLists.txt Source: https://github.com/balp/arduino-mock/blob/master/README.md Example CMakeLists.txt demonstrating how to fetch and link Catch2, googletest, and arduino-mock. ```cmake FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v2.11.1) FetchContent_MakeAvailable(Catch2) FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.10.0) FetchContent_MakeAvailable(googletest) FetchContent_Declare(arduino-mock GIT_REPOSITORY https://github.com/balp/arduino-mock.git GIT_TAG cmake3) FetchContent_MakeAvailable(arduino-mock) add_executable(tests main.cpp tests.cpp) target_link_libraries(tests Catch2::Catch2 arduino_mock) target_compile_features(tests PUBLIC cxx_std_11) set_target_properties(tests PROPERTIES CXX_EXTENSIONS OFF) add_test(NAME tests COMMAND tests) ``` -------------------------------- ### Project Setup and Dependencies Source: https://github.com/balp/arduino-mock/blob/master/CMakeLists.txt Configures the CMake minimum version, project name, and finds the Threads package. It also includes logic to fetch and make googletest available if not already present. ```cmake cmake_minimum_required(VERSION 3.14) if (NOT DEFINED PROJECT_NAME) set(NOT_SUBPROJECT ON) endif () project(arduino_mock) find_package(Threads REQUIRED) # If we are a stand alone project not included with add_subdirectory() and # googletest, e.g. googlemock is not provided make sure to download it. if (NOT_SUBPROJECT) if (NOT TARGET gmock_main) include(FetchContent) FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.10.0) FetchContent_MakeAvailable(googletest) endif () endif () ``` -------------------------------- ### gmock ExternalProject Configuration Source: https://github.com/balp/arduino-mock/blob/master/lib/gmock/CMakeLists.txt This snippet shows how to add gmock as an external project using CMake's ExternalProject_Add command, specifying the URL, prefix, and install command. ```cmake cmake_minimum_required(VERSION 2.8.8) project(gmock_builder C CXX) include(ExternalProject) ExternalProject_Add( gmock URL https://github.com/paulsapps/gmock-1.7.0/archive/master.zip PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gmock INSTALL_COMMAND "" ) ``` -------------------------------- ### gtest ExternalProject Configuration Source: https://github.com/balp/arduino-mock/blob/master/lib/gtest/CMakeLists.txt Configures gtest as an external project using CMake's ExternalProject_Add command, specifying the URL, prefix, and an empty install command. ```cmake message("in gtest") project(gtest_builder C CXX) include(ExternalProject) ExternalProject_Add( gtest URL https://github.com/google/googletest/archive/release-1.7.0.zip PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest INSTALL_COMMAND "" ) ``` -------------------------------- ### Output Directory Properties Source: https://github.com/balp/arduino-mock/blob/master/CMakeLists.txt Sets the output directories for archive, library, and runtime files. ```cmake set_target_properties(arduino_mock PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/bin" ) ``` -------------------------------- ### Test Configuration Source: https://github.com/balp/arduino-mock/blob/master/CMakeLists.txt Enables testing and adds the test subdirectory if the 'test' option is set to ON. ```cmake add_dependencies(arduino_mock gtest gmock) option(test "Build all tests." OFF) if (test) enable_testing() add_subdirectory(test) endif () ``` -------------------------------- ### Library Definition and Configuration Source: https://github.com/balp/arduino-mock/blob/master/CMakeLists.txt Defines the arduino_mock library as a static library, specifies include directories, and links necessary libraries like gmock, gtest, and Threads. ```cmake add_library(arduino_mock STATIC src/Arduino.cc src/EEPROM.cc src/OneWire.cc src/Serial.cc src/Spark.cc src/Wire.cc src/IRremote.cc src/SPI.cc src/SoftwareSerial.cc src/WiFi.cc src/serialHelper.cc ) target_include_directories(arduino_mock PRIVATE "include" PUBLIC "include/arduino-mock" INTERFACE "include/arduino-mock" ) target_link_libraries(arduino_mock gmock gtest ${CMAKE_THREAD_LIBS_INIT} ) target_compile_features(arduino_mock PUBLIC cxx_std_11) set_target_properties(arduino_mock PROPERTIES CXX_EXTENSIONS OFF) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/balp/arduino-mock/blob/master/test/CMakeLists.txt This snippet shows the CMake configuration for building the test executable, linking against the arduino_mock library and Google Test/Mock libraries. ```cmake message ("building tests for Arduino Mock") # include_directories(${GTEST_INCLUDE_DIRS}) file(GLOB SRCS *.cc) add_executable(test_all test_all.cc) target_link_libraries(test_all arduino_mock ${GTEST_LIBS_DIR}/libgtest.a ${GTEST_LIBS_DIR}/libgtest_main.a ${GMOCK_LIBS_DIR}/libgmock.a ${CMAKE_THREAD_LIBS_INIT} ) add_dependencies(test_all gtest) add_test(arduino_mock_test test_all) ``` -------------------------------- ### gmock Include and Library Directories Source: https://github.com/balp/arduino-mock/blob/master/lib/gmock/CMakeLists.txt These snippets retrieve the source and binary directories of the gmock external project and set the GMOCK_INCLUDE_DIRS and GMOCK_LIBS_DIR variables. ```cmake # Specify include dir ExternalProject_Get_Property(gmock source_dir) set(GMOCK_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE) ``` ```cmake # Specify MainTest's link libraries ExternalProject_Get_Property(gmock binary_dir) set(GMOCK_LIBS_DIR ${binary_dir} PARENT_SCOPE) ``` -------------------------------- ### gtest Libraries Directory Property Source: https://github.com/balp/arduino-mock/blob/master/lib/gtest/CMakeLists.txt Retrieves the binary directory of the gtest external project and sets theGTEST_LIBS_DIR property. ```cmake # Specify MainTest's link libraries ExternalProject_Get_Property(gtest binary_dir) set(GTEST_LIBS_DIR ${binary_dir} PARENT_SCOPE) ``` -------------------------------- ### gtest Include Directory Property Source: https://github.com/balp/arduino-mock/blob/master/lib/gtest/CMakeLists.txt Retrieves the source directory of the gtest external project and sets the GTEST_INCLUDE_DIRS property. ```cmake # Specify include dir ExternalProject_Get_Property(gtest source_dir) set(GTEST_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.