cmake:if(file1 IS_NEWER_THAN file2)坏了吗?

时间:2016-11-17 20:15:29

标签: cmake

作为构建过程的一部分,我们将构建的二进制文件安装到某个位置。

我有一个自定义的cmake脚本,用于检查构建的二进制文件的时间戳,如果它比已安装的二进制文件更新,则复制它。

以下是该剧本的摘录:

if(SRC_FILE IS_NEWER_THAN DEST_FILE)
    message(STATUS "installing ${DEST_FILE}")

    execute_process(
        COMMAND
            ${CMAKE_COMMAND} -E make_directory ${INSTALL_DIR}

        COMMAND
            ${CMAKE_COMMAND} -E copy ${SRC_FILE} ${DEST_FILE}

        # copy preserves timestamps, so touch to make the installed file newer
        COMMAND
            ${CMAKE_COMMAND} -E touch ${DEST_FILE} 
      )
endif()

出于某种原因,我继续从true返回IS_NEWER_THAN,所以我添加了一些调试语句来打印出两个文件的时间戳:

file(TIMESTAMP ${DEST_FILE} DEST_TIMESTAMP)
file(TIMESTAMP ${SRC_FILE} SRC_TIMESTAMP)

message("DST_FILE: ${DEST_TIMESTAMP} ${DEST_FILE}")
message("SRC_FILE: ${SRC_TIMESTAMP} ${SRC_FILE}")

if(SRC_FILE IS_NEWER_THAN DEST_FILE)
    message("SRC is newer than DEST")
endif()

以下是一些示例输出:

DST_FILE: 2016-11-17T15:08:28 /home/steve/src/install/app
SRC_FILE: 2016-11-17T14:56:35 /home/steve/src/.build/app/app.bin
SRC is newer than DEST

这清楚地表明SRC_FILE创建了14:56:35,而DEST_FILE创建了15:08:28

IS_NEWER_THAN true SRC_FILE如何回归<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="" Text="Edit" OnClientClick='<%# Eval("ID", "window.open(\"EditFrm.aspx?ID={0}\", null, \"width=700,height=600,top=100,left=300\", \"true\");") %> '/>

2 个答案:

答案 0 :(得分:1)

我遇到的另一个问题是相对文件名。正如 documentation 所指示的,IS_NEWER_THAN 仅适用于绝对路径。一种解决方法可能是像这样创建文件名变量:

set(${PROJECT_NAME}_param_file ${CMAKE_SOURCE_DIR}/param/file)

答案 1 :(得分:0)

the documentation可以看出,if(file1 IS_NEWER_THAN file2)需要两个文件名,而不是变量。

if(file1 IS_NEWER_THAN file2)
    True if file1 is newer than file2 or if one of the two files doesn’t exist.

因此,您需要评估变量,以便将实际路径传递给if

那是:

<强>不正确:

if(SRC_FILE IS_NEWER_THAN DEST_FILE)

<强>正确:

if(${SRC_FILE} IS_NEWER_THAN ${DEST_FILE})
相关问题