## @file
## @brief Contains the update xtd version number scripts.
## @remarks If you change the version of the xtd, the CMake script will detect the change automatically and update the files that need the xtd version.
## @remarks see xtd_version.cmake

################################################################################
# xtd Version

file(READ src/xtd.core/src/xtd/environment_version.cpp ENVIRONMENT_VERSION_API)
string(FIND "${ENVIRONMENT_VERSION_API}" "${XTD_VERSION}" STRING_FOUND)
if (${STRING_FOUND} EQUAL -1)
  message(NOTICE "")
  message(NOTICE "--------------------------------")
  message(NOTICE "--- Version number changed ! ---")
  message(NOTICE "--------------------------------")
  message(NOTICE "")
  
  file(WRITE src/xtd.core/src/xtd/environment_version.cpp
    "// This code was generated by CMake script.\n"
    "//\n"
    "// Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.\n"
    "\n"
    "#include \"../include/xtd/environment.h\"\n"
    "\n"
    "xtd::version xtd::environment::version() {\n"
    "  return xtd::version::parse(\"${XTD_VERSION}\");\n"
    "}\n"
  )

  file(WRITE install
    "#!/usr/bin/env bash\n"
    "# This code was generated by CMake script.\n"
    "#\n"
    "# Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.\n"
    "\n"
    "export xtd_version=${XTD_VERSION}\n"
    "scripts/install/install.sh \"$@\"\n"
  )
  
  file(WRITE install.cmd
    "@echo off\n"
    ":: This code was generated by CMake script.\n"
    "::\n"
    ":: Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.\n"
    "\n"
    "set xtd_version=${XTD_VERSION}\n"
    "call scripts\\install\\install.cmd %*\n"
  )
endif()
