Skip to content

Commit a15d446

Browse files
dschogitster
authored andcommitted
cmake: also build unit tests
A new, better way to run unit tests was just added to Git. This adds support for building those unit tests via CMake. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8f416b commit a15d446

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,24 @@ target_link_libraries(test-fake-ssh common-main)
965965
parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
966966
list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
967967

968+
#unit-tests
969+
add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
970+
971+
parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "")
972+
foreach(unit_test ${unit_test_PROGRAMS})
973+
add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c")
974+
target_link_libraries("${unit_test}" unit-test-lib common-main)
975+
set_target_properties("${unit_test}"
976+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
977+
if(MSVC)
978+
set_target_properties("${unit_test}"
979+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
980+
set_target_properties("${unit_test}"
981+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
982+
endif()
983+
list(APPEND PROGRAMS_BUILT "${unit_test}")
984+
endforeach()
985+
968986
#test-tool
969987
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
970988

0 commit comments

Comments
 (0)