From 77c6bd9f38c96a568d851beef185aeb9930de7b4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Sep 2024 19:21:16 +0000 Subject: [PATCH 1/3] cmake: rename clar-related variables to avoid confusion In c3de556a841f (Makefile: rename clar-related variables to avoid confusion, 2024-09-10) some `Makefile` variables were renamed that were partially used by the CMake definition. Adapt the latter to the new lay of the land. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/buildsystems/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 608fd3fe70..7890bc40c5 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -1004,14 +1004,14 @@ foreach(unit_test ${unit_test_PROGRAMS}) endif() endforeach() -parse_makefile_for_scripts(unit_tests_SUITES "UNIT_TESTS_SUITES" "") +parse_makefile_for_scripts(clar_test_SUITES "CLAR_TEST_SUITES" "") set(clar_decls "") set(clar_cbs "") set(clar_cbs_count 0) set(clar_suites "static struct clar_suite _clar_suites[] = {\n") -list(LENGTH unit_tests_SUITES clar_suites_count) -foreach(suite ${unit_tests_SUITES}) +list(LENGTH clar_test_SUITES clar_suites_count) +foreach(suite ${clar_test_SUITES}) file(STRINGS "${CMAKE_SOURCE_DIR}/t/unit-tests/${suite}.c" decls REGEX "^void test_${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*\\(void\\)$") @@ -1042,9 +1042,9 @@ string(APPEND clar_suites file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" "${clar_decls}") file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" "${clar_decls}" "${clar_cbs}" "${clar_suites}") -list(TRANSFORM unit_tests_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/") -list(TRANSFORM unit_tests_SUITES APPEND ".c") -add_library(unit-tests-lib ${unit_tests_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c") +list(TRANSFORM clar_test_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/") +list(TRANSFORM clar_test_SUITES APPEND ".c") +add_library(unit-tests-lib ${clar_test_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c") target_include_directories(unit-tests-lib PRIVATE "${CMAKE_SOURCE_DIR}/t/unit-tests") add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c") target_link_libraries(unit-tests unit-tests-lib common-main) From 75c4d8f0448a7669447942e725cb87ce22067ff2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Sep 2024 19:23:20 +0000 Subject: [PATCH 2/3] cmake: stop looking for `REFTABLE_TEST_OBJS` in the Makefile As of 15e29ea1c648 (t: move reftable/stack_test.c to the unit testing framework, 2024-09-08), the reftable tests are no longer part of `test-tool.exe`, so let's stop looking for those lines that are no longer in the `Makefile`. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/buildsystems/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 7890bc40c5..0aeb5f984a 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -970,10 +970,6 @@ if(BUILD_TESTING) add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c) target_link_libraries(test-fake-ssh common-main) -#reftable-tests -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) add_library(unit-test-lib-oid OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/lib-oid.c) @@ -1062,7 +1058,7 @@ parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c) list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/") -add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES}) +add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES}) target_link_libraries(test-tool test-lib common-main) set_target_properties(test-fake-ssh test-tool From 8afda42fce60126fe6d3bde86a44d8db63a77c08 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Sep 2024 19:29:29 +0000 Subject: [PATCH 3/3] cmake: generalize the handling of the `UNIT_TEST_OBJS` list In a15d4465a991 (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 872721538c26 (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 428672a3b16 (Makefile: stop listing test library objects twice, 2024-09-16), 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 a4f50bb1e9b (t/unit-tests: introduce reftable library, 2024-09-16), 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 Signed-off-by: Junio C Hamano --- contrib/buildsystems/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 0aeb5f984a..62af7b33d2 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -971,13 +971,14 @@ add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c) target_link_libraries(test-fake-ssh common-main) #unit-tests -add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c) -add_library(unit-test-lib-oid OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/lib-oid.c) +parse_makefile_for_sources(unit-test_SOURCES "UNIT_TEST_OBJS") +list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/") +add_library(unit-test-lib STATIC ${unit-test_SOURCES}) 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 unit-test-lib-oid common-main) + 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/bin) if(MSVC)