# PROCESS_PACKAGE_PROPERTIES() Process additional tart.yaml properties
#
FUNCTION(PROCESS_PACKAGE_PROPERTIES PACKAGE_NAME ENTRIES ENTRY_INDENTS)
  PROCESS_TARGET_DEFAULT_PROPERTIES(${PACKAGE_NAME} "${ENTRIES}" "${ENTRY_INDENTS}")
  PROCESS_DEPENDENCY_ENTRIES(${PACKAGE_NAME} "${ENTRIES}" "${ENTRY_INDENTS}")
  PROCESS_TARGET_PROPERTIES(${PACKAGE_NAME} "${ENTRIES}" "${ENTRY_INDENTS}")
  PROCESS_TARGET_CUSTOM_CONFIG_PROPERTIES(${PACKAGE_NAME} "${ENTRIES}" "${ENTRY_INDENTS}")
  PROCESS_TARGET_OS_PROPERTIES(${PACKAGE_NAME} "${ENTRIES}" "${ENTRY_INDENTS}")
  PROCESS_TARGET_ARCH_PROPERTIES(${PACKAGE_NAME} "${ENTRIES}" "${ENTRY_INDENTS}")
ENDFUNCTION()

# PROCESS_TARGET_PROPERTIES() Process entries of the target properties list from a tart.yaml file
#
FUNCTION(PROCESS_TARGET_PROPERTIES PACKAGE_TARGET ENTRIES ENTRY_INDENTS)
  GET_ENTRY_VALUES("target_properties" "${ENTRIES}" "${ENTRY_INDENTS}" TARGET_PROPERTIES HAS_SUBTREE)
  TART_DEBUG("Processing target_properties: ${TARGET_PROPERTIES}")
  
  FOREACH(TARGET_PROPERTY ${TARGET_PROPERTIES})
    STRING(REGEX MATCH "^.+[ ]" PROPERTY_KEY "${TARGET_PROPERTY}")
    STRING(STRIP ${PROPERTY_KEY} PROPERTY_KEY)
    TART_DEBUG("TARGET_PROPERTY: ${PROPERTY_KEY}")
    STRING(REGEX MATCH "[ ].+$" PROPERTY_VALUE "${TARGET_PROPERTY}")
    STRING(STRIP ${PROPERTY_VALUE} PROPERTY_VALUE)
    TART_DEBUG("TARGET_PROPERTY value: ${PROPERTY_VALUE}")
    SET_TARGET_PROPERTIES(${PACKAGE_TARGET} PROPERTIES "${PROPERTY_KEY}" "${PROPERTY_VALUE}")
  ENDFOREACH()
ENDFUNCTION(PROCESS_TARGET_PROPERTIES)

# PROCESS_TARGET_CUSTOM_CONFIG_PROPERTIES() Process entries of the custom configuration properties list from a tart.yaml file
#
FUNCTION(PROCESS_TARGET_CUSTOM_CONFIG_PROPERTIES PACKAGE_TARGET ENTRIES ENTRY_INDENTS)
  GET_ENTRY_VALUES("custom_configuration_properties" "${ENTRIES}" "${ENTRY_INDENTS}" CUSTOM_CONFIGURATIONS HAS_SUBTREE)
  TART_DEBUG("Processing custom_configuration_properties: ${CUSTOM_CONFIGURATIONS}")
  
  FOREACH(CUSTOM_CONFIG ${CUSTOM_CONFIGURATIONS})
    GET_ENTRY_VALUES(${CUSTOM_CONFIG} "${ENTRIES}" "${ENTRY_INDENTS}" SPECIFIC_CONFIG_PROPERTIES HAS_SUBTREE)
    FOREACH(SPECIFIC_CONFIG_PROPERTY ${SPECIFIC_CONFIG_PROPERTIES})
      STRING(REGEX MATCH "^.+[ ]" PROPERTY_KEY "${SPECIFIC_CONFIG_PROPERTY}")
      STRING(STRIP ${PROPERTY_KEY} PROPERTY_KEY)
      TART_DEBUG("   ${CUSTOM_CONFIG} property: ${PROPERTY_KEY}")
      STRING(REGEX MATCH "[ ].+$" PROPERTY_VALUE "${SPECIFIC_CONFIG_PROPERTY}")
      STRING(STRIP ${PROPERTY_VALUE} PROPERTY_VALUE)
      TART_DEBUG("   ${CUSTOM_CONFIG} value: ${PROPERTY_VALUE}")
      SET_TARGET_PROPERTIES(${PACKAGE_TARGET} PROPERTIES "${PROPERTY_KEY}" "${PROPERTY_VALUE}")
    ENDFOREACH()
  ENDFOREACH()
