Hey. I looked everywhere for this and couldn’t find anything. So basically I’m looking for a way to create a target that is dependent on existing files. For example, let’s say I have a bunch of python files in my repo and I want to create a target named lint_python_files that runs pylint on them. If I run the target once it should lint all python files. If I run it again right after, it should know that none of the python files have changed and just skip linting entirely. If I then touch/change a single python file and then run the target, then I’d like only that file to be linted. I have created a custom function that does this, but was wondering if there’s a smarter way to do this or if there’s a builtin function for this?
function(add_glob_targets)
  cmake_parse_arguments(SMART
    ""
    "TARGET;COMMAND"
    "FLAGS;FILES"
    ${ARGN}
  )
  set(touch_dir ${TOUCHES_DIR}/${SMART_TARGET})
  file(MAKE_DIRECTORY ${touch_dir})
  foreach(f ${SMART_FILES})
    string(REPLACE "/" "_" filename ${f})
    set(touch_file ${touch_dir}/${filename})
    add_custom_command(
      OUTPUT ${touch_file}
      COMMAND ${CMAKE_COMMAND} -E touch ${touch_file}
      COMMAND ${PRG} ${SMART_FLAGS} ${f}
      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
      DEPENDS ${f})
    list(APPEND touch_list ${touch_file})
  endforeach()
  add_custom_target(${SMART_TARGET} DEPENDS ${touch_list})
endfunction()