cmake_minimum_required(VERSION 3.14) # Enable testing enable_testing() # Enable code coverage if(CMAKE_COMPILER_IS_GNUCXX) option(CIGUI_CODE_COVERAGE "Enable code coverage reporting" OFF) if(CIGUI_CODE_COVERAGE) target_compile_options(cigui_tests PRIVATE --coverage) target_link_options(cigui_tests PRIVATE --coverage) endif() endif() # Add GoogleTest (fetched via CPM) CPMAddPackage( NAME GTest GITHUB_REPOSITORY google/googletest VERSION 1.16.0 OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt ON" ) # Function to easily add test files function(add_cigui_test TEST_NAME) add_executable(${TEST_NAME} ${ARGN}) target_link_libraries(${TEST_NAME} PRIVATE cigui gtest gtest_main gmock) target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src) # Add test to CTest add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) # Copy DLLs on Windows when using shared libraries if(WIN32 AND CIGUI_BUILD_SHARED) add_custom_command(TARGET ${TEST_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ $ $ $ ) endif() endfunction() # Main test executable add_executable( cigui_tests test_main.cpp ) # Link against the library and test framework target_link_libraries( cigui_tests PRIVATE cigui gtest gmock ) # Include private headers for white-box testing target_include_directories( cigui_tests PRIVATE ${CMAKE_SOURCE_DIR}/src ) # Add main test to CTest add_test(NAME cigui_tests COMMAND cigui_tests) # Copy DLLs on Windows when using shared libraries if(WIN32 AND CIGUI_BUILD_SHARED) add_custom_command(TARGET cigui_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ $ $ $ ) endif() # Optional: Individual test executables # Uncomment to build separate test executables in addition to the main one # add_cigui_test(widget_test widgets/widget_test.cpp) # add_cigui_test(button_test widgets/button_test.cpp) # add_cigui_test(window_test core/window_test.cpp)