Skip to content

Commit 43725b8

Browse files
committed
ParseMakefileVars now replaces Makefile vars with CMake vars.
1 parent 14fd3d3 commit 43725b8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cmake/utils.cmake

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ endfunction ()
1414

1515
# Reads a Makefile into CMake vars.
1616
# TODO: respect IFDEF/IFNDEF?
17-
# TODO: regex replace makefile vars, e.g. $(TSUFFIX) is set to the target arch in the var CGEMMOTCOPYOBJ = cgemm_otcopy$(TSUFFIX).$(SUFFIX)
1817
macro(ParseMakefileVars MAKEFILE_IN)
1918
message(STATUS "Reading vars from ${MAKEFILE_IN}...")
2019
file(STRINGS ${MAKEFILE_IN} makefile_contents)
@@ -23,14 +22,19 @@ macro(ParseMakefileVars MAKEFILE_IN)
2322
if (NOT "${line_match}" STREQUAL "")
2423
set(var_name ${CMAKE_MATCH_1})
2524
set(var_value ${CMAKE_MATCH_2})
25+
# check for Makefile variables in the string, e.g. $(TSUFFIX)
26+
string(REGEX MATCHALL "\\$\\(([0-9_a-zA-Z]+)\\)" make_var_matches ${var_value})
27+
foreach (make_var ${make_var_matches})
28+
# strip out Makefile $() markup
29+
string(REGEX REPLACE "\\$\\(([0-9_a-zA-Z]+)\\)" "\\1" make_var ${make_var})
30+
# now replace the instance of the Makefile variable with the value of the CMake variable (note the double quote)
31+
string(REPLACE "$(${make_var})" "${${make_var}}" var_value ${var_value})
32+
endforeach ()
2633
set(${var_name} ${var_value})
27-
message(STATUS "found var ${var_name} = ${var_value}")
2834
else ()
2935
string(REGEX MATCH "include \\$\\(KERNELDIR\\)/(.+)$" line_match "${makefile_line}")
3036
if (NOT "${line_match}" STREQUAL "")
3137
ParseMakefileVars(${KERNELDIR}/${CMAKE_MATCH_1})
32-
else ()
33-
message(STATUS "couldn't parse ${makefile_line} into a var")
3438
endif ()
3539
endif ()
3640
endforeach ()
@@ -106,8 +110,10 @@ function(GenerateNamedObjects sources_in)
106110
set(defines_in ${ARGV1})
107111
endif ()
108112

109-
if (DEFINED ARGV2)
113+
if (DEFINED ARGV2 AND NOT "${ARGV2}" STREQUAL "")
110114
set(name_in ${ARGV2})
115+
# strip off extension for kernel files that pass in the object name.
116+
get_filename_component(name_in ${name_in} NAME_WE)
111117
endif ()
112118

113119
if (DEFINED ARGV3)

0 commit comments

Comments
 (0)