Skip to content

Commit

Permalink
add build_unittests to build all the test targets
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeltzun committed Sep 28, 2023
1 parent 6c1cb39 commit f1860ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/coreComponents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,30 @@ if( GEOS_ENABLE_TESTS )
add_subdirectory( unitTests )
endif( )

########################################################################
# the following commmand adds `unittests` Cmake target such that running `$ make unittests test`
# builds the unit tests before running them
function(get_all_test_targets var)
set(targets)
get_all_test_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()

macro(get_all_test_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
get_all_test_targets_recursive(${targets} ${subdir})
endforeach()

get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
foreach(target ${current_targets})
if(${target} MATCHES "(test|example).+")
list(APPEND ${targets} ${target})
endif()
endforeach()
endmacro()

get_all_test_targets(unittests_targets)
# message(STATUS "UnitTests: ${unittests_targets}")
add_custom_target(unittests COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${unittests_targets})
########################################################################
2 changes: 1 addition & 1 deletion src/coreComponents/unitTests/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

set( gtest_geosx_tests
testDebug.cpp )
testNDEBUG.cpp )

set( dependencyList ${parallelDeps} gtest )

Expand Down

0 comments on commit f1860ef

Please sign in to comment.