ENDFUNCTION(PROCESS_TARGET_CUSTOM_CONFIG_PROPERTIES)

# PROCESS_TARGET_OS_PROPERTIES() Process entries of the custom configuration properties list from a tart.yaml file
#
FUNCTION(PROCESS_TARGET_OS_PROPERTIES PACKAGE_TARGET ENTRIES ENTRY_INDENTS)
  GET_ENTRY_VALUES("target_os_properties" "${ENTRIES}" "${ENTRY_INDENTS}" TARGET_OS_LIST HAS_SUBTREE)
  TART_DEBUG("Processing target_os_properties: ${TARGET_OS_LIST}")
  TART_DEBUG("TART_TARGET_OS: ${TART_TARGET_OS}")
  
  FOREACH(TARGET_OS ${TARGET_OS_LIST})
    IF(${TART_TARGET_OS} STREQUAL ${TARGET_OS})
    ELSE()
      CONTINUE()
    ENDIF()
    GET_ENTRY_VALUES(${TARGET_OS} "${ENTRIES}" "${ENTRY_INDENTS}" TARGET_OS_PROPERTIES HAS_SUBTREE)
    FOREACH(TARGET_OS_PROPERTY ${TARGET_OS_PROPERTIES})
      STRING(REGEX MATCH "^.+[ ]*" PROPERTY_KEY "${TARGET_OS_PROPERTY}")
      STRING(STRIP ${PROPERTY_KEY} PROPERTY_KEY)
      TART_DEBUG("   ${TARGET_OS} property: ${PROPERTY_KEY}")
      STRING(REGEX MATCH "[ ].+$" PROPERTY_VALUE "${TARGET_OS_PROPERTY}")
      STRING(STRIP ${PROPERTY_VALUE} PROPERTY_VALUE)
      IF(${PROPERTY_VALUE})
        TART_DEBUG("   ${TARGET_OS} value: ${PROPERTY_VALUE}")
        SET_TARGET_PROPERTIES(${PACKAGE_TARGET} PROPERTIES "${PROPERTY_KEY}" "${PROPERTY_VALUE}")
      ENDIF()
    ENDFOREACH()
  ENDFOREACH()
ENDFUNCTION(PROCESS_TARGET_OS_PROPERTIES)

# PROCESS_TARGET_ARCH_PROPERTIES() Process entries of the custom configuration properties list from a tart.yaml file
#
FUNCTION(PROCESS_TARGET_ARCH_PROPERTIES PACKAGE_TARGET ENTRIES ENTRY_INDENTS)
  GET_ENTRY_VALUES("target_arch_properties" "${ENTRIES}" "${ENTRY_INDENTS}" TARGET_ARCH_LIST HAS_SUBTREE)
  TART_DEBUG("Processing target_arch_properties: ${TARGET_ARCH_LIST}")
  TART_DEBUG("TART_TARGET_ARCH: ${TART_TARGET_ARCH}")
  
  FOREACH(TARGET_ARCH ${TARGET_ARCH_LIST})
    IF(${TART_TARGET_ARCH} STREQUAL ${TARGET_ARCH})
    ELSE()
      CONTINUE()
    ENDIF()
    GET_ENTRY_VALUES(${TARGET_ARCH} "${ENTRIES}" "${ENTRY_INDENTS}" TARGET_ARCH_PROPERTIES HAS_SUBTREE)
    FOREACH(TARGET_ARCH_PROPERTY ${TARGET_ARCH_PROPERTIES})
      STRING(REGEX MATCH "^.+[ ]*" PROPERTY_KEY "${TARGET_ARCH_PROPERTY}")
      STRING(STRIP ${PROPERTY_KEY} PROPERTY_KEY)
      TART_DEBUG("   ${TARGET_ARCH} property: ${PROPERTY_KEY}")
      STRING(REGEX MATCH "[ ].+$" PROPERTY_VALUE "${TARGET_ARCH_PROPERTY}")
      STRING(STRIP ${PROPERTY_VALUE} PROPERTY_VALUE)
      IF(${PROPERTY_VALUE})
        TART_DEBUG("   ${TARGET_ARCH} value: ${PROPERTY_VALUE}")
        SET_TARGET_PROPERTIES(${PACKAGE_TARGET} PROPERTIES "${PROPERTY_KEY}" "${PROPERTY_VALUE}")
      ENDIF()
    ENDFOREACH()
  ENDFOREACH()
ENDFUNCTION(PROCESS_TARGET_ARCH_PROPERTIES)
