如果原始文件更改,则CMake复制 [英] CMake copy if original file changed

查看:98
本文介绍了如果原始文件更改,则CMake复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CMake中,我有一个包含预定义Gettext目录的文件夹,在构建时我将其复制到一个文件夹中,然后对其进行修改。但是问题在于,每次运行目标时,它都会将预定义文件复制到本地副本(可能已修改)上。如果文件与以前的状态不同,是否可以复制,否则就别管它了吗?

In CMake I have a folder containing predefined Gettext catalogs, which at build time I copy to a folder and then modify them. But the problem is that every time I run the target it'll copy the predefined file on the local copy (which is probably modified). Is there a way to copy if the file is different to a state it was before, otherwise leave it alone?

我还想一种实现此目的的方法是在CMake生成时复制它们,但是我感到有些疲倦,因为人们可能会删除文件夹并弄乱东西。另外,我不知道如何在生成时执行命令,而仅在生成时执行。

I was also thinking that a way to do this would be to copy them across at CMake generation time, but I feel a little weary of doing that as people may delete the folders and screw things up. Also I don't know how to perform commands at generation time, only at build time.

推荐答案

好的,我设法解决了前阵子,但忘记了这个答案。抱歉,所有跳过此操作却没有答案的人!

Alrighty, I managed to fix this a while back but forgot about this answer. Sorry all the people who've skipped over this and not had the answer!

# ----- Copy and merge across the po files that come with the source.

message("Copying and updating stock translations...")

file(GLOB poFiles "${stockDir}/*.po")

foreach(file ${poFiles})
  # Get the language name, like en_US or zh_CN from the name of the po file, so
  # 'en_US.po' or 'zh_CN.po' become 'en_US' or 'zh_CN.po'
  get_filename_component(langName ${file} NAME_WE)

  set(newFile "${langDir}/${langName}.po")

  if(NOT EXISTS ${newFile})
    execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
      "--output-file" ${newFile} ${file} ${potFile}
      OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)

    if(ret) # Have to do this hack as msgmerge prints to stderr.
      message(SEND_ERROR "${error}")
    endif()

    message(" '${langName}' copied.")
  elseif(${file} IS_NEWER_THAN ${newFile})
     execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
       "--update" ${newFile} ${file}
       OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)

     if(ret) # Have to do this hack as msgmerge prints to stderr.
       message(SEND_ERROR "${error}")
     endif()

     message(" '${langName}' merged.")
  endif()
endforeach()

stockDir是包含存放的po文件的目录,该文件不是用户编辑(除非提交回购协议)。 langDir在 lang下的构建目录中。它会通过,并根据文件的使用期限进行复制或更新。

stockDir is the directory containing the stocked po files that aren't meant to be user edited (unless committing to the repo). langDir is in the build directory under 'lang'. It goes through, and either copies or updates it based on the files' age.

这篇关于如果原始文件更改,则CMake复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