#!/bin/bash
# Usage: $0 <TARGET-NAME> <PRIVATE_EXCLUDE>

PRIVATE=()
PUBLIC=()
while IFS= read -r source; do
  if grep -q "Q_OBJECT" "$source"; then
    PRIVATE+=("$source")
  else
    PUBLIC+=("$source")
  fi
done < <(find include \( -name "*.h" -or -name "*.hpp" -or -name "*.inl" \) | LC_ALL=C sort)

while IFS= read -r source; do
  if [[ $source != "$2" ]]; then
    PRIVATE+=("$source")
  fi
done < <(find src \( -name "*.c" -or -name "*.cpp" \) | LC_ALL=C sort)

echo "# This file was autogenerated using '$0 $*' - DO NOT EDIT"
echo
echo "target_sources($1"
echo "  PUBLIC"
for source in "${PUBLIC[@]}"; do
  echo "    \"\${CMAKE_CURRENT_SOURCE_DIR}/$source\""
done
echo "  PRIVATE"
for source in "${PRIVATE[@]}"; do
  echo "    \"\${CMAKE_CURRENT_SOURCE_DIR}/$source\""
done
echo ")"
