[cmake-developers] [CMake 0014904]: Gettext module does not allow installing .po files with the same name from different directories

Mantis Bug Tracker mantis at public.kitware.com
Mon May 5 10:16:36 EDT 2014


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=14904 
====================================================================== 
Reported By:                Aurélien Gâteau
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14904
Category:                   Modules
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2014-05-05 10:16 EDT
Last Modified:              2014-05-05 10:16 EDT
====================================================================== 
Summary:                    Gettext module does not allow installing .po files
with the same name from different directories
Description: 
I have the following directory hierarchy:

app/
  src/
  po/
    es/
      app.po
    fr/
      app.po
  CMakeLists.txt

I would like to have all code handling the translation files in the top-level
CMakeLists.txt file so that new translations can be added inside the "po"
directory without adding any CMake code.

app/CMakeLists.txt looks like this:

    find_package(Gettext REQUIRED)

    foreach(lang fr es)
        gettext_process_po_files(${lang} ALL
            INSTALL_DESTINATION share/locale
            PO_FILES po/${lang}/test.po)
    endforeach()

But this does not work. Running CMake outputs the following error:

CMake Error: Attempt to add a custom rule to output
"(...)/app/build/app.gmo.rule" which already has a custom rule.

Steps to Reproduce: 
- Unpack attached test-case
- Run cmake

Additional Information: 
I worked around that bug by copying the code from gettext_process_po_files() in
my project and adjusting it like this:

diff --git a/Modules/FindGettext.cmake b/Modules/FindGettext.cmake
index 6a1e36e..4b3ada7 100644
--- a/Modules/FindGettext.cmake
+++ b/Modules/FindGettext.cmake
@@ -203,7 +203,7 @@ function(GETTEXT_PROCESS_PO_FILES _lang)
    foreach(_current_PO_FILE ${_parsedArguments_PO_FILES})
       get_filename_component(_name ${_current_PO_FILE} NAME)
       string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _basename ${_name})
-      set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo)
+      set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}-${_basename}.gmo)
       add_custom_command(OUTPUT ${_gmoFile}
             COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile}
${_current_PO_FILE}
             WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
@@ -211,7 +211,7 @@ function(GETTEXT_PROCESS_PO_FILES _lang)
          )
 
       if(_parsedArguments_INSTALL_DESTINATION)
-         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo DESTINATION
${_parsedArguments_INSTALL_
+         install(FILES ${_gmoFile} DESTINATION
${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES
       endif()
       list(APPEND _gmoFiles ${_gmoFile})
    endforeach()

Not sure if this is the best fix, though.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2014-05-05 10:16 Aurélien GâteauNew Issue                                    
2014-05-05 10:16 Aurélien GâteauFile Added: cmake-gettext-pofile-name.tar.bz2 
                  
======================================================================



More information about the cmake-developers mailing list