# Reads a Makefile into CMake vars.
# TODO: respect IFDEF/IFNDEF?
-# TODO: regex replace makefile vars, e.g. $(TSUFFIX) is set to the target arch in the var CGEMMOTCOPYOBJ = cgemm_otcopy$(TSUFFIX).$(SUFFIX)
macro(ParseMakefileVars MAKEFILE_IN)
message(STATUS "Reading vars from ${MAKEFILE_IN}...")
file(STRINGS ${MAKEFILE_IN} makefile_contents)
if (NOT "${line_match}" STREQUAL "")
set(var_name ${CMAKE_MATCH_1})
set(var_value ${CMAKE_MATCH_2})
+ # check for Makefile variables in the string, e.g. $(TSUFFIX)
+ string(REGEX MATCHALL "\\$\\(([0-9_a-zA-Z]+)\\)" make_var_matches ${var_value})
+ foreach (make_var ${make_var_matches})
+ # strip out Makefile $() markup
+ string(REGEX REPLACE "\\$\\(([0-9_a-zA-Z]+)\\)" "\\1" make_var ${make_var})
+ # now replace the instance of the Makefile variable with the value of the CMake variable (note the double quote)
+ string(REPLACE "$(${make_var})" "${${make_var}}" var_value ${var_value})
+ endforeach ()
set(${var_name} ${var_value})
- message(STATUS "found var ${var_name} = ${var_value}")
else ()
string(REGEX MATCH "include \\$\\(KERNELDIR\\)/(.+)$" line_match "${makefile_line}")
if (NOT "${line_match}" STREQUAL "")
ParseMakefileVars(${KERNELDIR}/${CMAKE_MATCH_1})
- else ()
- message(STATUS "couldn't parse ${makefile_line} into a var")
endif ()
endif ()
endforeach ()
set(defines_in ${ARGV1})
endif ()
- if (DEFINED ARGV2)
+ if (DEFINED ARGV2 AND NOT "${ARGV2}" STREQUAL "")
set(name_in ${ARGV2})
+ # strip off extension for kernel files that pass in the object name.
+ get_filename_component(name_in ${name_in} NAME_WE)
endif ()
if (DEFINED ARGV3)