CalculateEnginePathId.cmake 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. # This script will generate a unique ID of the current engine path by using the first 9 characters of the SHA1 hash of the absolute engine path
  9. # and write the results to STDOUT
  10. if(${CMAKE_ARGC} LESS 3)
  11. message(FATAL_ERROR "Missing required engine path argument to calculate id from.")
  12. endif()
  13. # Get and normalize the path passed into this script as the main argument
  14. set(PATH_TO_HASH ${CMAKE_ARGV3})
  15. cmake_path(NORMAL_PATH PATH_TO_HASH)
  16. # Sanity check to make sure this is the path to the engine
  17. set(ENGINE_SANITY_CHECK_FILE "${PATH_TO_HASH}/engine.json")
  18. if (NOT EXISTS "${ENGINE_SANITY_CHECK_FILE}")
  19. message(FATAL_ERROR "Path ${PATH_TO_HASH} is not a valid engine path.")
  20. endif()
  21. string(TOLOWER ${PATH_TO_HASH} PATH_TO_HASH)
  22. # Calculate the path id based on the first 8 characters of the SHA1 hash of the normalized path
  23. string(SHA1 ENGINE_SOURCE_PATH_HASH "${PATH_TO_HASH}")
  24. string(SUBSTRING ${ENGINE_SOURCE_PATH_HASH} 0 8 ENGINE_SOURCE_PATH_ID)
  25. # Note: using 'message(STATUS ..' will print to STDOUT, but will always include a double hyphen '--'. Instead we will
  26. # use the cmake echo command directly to do this
  27. execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${ENGINE_SOURCE_PATH_ID})