generated.h
是由目前替换为touch
的脚本创建的。如何在每次运行make
时重新生成此文件?如下例所示调用rm
会产生错误。
cmake_minimum_required(VERSION 3.5.1)
project(MyProject)
set_source_files_properties(generated.h PROPERTIES GENERATED TRUE)
add_executable(jr
jr.cpp
generated.h
)
add_custom_command(
OUTPUT generated.h
COMMAND rm generated.h
COMMAND touch generated.h
)
答案 0 :(得分:1)
而不是add_custom_command
使用add_custom_target:每次运行构建时都会执行它:
add_custom_target(regenerate
COMMAND rm -f generated.h # Remove file if it exists.
COMMAND touch generated.h
)
# Force executable to be compiled after regeneration takes a place
add_dependencies(jr regenerate)
# You need to hint compiler about location of the header file generated.
include_directories(${CMAKE_CURRENT_BINARY_DIR})