LySet.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. get_directory_property(LY_PARENT_SCOPE PARENT_DIRECTORY)
  9. if(LY_PARENT_SCOPE)
  10. set(LY_PARENT_SCOPE ${LY_PARENT_SCOPE} PARENT_SCOPE)
  11. endif()
  12. #! ly_set: convenient function to set and export variable to the parent scope in scenarios
  13. # where CMAKE_SOURCE_DIR != CMAKE_CURRENT_LIST_DIR (e.g. when the engine's cmake
  14. # files are included from a project)
  15. #
  16. macro(ly_set name)
  17. set(${name} "${ARGN}")
  18. if(LY_PARENT_SCOPE)
  19. set(${name} "${ARGN}" PARENT_SCOPE)
  20. endif()
  21. endmacro()
  22. #! o3de_set_from_env_with_default: convenient function to set a variable
  23. # from an environment variable or a default if the environment var is empty
  24. # and then run CONFIGURE on the result to replace all @sign variable references
  25. #
  26. # Example usage:
  27. # set(default "example")
  28. # o3de_set_from_env_with_default(var ENVVAR "@default@" CACHE STRING "Example string")
  29. # message(INFO "Result is ${var}")
  30. # Prints "Result is example" if no environment var named "ENVVAR" is set or is empty
  31. #
  32. # \arg:name - name of output variable to set
  33. # \arg:env_name - name of environment variable to use
  34. # \argn - remaining args are passed to the set() command and should at least contain the value
  35. macro(o3de_set_from_env_with_default name env_name)
  36. set(${name} ${ARGN})
  37. if(NOT "$ENV{${env_name}}" STREQUAL "")
  38. set(${name} "$ENV{${env_name}}")
  39. endif()
  40. string(CONFIGURE ${${name}} ${name} @ONLY)
  41. endmacro()