Skip to content

Commit fb0a2eb

Browse files
dschoGit for Windows Build Agent
authored andcommitted
cmake: generalize the handling of the UNIT_TEST_OBJS list
In a15d446 (cmake: also build unit tests, 2023-09-25), I accommodated the CMake definition. Seeing that a `UNIT_TEST_OBJS` list was introduced that was built by transforming the `UNIT_TEST_PROGRAMS` list and then adding a single, hard-coded file ("t/unit-tests/test-lib.c"), I decided to hard-code that in the CMake definition, too. The reason why I hard-coded it instead of imitating the `parse_makefile_for_sources()` paradigm that was used elsewhere when using the `Makefile` as source of truth for given lists of files: This function expects _only_ hard-coded values, and that transformed `UNIT_TEST_PROGRAMS` list complicated everything. In 8727215 (cmake: fix build of `t-oidtree`, 2024-07-12), I accommodated the CMake definition again, after seeing that the `UNIT_TEST_OBJS` was still defined via that transformed list but now appending _two_ hard-coded files ("t/unit-tests/lib-oid.c" joined the fray). In e7e6d74 (Makefile: stop listing test library objects twice, 2024-09-09), the `Makefile` was changed so that `UNIT_TEST_OBJS` is finally only constructed using hard-coded file names just like the other `*_OBJS` variables. I missed that and therefore did not adjust the CMake definition. Besides, the code was working, so there was no real need to adjust it. With 4d76732 (t/unit-tests: introduce reftable library, 2024-09-09), however, the `UNIT_TEST_OBJS` list became a trio, and the CMake definition has to be adjusted again. Now that we can use the `parse_makefile_for_sources()` function without many complications, let's do that. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5611793 commit fb0a2eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,13 +1000,14 @@ add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
10001000
target_link_libraries(test-fake-ssh common-main)
10011001

10021002
#unit-tests
1003-
add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
1004-
add_library(unit-test-lib-oid OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/lib-oid.c)
1003+
parse_makefile_for_sources(unit-test_SOURCES "UNIT_TEST_OBJS")
1004+
list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/")
1005+
add_library(unit-test-lib STATIC ${unit-test_SOURCES})
10051006

10061007
parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "")
10071008
foreach(unit_test ${unit_test_PROGRAMS})
10081009
add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c")
1009-
target_link_libraries("${unit_test}" unit-test-lib unit-test-lib-oid common-main)
1010+
target_link_libraries("${unit_test}" unit-test-lib common-main)
10101011
set_target_properties("${unit_test}"
10111012
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
10121013
if(MSVC)

0 commit comments

Comments
 (0)