Configuration - Add support for Google Test framework in CMake #443

Enhance Google Test integration and add support for test projects.
Each Toolkit have GTests folder with place for new tests.
For adding new tests needs to extend FILES.cmake files in each GTests folder.
The single executable is created for each toolkit with all tests.
The tests grouped by module and toolkit with :: as separator.
Added option to download GTest by Cmake if not found.
Add GTest for PLib_JacobiPolynomial with comprehensive test cases
Add GTest for TCollection_AsciiString and TCollection_ExtendedString
Set C++ standard to C++14 for GTest compatibility if required
This commit is contained in:
Pasukhin Dmitry
2025-03-24 08:58:02 +00:00
committed by GitHub
parent 986af180e6
commit 876ccbe977
82 changed files with 1596 additions and 15 deletions

View File

@@ -82,6 +82,12 @@ elseif ("${BUILD_CPP_STANDARD}" STREQUAL "C++23")
else ()
message (FATAL_ERROR, "misprint in c++ standard name")
endif()
if (DEFINED BUILD_GTEST AND BUILD_GTEST AND CMAKE_CXX_STANDARD LESS 14)
set (CMAKE_CXX_STANDARD 14)
message (STATUS "Info: C++14 standard is required for GTest. Set to C++14.")
endif()
set (CMAKE_CXX_STANDARD_REQUIRED ON)
# include cmake file
@@ -449,6 +455,10 @@ else()
OCCT_CHECK_AND_UNSET (USE_VTK)
endif()
if (NOT DEFINED BUILD_GTEST)
set (BUILD_GTEST OFF CACHE BOOL "${BUILD_GTEST_DESCR}")
endif()
# Rebuild *.yacc and *.lex files that are contained by TKMath toolkit
list (FIND BUILD_TOOLKITS TKMath CAN_REBUILD_PDC_FOR_TKMATH)
list (FIND BUILD_TOOLKITS StepFile CAN_REBUILD_PDC_FOR_STEPFILE)
@@ -1184,6 +1194,29 @@ foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
add_subdirectory ("${OCCT_${BUILD_TOOLKIT}_FILES_LOCATION}")
endforeach()
# Setup Google Test integration if enabled
if (BUILD_GTEST)
OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/gtest")
enable_testing()
OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_gtest")
# Initialize GTest environment and create the target first
OCCT_INIT_GTEST()
# Collect test files from all active toolkits and add them to the target
foreach (BUILD_TOOLKIT ${BUILD_TOOLKITS})
OCCT_COLLECT_TOOLKIT_TESTS(${BUILD_TOOLKIT})
endforeach()
# Set environment variables for all tests
OCCT_SET_GTEST_ENVIRONMENT()
else()
# Disable GTest integration if not enabled
OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_GTEST")
OCCT_CHECK_AND_UNSET_GROUP ("GTest")
OCCT_CHECK_AND_UNSET ("INSTALL_GTEST")
endif()
if (BUILD_DOC_Overview OR BUILD_DOC_RefMan)
OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_doc")
# Setup documentation targets