CheckHost.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) 2008-2023 the Urho3D project
  2. # License: MIT
  3. # Check the capability of the host system
  4. #
  5. # NULL_DEVICE
  6. #
  7. # WIN32 only:
  8. # HAS_MKLINK (capable to create mklink which is analogous to symlink)
  9. #
  10. # non-WIN32:
  11. # HAS_LIB64 (multilib capable)
  12. # CCACHE_VERSION (when ccache is used)
  13. #
  14. # Neither here nor there:
  15. # BASH_ON_WINDOWS
  16. #
  17. if (CMAKE_HOST_WIN32)
  18. set (NULL_DEVICE nul)
  19. if (NOT DEFINED HAS_MKLINK)
  20. # Test whether the host system is capable of setting up symbolic link
  21. execute_process (COMMAND cmd /C mklink test-link CMakeCache.txt WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE MKLINK_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
  22. if (MKLINK_EXIT_CODE EQUAL 0)
  23. set (HAS_MKLINK TRUE)
  24. file (REMOVE ${CMAKE_BINARY_DIR}/test-link)
  25. else ()
  26. set (HAS_MKLINK FALSE)
  27. message (WARNING "Could not use MKLINK to setup symbolic links as this Windows user account does not have the privilege to do so. "
  28. "When MKLINK is not available then the build system will fallback to use file/directory copy of the library headers from source tree to build tree. "
  29. "In order to prevent stale headers being used in the build, this file/directory copy will be redone also as a post-build step for each library targets. "
  30. "This may slow down the build unnecessarily or even cause other unforseen issues due to incomplete or stale headers in the build tree. "
  31. "Request your Windows Administrator to grant your user account to have privilege to create symlink via MKLINK command. "
  32. "You are NOT advised to use the Administrator account directly to generate build tree in all cases.")
  33. endif ()
  34. set (HAS_MKLINK ${HAS_MKLINK} CACHE INTERNAL "MKLINK capability")
  35. endif ()
  36. else ()
  37. set (NULL_DEVICE /dev/null)
  38. if (NOT DEFINED HAS_LIB64)
  39. if (EXISTS /usr/lib64)
  40. set (HAS_LIB64 TRUE)
  41. else ()
  42. set (HAS_LIB64 FALSE)
  43. endif ()
  44. set (HAS_LIB64 ${HAS_LIB64} CACHE INTERNAL "Multilib capability")
  45. endif ()
  46. # Test if it is a userspace bash on Windows host system
  47. if (NOT DEFINED BASH_ON_WINDOWS)
  48. execute_process (COMMAND grep -cq Microsoft /proc/version RESULT_VARIABLE GREP_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
  49. if (GREP_EXIT_CODE EQUAL 0)
  50. set (BASH_ON_WINDOWS TRUE)
  51. endif ()
  52. set (BASH_ON_WINDOWS ${BASH_ON_WINDOWS} CACHE INTERNAL "Bash on Ubuntu on Windows")
  53. endif ()
  54. if ("$ENV{USE_CCACHE}" AND NOT DEFINED CCACHE_VERSION)
  55. execute_process (COMMAND ccache --version COMMAND head -1 RESULT_VARIABLE CCACHE_EXIT_CODE OUTPUT_VARIABLE CCACHE_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  56. string (REGEX MATCH "[^ .]+\\.[^.]+\\.[^ ]+" CCACHE_VERSION "${CCACHE_VERSION}") # Stringify as it could be empty when an error has occurred
  57. if (CCACHE_EXIT_CODE EQUAL 0)
  58. set (CCACHE_VERSION ${CCACHE_VERSION} CACHE INTERNAL "ccache version")
  59. endif ()
  60. endif ()
  61. endif ()