git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sources

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Sep 9, 2026, 19:50 UTC
Message-ID
<20260909195006.2179119-3-szeder.dev@gmail.com>
In-Reply-To
<20260909195006.2179119-1-szeder.dev@gmail.com>

To get various lists of files, CMake parses our Makefile looking for lines matching e.g. "list_var += ...". In case of LIB_OBJS this picks up the line "LIB_OBJS += $(COMPAT_OBJS)" as well, so the parsing macro has a specific instruction to remove "$(COMPAT_OBJS)" from the resulting list.

Currently this is the only such Makefile variable to be removed from the list, but the next patches will (re)introduce more variables containing lists of object files, so let's generalize that removing instruction to remove any "$(*_OBJS)" Makefile variable as well.

Note that we can't make the pattern matching the Makefile variable too general, e.g. to match any "$(VARIABLE)", because some lines of our Makefile do contain variables as directory prefixes, e.g. "UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o", and we must definitely keep those.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---

I rarely do CMake, so it's quite possible that this is not the most straightforward or idiomatic approach.

 contrib/buildsystems/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 8f56203f34..241da0d43a 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -102,7 +102,7 @@ project(git
 macro(parse_makefile_for_sources list_var makefile regex)
 	file(STRINGS ${makefile} ${list_var} REGEX "^${regex} \\+=(.*)")
 	string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
-	string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit.
+	string(REGEX REPLACE "\\$\\([^)]*_OBJS\\)" "" ${list_var} ${${list_var}}) # remove any "$(*_OBJS)" variables
 	string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
 	string(REPLACE ".o" ".c;" ${list_var} ${${list_var}}) #change .o to .c, ; is for converting the string into a list
 	list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list
-- 
2.55.0.1193.g1b994e35de
Previous: SZEDER GáborNext: SZEDER Gábor
Message 3 of 15 in “make: precompile "git-compat-util.h"”
  1. 0/4 make: precompile "git-compat-util.h"SZEDER Gábor, Sep 9, 2026
  2. 1/4 Makefile: remove XDIFF_OBJS initializationSZEDER Gábor, Sep 9, 2026
  3. 2/4 cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sourcesSZEDER Gábor, Sep 9, 2026
  4. 3/4 Makefile: reintroduce REFTABLE_OBJSSZEDER Gábor, Sep 9, 2026
  5. Junio C HamanoSep 9, 2026
  6. 4/4 Makefile: precompile "git-compat-util.h"SZEDER Gábor, Sep 9, 2026
  7. SZEDER GáborSep 9, 2026
  8. 0/4 make: precompile "git-compat-util.h"SZEDER Gábor, Sep 15, 2026
  9. 1/4 Makefile: remove XDIFF_OBJS initializationSZEDER Gábor, Sep 15, 2026
  10. 2/4 cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sourcesSZEDER Gábor, Sep 15, 2026
  11. 3/4 Makefile: reintroduce REFTABLE_OBJSSZEDER Gábor, Sep 15, 2026
  12. 4/4 Makefile: precompile "git-compat-util.h"SZEDER Gábor, Sep 15, 2026
  13. Jeff KingSep 24, 2026
  14. SZEDER GáborSep 25, 2026
  15. SZEDER GáborOct 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.