diff --git a/cmake/catkin_libraries.cmake b/cmake/catkin_libraries.cmake index b19f4c8aa..dc614e630 100644 --- a/cmake/catkin_libraries.cmake +++ b/cmake/catkin_libraries.cmake @@ -70,26 +70,7 @@ endfunction() # @public # function(catkin_pack_libraries_with_build_configuration VAR) - set(result "") - set(_argn ${ARGN}) - list(LENGTH _argn _count) - set(_index 0) - while(${_index} LESS ${_count}) - list(GET _argn ${_index} lib) - if("${lib}" MATCHES "^(debug|optimized|general)$") - math(EXPR _index "${_index} + 1") - if(${_index} EQUAL ${_count}) - message(FATAL_ERROR "catkin_pack_libraries_with_build_configuration() the list of libraries '${_argn}' ends with '${lib}' which is a build configuration keyword and must be followed by a library") - endif() - list(GET _argn ${_index} library) - list(APPEND result "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}") - else() - list(APPEND result "${lib}") - endif() - math(EXPR _index "${_index} + 1") - endwhile() - #debug_message(10 "catkin_pack_libraries_with_build_configuration(${VAR} ${_argn}) ${result}") - set(${VAR} "${result}" PARENT_SCOPE) + string(REGEX REPLACE "(^|;)(debug|optimized|general);([^;]+)(;|$)" "\\1\\2${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}\\3\\4" ${VAR} "${ARGN}") endfunction() # @@ -104,14 +85,7 @@ endfunction() # @public # function(catkin_unpack_libraries_with_build_configuration VAR) - set(result "") - foreach(lib ${ARGN}) - string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}") - list(APPEND result "${lib}") - endforeach() - #set(_argn ${ARGN}) - #debug_message(10 "catkin_unpack_libraries_with_build_configuration(${VAR} ${_argn}) ${result}") - set(${VAR} "${result}" PARENT_SCOPE) + string(REGEX REPLACE "(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}([^;]+)" "\\1;\\2" ${VAR} "${ARGN}") endfunction() # diff --git a/cmake/list_append_deduplicate.cmake b/cmake/list_append_deduplicate.cmake index e59a61bb1..5c56099c3 100644 --- a/cmake/list_append_deduplicate.cmake +++ b/cmake/list_append_deduplicate.cmake @@ -1,11 +1,6 @@ # # Append elements to a list and remove existing duplicates from the list. # -# .. note:: Using CMake's ``list(APPEND ..)`` and -# ``list(REMOVE_DUPLICATES ..)`` is not sufficient since its -# implementation uses a set internally which makes the operation -# unstable. -# macro(list_append_deduplicate listname) if(NOT "${ARGN}" STREQUAL "") if(${listname}) diff --git a/cmake/list_append_unique.cmake b/cmake/list_append_unique.cmake index 4c9bb1df8..a6163cd62 100644 --- a/cmake/list_append_unique.cmake +++ b/cmake/list_append_unique.cmake @@ -1,16 +1,9 @@ # # Append elements to a list if they are not already in the list. # -# .. note:: Using CMake's ``list(APPEND ..)`` and -# ``list(REMOVE_DUPLICATES ..)`` is not sufficient since its -# implementation uses a set internally which makes the operation -# unstable. -# macro(list_append_unique listname) - foreach(_item ${ARGN}) - list(FIND ${listname} ${_item} _index) - if(_index EQUAL -1) - list(APPEND ${listname} ${_item}) - endif() - endforeach() + if(NOT "${ARGN}" STREQUAL "") + list(APPEND ${listname} ${ARGN}) + list(REMOVE_DUPLICATES ${listname}) + endif() endmacro() diff --git a/cmake/templates/pkgConfig.cmake.in b/cmake/templates/pkgConfig.cmake.in index 8740d9944..e2f7d0ed7 100644 --- a/cmake/templates/pkgConfig.cmake.in +++ b/cmake/templates/pkgConfig.cmake.in @@ -16,47 +16,24 @@ endmacro() # copied from catkin/cmake/list_append_unique.cmake to keep pkgConfig # self contained macro(_list_append_unique listname) - foreach(_item ${ARGN}) - list(FIND ${listname} ${_item} _index) - if(_index EQUAL -1) - list(APPEND ${listname} ${_item}) - endif() - endforeach() + if(NOT "${ARGN}" STREQUAL "") + list(APPEND ${listname} ${ARGN}) + list(REMOVE_DUPLICATES ${listname}) + endif() endmacro() # pack a list of libraries with optional build configuration keywords # copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig # self contained macro(_pack_libraries_with_build_configuration VAR) - set(${VAR} "") - set(_argn ${ARGN}) - list(LENGTH _argn _count) - set(_index 0) - while(${_index} LESS ${_count}) - list(GET _argn ${_index} lib) - if("${lib}" MATCHES "^(debug|optimized|general)$") - math(EXPR _index "${_index} + 1") - if(${_index} EQUAL ${_count}) - message(FATAL_ERROR "_pack_libraries_with_build_configuration() the list of libraries '${ARGN}' ends with '${lib}' which is a build configuration keyword and must be followed by a library") - endif() - list(GET _argn ${_index} library) - list(APPEND ${VAR} "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}") - else() - list(APPEND ${VAR} "${lib}") - endif() - math(EXPR _index "${_index} + 1") - endwhile() + string(REGEX REPLACE "(^|;)(debug|optimized|general);([^;]+)(;|$)" "\\1\\2${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}\\3\\4" ${VAR} "${ARGN}") endmacro() # unpack a list of libraries with optional build configuration keyword prefixes # copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig # self contained macro(_unpack_libraries_with_build_configuration VAR) - set(${VAR} "") - foreach(lib ${ARGN}) - string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}") - list(APPEND ${VAR} "${lib}") - endforeach() + string(REGEX REPLACE "(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}([^;]+)" "\\1;\\2" ${VAR} "${ARGN}") endmacro()