FindGetText: fix multiple targets with the same name problem (CMP0002)

The functions in FindGettext create a custom target. If the functions
are called multiple times, multiple times the same target is created.
This works only if CMP0002 is set to OLD.
With this patch there is only one central target created, and each
invocation of the function creates a target with a unique name and
make the central target depend on this one.

Alex
This commit is contained in:
Alex Neundorf 2012-02-12 18:57:28 +01:00
parent 677047dda0
commit 3b48822803
1 changed files with 43 additions and 5 deletions

View File

@ -61,6 +61,17 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext
INCLUDE(CMakeParseArguments) INCLUDE(CMakeParseArguments)
FUNCTION(_GETTEXT_GET_UNIQUE_TARGET_NAME _name _unique_name)
SET(propertyName "_GETTEXT_UNIQUE_COUNTER_${_name}")
GET_PROPERTY(currentCounter GLOBAL PROPERTY "${propertyName}")
IF(NOT currentCounter)
SET(currentCounter 1)
ENDIF()
SET(${_unique_name} "${_name}_${currentCounter}" PARENT_SCOPE)
MATH(EXPR currentCounter "${currentCounter} + 1")
SET_PROPERTY(GLOBAL PROPERTY ${propertyName} ${currentCounter} )
ENDFUNCTION()
MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
# make it a real variable, so we can modify it here # make it a real variable, so we can modify it here
SET(_firstPoFile "${_firstPoFileArg}") SET(_firstPoFile "${_firstPoFileArg}")
@ -94,7 +105,15 @@ MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
ENDFOREACH (_currentPoFile ) ENDFOREACH (_currentPoFile )
ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles}) IF(NOT TARGET translations)
ADD_CUSTOM_TARGET(translations)
ENDIF()
_GETTEXT_GET_UNIQUE_TARGET_NAME(translations uniqueTargetName)
ADD_CUSTOM_TARGET(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles})
ADD_DEPENDENCIES(translations ${uniqueTargetName})
ENDMACRO(GETTEXT_CREATE_TRANSLATIONS ) ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
@ -133,11 +152,20 @@ FUNCTION(GETTEXT_PROCESS_POT_FILE _potFile)
LIST(APPEND _gmoFiles ${_gmoFile}) LIST(APPEND _gmoFiles ${_gmoFile})
ENDFOREACH (_lang ) ENDFOREACH (_lang )
IF(NOT TARGET potfiles)
ADD_CUSTOM_TARGET(potfiles)
ENDIF()
_GETTEXT_GET_UNIQUE_TARGET_NAME( potfiles uniqueTargetName)
IF(_parsedArguments_ALL) IF(_parsedArguments_ALL)
ADD_CUSTOM_TARGET(potfiles ALL DEPENDS ${_gmoFiles}) ADD_CUSTOM_TARGET(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
ELSE(_parsedArguments_ALL) ELSE(_parsedArguments_ALL)
ADD_CUSTOM_TARGET(potfiles DEPENDS ${_gmoFiles}) ADD_CUSTOM_TARGET(${uniqueTargetName} DEPENDS ${_gmoFiles})
ENDIF(_parsedArguments_ALL) ENDIF(_parsedArguments_ALL)
ADD_DEPENDENCIES(potfiles ${uniqueTargetName})
ENDFUNCTION(GETTEXT_PROCESS_POT_FILE) ENDFUNCTION(GETTEXT_PROCESS_POT_FILE)
@ -165,11 +193,21 @@ FUNCTION(GETTEXT_PROCESS_PO_FILES _lang)
LIST(APPEND _gmoFiles ${_gmoFile}) LIST(APPEND _gmoFiles ${_gmoFile})
ENDFOREACH(_current_PO_FILE) ENDFOREACH(_current_PO_FILE)
IF(NOT TARGET pofiles)
ADD_CUSTOM_TARGET(pofiles)
ENDIF()
_GETTEXT_GET_UNIQUE_TARGET_NAME( pofiles uniqueTargetName)
IF(_parsedArguments_ALL) IF(_parsedArguments_ALL)
ADD_CUSTOM_TARGET(pofiles ALL DEPENDS ${_gmoFiles}) ADD_CUSTOM_TARGET(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
ELSE(_parsedArguments_ALL) ELSE(_parsedArguments_ALL)
ADD_CUSTOM_TARGET(pofiles DEPENDS ${_gmoFiles}) ADD_CUSTOM_TARGET(${uniqueTargetName} DEPENDS ${_gmoFiles})
ENDIF(_parsedArguments_ALL) ENDIF(_parsedArguments_ALL)
ADD_DEPENDENCIES(pofiles ${uniqueTargetName})
ENDFUNCTION(GETTEXT_PROCESS_PO_FILES) ENDFUNCTION(GETTEXT_PROCESS_PO_FILES)
IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )