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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Sep 25, 2023 at 11:20 UTC
a15d4465a9918911e0953e89276d563fdc8cceef
1 file changed
+18
contrib/buildsystems/CMakeLists.txt
+18
@@ -965,6 +965,24 @@ target_link_libraries(test-fake-ssh common-main)
965
parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
966
list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
967
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
+
986
#test-tool
987
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
988