CMake copy if original file changed

后端 未结 3 851
無奈伤痛
無奈伤痛 2021-01-07 23:08

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 ta

3条回答
  •  隐瞒了意图╮
    2021-01-08 00:03

    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 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.

提交回复
热议问题