cmake后期构建中的递归搜索

问题描述

我希望在一个目录中包含 CMake 中具有特定扩展名的所有文件。这些扩展文件是在运行构建后生成的。 我试过了

(() => {
  const activeTimers = new Set();
  const _setTimeout = window.setTimeout;
  const _setInterval = window.setInterval;
  const _clearTimeout = window.clearTimeout;
  const _clearInterval = window.clearInterval;
  
  window.setTimeout = (cb,duration) => {
    let id = -1;
    
    const wrapper = (...args) => {
      activeTimers.delete(id);
      cb(...args);
    }
    
    id = _setTimeout(wrapper,duration);
    
    activeTimers.add(id);
    
    return id;
  };
  
  window.setInterval = (cb,duration) => {
    const id = _setInterval(cb,duration);
    activeTimers.add(id);
    return id;
  };
  
  window.clearTimeout = (id) => {
    _clearTimeout(id);
    activeTimers.delete(id);
  };
  
  window.clearInterval = (id) => {
    _clearInterval(id);
    activeTimers.delete(id);
  };
  
  // YOU CAN EXPORT THIS METHOD FROM A MODULE INSTEAD OF ADDING IT TO THE window OBJECT.
  window.getActiveTimers = () => {
    return Array.from(activeTimers.values());
  };
})();

// USAGE:

console.log('INITIAL TIMERS:',getActiveTimers());

// EXAMPLE 1

setTimeout(() => {
  console.log('TIMER 1 FINISHED:',getActiveTimers());
},1000);
console.log('TIMER 1 ADDED: ',getActiveTimers().toString());

// EXAMPLE 2

const timer2Id = setTimeout(() => {
  console.log('TIMER 2 FINISHED:',1000);
console.log('TIMER 2 ADDED: ',getActiveTimers().toString());

clearTimeout(timer2Id);
console.log('TIMER 2 REMOVED: ',getActiveTimers().toString());

// EXPECTED OUTPUT ORDER: [] -> 1 -> 1,2 -> 1 -> []

但是这是在运行构建之前执行的。我想要这样的东西

file(GLOB_RECURSE GCOV_OBJECTS $ENV{OUTPUT_UT_DIR} *Test.cpp.o)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND my_command_to_get_all_desired_files 中使用文件命令给我一个语法错误。不知道如何从这里开始。

解决方法

创建一个 cmake 脚本:

# mycmakescript.cmake
file(GLOB_RECURSE GCOV_OBJECTS $ENV{OUTPUT_UT_DIR} *Test.cpp.o)
message("${GCOV_OBJECTS}")
#  I need to execute a command on those files. like gcov ${GCOV_OBJECTS}
execute_process(COMMAND gvoc ${GCOV_OBJECTS})

并在构建时调用它:

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
              COMMAND cmake -P mycmakescript.cmake)