From: Phillip Wood Date: Mon, 11 Sep 2023 13:23:44 GMT Subject: Re: [PATCH 1/4] cmake: also build unit tests Message-ID: In-Reply-To: <2cc1c03d85153356edd55fc0747a957db3c94ab0.1693462532.git.gitgitgadget@gmail.com> Hi Johannes On 31/08/2023 07:15, Johannes Schindelin via GitGitGadget wrote: > From: Johannes Schindelin > > A new, better way to run unit tests was just added to Git. This adds > support for building those unit tests via CMake. This patch builds the unit tests but does not add them to the list of tests run by CTest - how are the tests typically run on the CMake build? Best Wishes Phillip > Signed-off-by: Johannes Schindelin > --- > contrib/buildsystems/CMakeLists.txt | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt > index 2f6e0197ffa..45016213358 100644 > --- a/contrib/buildsystems/CMakeLists.txt > +++ b/contrib/buildsystems/CMakeLists.txt > @@ -965,6 +965,24 @@ target_link_libraries(test-fake-ssh common-main) > parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS") > list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") > > +#unit-tests > +add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c) > + > +parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "") > +foreach(unit_test ${unit_test_PROGRAMS}) > + add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c") > + target_link_libraries("${unit_test}" unit-test-lib common-main) > + set_target_properties("${unit_test}" > + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests) > + if(MSVC) > + set_target_properties("${unit_test}" > + PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests) > + set_target_properties("${unit_test}" > + PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests) > + endif() > + list(APPEND PROGRAMS_BUILT "${unit_test}") > +endforeach() > + > #test-tool > parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") >