Utilities.cmake 1.1 KB

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