4edf8b6d9a51aae13bb7ae5cafc7479c253871a6
[platform/upstream/curl.git] / CMake / Utilities.cmake
1 # File containing various utilities
2
3 # Converts a CMake list to a string containing elements separated by spaces
4 FUNCTION(TO_LIST_SPACES _LIST_NAME OUTPUT_VAR)
5   SET(NEW_LIST_SPACE)
6   FOREACH(ITEM ${${_LIST_NAME}})
7     SET(NEW_LIST_SPACE "${NEW_LIST_SPACE} ${ITEM}")
8   ENDFOREACH()
9   STRING(STRIP ${NEW_LIST_SPACE} NEW_LIST_SPACE)
10   SET(${OUTPUT_VAR} "${NEW_LIST_SPACE}" PARENT_SCOPE)
11 ENDFUNCTION()
12
13 # Appends a lis of item to a string which is a space-separated list, if they don't already exist.
14 FUNCTION(LIST_SPACES_APPEND_ONCE LIST_NAME)
15   STRING(REPLACE " " ";" _LIST ${${LIST_NAME}})
16   LIST(APPEND _LIST ${ARGN})
17   LIST(REMOVE_DUPLICATES _LIST)
18   TO_LIST_SPACES(_LIST NEW_LIST_SPACE)
19   SET(${LIST_NAME} "${NEW_LIST_SPACE}" PARENT_SCOPE)
20 ENDFUNCTION()
21
22 # Convinience function that does the same as LIST(FIND ...) but with a TRUE/FALSE return value.
23 # Ex: IN_STR_LIST(MY_LIST "Searched item" WAS_FOUND)
24 FUNCTION(IN_STR_LIST LIST_NAME ITEM_SEARCHED RETVAL)
25         LIST(FIND ${LIST_NAME} ${ITEM_SEARCHED} FIND_POS)
26         IF(${FIND_POS} EQUAL -1)
27                 SET(${RETVAL} FALSE PARENT_SCOPE)
28         ELSE()
29                 SET(${RETVAL} TRUE PARENT_SCOPE)
30         ENDIF()
31 ENDFUNCTION()