繁体   English   中英

cmake:每次生成时都重新生成文件

[英]cmake: regenerate file with each build

由脚本(暂时替换为touch )创建generated.h 如何在每次运行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
        )

代替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})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM