mirror of
https://github.com/meekrosoft/fff
synced 2026-01-22 16:05:59 +01:00
Add GTest with FetchContent (#120)
* Add missing GTest linking * Add unit testing switch * Rename UNIT_TESTING to be fff-specific * Add fff.h generation toggle * Use options instead of variables for disabling build elements * Add interface library for when the header is not regenerated * Update build script and README
This commit is contained in:
@@ -6,29 +6,41 @@ project(fff)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
# Add the gtest library which will be used below
|
||||
add_subdirectory(gtest)
|
||||
|
||||
# Enable ctest
|
||||
enable_testing()
|
||||
|
||||
add_library(fff INTERFACE)
|
||||
|
||||
option(FFF_GENERATE "If enabled, fff.h will be regenerated using ruby" OFF)
|
||||
|
||||
# Generate fff.h if fakegen.rb changed
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${CMAKE_CURRENT_LIST_DIR}/fff.h
|
||||
COMMAND
|
||||
ruby ${CMAKE_CURRENT_LIST_DIR}/fakegen.rb >> ${CMAKE_CURRENT_LIST_DIR}/fff.h
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_LIST_DIR}/fakegen.rb
|
||||
${CMAKE_CURRENT_LIST_DIR}/LICENSE
|
||||
)
|
||||
add_custom_target(fff_h DEPENDS ${CMAKE_CURRENT_LIST_DIR}/fff.h)
|
||||
if(FFF_GENERATE)
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${CMAKE_CURRENT_LIST_DIR}/fff.h
|
||||
COMMAND
|
||||
ruby ${CMAKE_CURRENT_LIST_DIR}/fakegen.rb >> ${CMAKE_CURRENT_LIST_DIR}/fff.h
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_LIST_DIR}/fakegen.rb
|
||||
${CMAKE_CURRENT_LIST_DIR}/LICENSE
|
||||
)
|
||||
add_custom_target(fff_h DEPENDS ${CMAKE_CURRENT_LIST_DIR}/fff.h)
|
||||
else()
|
||||
add_library(fff_h INTERFACE)
|
||||
set_target_properties(fff_h
|
||||
PROPERTIES PUBLIC_HEADER "fff.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_dependencies(fff fff_h)
|
||||
|
||||
# Add an interface library for fff.h
|
||||
add_library(fff INTERFACE)
|
||||
add_dependencies(fff fff_h)
|
||||
target_include_directories(fff INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Add tests and samples
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(examples)
|
||||
option(FFF_UNIT_TESTING "If enabled, fff tests will be compiled and run" OFF)
|
||||
|
||||
if(FFF_UNIT_TESTING)
|
||||
# Add tests and samples
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
@@ -35,7 +35,7 @@ To run all the tests and sample apps, simply call `$ buildandtest`. This script
|
||||
will call down into CMake with the following:
|
||||
|
||||
```shell
|
||||
cmake -GNinja -B build
|
||||
cmake -B build -DFFF_GENERATE=ON -DFFF_UNIT_TESTING=ON
|
||||
cmake --build build
|
||||
ctest --test-dir build --output-on-failure
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ rm -fr build fff.h
|
||||
mkdir build
|
||||
|
||||
# Configure the build
|
||||
cmake -GNinja -B build || exit -1
|
||||
cmake -B build -DFFF_GENERATE=ON -DFFF_UNIT_TESTING=ON || exit -1
|
||||
|
||||
# Build all targets
|
||||
cmake --build build || exit -1
|
||||
|
||||
@@ -7,7 +7,7 @@ add_executable(driver_test
|
||||
src/driver.test.cpp
|
||||
)
|
||||
target_include_directories(driver_test PRIVATE include)
|
||||
target_link_libraries(driver_test PRIVATE gtest fff)
|
||||
target_link_libraries(driver_test PRIVATE GTest::gtest_main fff)
|
||||
target_compile_definitions(driver_test PUBLIC TEST_USER_OWN_TR1_TUPLE=1 TESTING)
|
||||
|
||||
# Create the driver fff test binary
|
||||
@@ -16,7 +16,7 @@ add_executable(driver_fff_test
|
||||
src/driver.test.fff.cpp
|
||||
)
|
||||
target_include_directories(driver_fff_test PRIVATE include)
|
||||
target_link_libraries(driver_fff_test PRIVATE gtest fff)
|
||||
target_link_libraries(driver_fff_test PRIVATE GTest::gtest_main fff)
|
||||
target_compile_definitions(driver_fff_test PUBLIC TEST_USER_OWN_TR1_TUPLE=1 TESTING)
|
||||
|
||||
# Add tests to ctest
|
||||
|
||||
@@ -9,7 +9,7 @@ target_link_libraries(ui_test_ansic PRIVATE fff)
|
||||
# Create the ui_test_cpp test binary
|
||||
add_executable(ui_test_cpp src/UI_test_cpp.cpp src/UI.c)
|
||||
target_include_directories(ui_test_cpp PRIVATE include)
|
||||
target_link_libraries(ui_test_cpp PRIVATE gtest fff)
|
||||
target_link_libraries(ui_test_cpp PRIVATE GTest::gtest_main fff)
|
||||
|
||||
# Add tests to ctest
|
||||
add_test(
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# Copyright 2022 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
set(CMAKE_EXE_LINKER_FLAGS " -static")
|
||||
|
||||
# Create the gtest library
|
||||
add_library(gtest src/gtest-all.cc src/gtest-main.cc)
|
||||
target_include_directories(gtest PUBLIC include include/gtest)
|
||||
target_link_libraries(gtest PRIVATE Threads::Threads -static-libstdc++)
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,6 +0,0 @@
|
||||
#include "gtest.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -8,6 +8,17 @@ set(
|
||||
src/test_cases.include
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG v1.12.0
|
||||
)
|
||||
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
# Create the C test executable
|
||||
add_executable(c_test src/fff_test_c.c ${COMMON_FILE_LIST})
|
||||
target_include_directories(c_test PRIVATE include)
|
||||
@@ -16,7 +27,7 @@ target_link_libraries(c_test PRIVATE fff)
|
||||
# Create the C++ test executable
|
||||
add_executable(cpp_test src/fff_test_cpp.cpp ${COMMON_FILE_LIST})
|
||||
target_include_directories(cpp_test PRIVATE include)
|
||||
target_link_libraries(cpp_test PRIVATE gtest fff)
|
||||
target_link_libraries(cpp_test PRIVATE GTest::gtest_main fff)
|
||||
|
||||
# Create the C global test executable
|
||||
add_executable(c_global_test
|
||||
@@ -36,7 +47,7 @@ add_executable(cpp_global_test
|
||||
${COMMON_FILE_LIST}
|
||||
)
|
||||
target_include_directories(cpp_global_test PRIVATE include)
|
||||
target_link_libraries(cpp_global_test PRIVATE gtest fff)
|
||||
target_link_libraries(cpp_global_test PRIVATE GTest::gtest_main fff)
|
||||
|
||||
# Create the C++ custom function signature executable
|
||||
add_executable(cpp_custom_fn_signature_test
|
||||
@@ -44,7 +55,7 @@ add_executable(cpp_custom_fn_signature_test
|
||||
${COMMON_FILE_LIST}
|
||||
)
|
||||
target_include_directories(cpp_custom_fn_signature_test PRIVATE include)
|
||||
target_link_libraries(cpp_custom_fn_signature_test PRIVATE gtest fff)
|
||||
target_link_libraries(cpp_custom_fn_signature_test PRIVATE GTest::gtest_main fff)
|
||||
# Due to a bug in WinLibs for Windows it's not currently possible to use:
|
||||
# target_precompile_headers(cpp_custom_fn_signature_test PUBLIC include/custom_function.hpp)
|
||||
# See more info at target_precompile_headers(cpp_custom_fn_signature_test PUBLIC include/custom_function.hpp)
|
||||
|
||||
Reference in New Issue
Block a user