Skip to content

Commit

Permalink
Add depfile support to CMake rules (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreinking authored Feb 14, 2023
1 parent 46bb1c6 commit 1bec846
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/exo/cmake/AddExoLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function(add_exo_library)
list(APPEND source_files "${src}")
endforeach ()

set(intdir "${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}.exo")
set(intdir "${ARG_NAME}.exo")
set(files "${intdir}/${ARG_NAME}.c" "${intdir}/${ARG_NAME}.h")

list(TRANSFORM ARG_PYTHONPATH PREPEND "--modify;PYTHONPATH=path_list_append:")
Expand All @@ -21,10 +21,12 @@ function(add_exo_library)
$<TARGET_FILE:Exo::compiler> -o "${intdir}" --stem "${ARG_NAME}"
${source_files}
DEPENDS ${source_files}
DEPFILE "${intdir}/${ARG_NAME}.d"
VERBATIM
)

list(TRANSFORM files PREPEND "${CMAKE_CURRENT_BINARY_DIR}/")
add_library(${ARG_NAME} ${files})
add_library(${PROJECT_NAME}::${ARG_NAME} ALIAS ${ARG_NAME})
target_include_directories(${ARG_NAME} PUBLIC "$<BUILD_INTERFACE:${intdir}>")
target_include_directories(${ARG_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${intdir}>")
endfunction()
22 changes: 21 additions & 1 deletion src/exo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import importlib
import importlib.machinery
import importlib.util
import inspect
import sys
from pathlib import Path

Expand Down Expand Up @@ -32,7 +33,6 @@ def main():

outdir = Path(args.outdir)
outdir.mkdir(parents=True, exist_ok=True)
outdir = outdir.resolve(strict=True)

library = [
proc
Expand All @@ -41,6 +41,26 @@ def main():
]

exo.compile_procs(library, outdir, f"{args.stem}.c", f"{args.stem}.h")
write_depfile(outdir, args.stem)


def write_depfile(outdir, stem):
modules = set()
for mod in sys.modules.values():
try:
modules.add(inspect.getfile(mod))
except TypeError:
pass # this is the case for built-in modules

c_file = outdir / f"{stem}.c"
h_file = outdir / f"{stem}.h"
depfile = outdir / f"{stem}.d"

sep = " \\\n "
deps = sep.join(sorted(modules))
contents = f"{c_file} {h_file} : {deps}"

depfile.write_text(contents)


def get_procs_from_module(user_module):
Expand Down

0 comments on commit 1bec846

Please sign in to comment.