CheckHost.cmake 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # Copyright (c) 2008-2020 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Check the capability of the host system
  23. #
  24. # NULL_DEVICE
  25. #
  26. # WIN32 only:
  27. # HAS_MKLINK (capable to create mklink which is analogous to symlink)
  28. #
  29. # non-WIN32:
  30. # HAS_LIB64 (multilib capable)
  31. # CCACHE_VERSION (when ccache is used)
  32. #
  33. # Neither here nor there:
  34. # BASH_ON_WINDOWS
  35. #
  36. if (CMAKE_HOST_WIN32)
  37. set (NULL_DEVICE nul)
  38. if (NOT DEFINED HAS_MKLINK)
  39. # Test whether the host system is capable of setting up symbolic link
  40. execute_process (COMMAND cmd /C mklink test-link CMakeCache.txt WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE MKLINK_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
  41. if (MKLINK_EXIT_CODE EQUAL 0)
  42. set (HAS_MKLINK TRUE)
  43. file (REMOVE ${CMAKE_BINARY_DIR}/test-link)
  44. else ()
  45. set (HAS_MKLINK FALSE)
  46. message (WARNING "Could not use MKLINK to setup symbolic links as this Windows user account does not have the privilege to do so. "
  47. "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. "
  48. "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. "
  49. "This may slow down the build unnecessarily or even cause other unforseen issues due to incomplete or stale headers in the build tree. "
  50. "Request your Windows Administrator to grant your user account to have privilege to create symlink via MKLINK command. "
  51. "You are NOT advised to use the Administrator account directly to generate build tree in all cases.")
  52. endif ()
  53. set (HAS_MKLINK ${HAS_MKLINK} CACHE INTERNAL "MKLINK capability")
  54. endif ()
  55. else ()
  56. set (NULL_DEVICE /dev/null)
  57. if (NOT DEFINED HAS_LIB64)
  58. if (EXISTS /usr/lib64)
  59. set (HAS_LIB64 TRUE)
  60. else ()
  61. set (HAS_LIB64 FALSE)
  62. endif ()
  63. set (HAS_LIB64 ${HAS_LIB64} CACHE INTERNAL "Multilib capability")
  64. endif ()
  65. # Test if it is a userspace bash on Windows host system
  66. if (NOT DEFINED BASH_ON_WINDOWS)
  67. execute_process (COMMAND grep -cq Microsoft /proc/version RESULT_VARIABLE GREP_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
  68. if (GREP_EXIT_CODE EQUAL 0)
  69. set (BASH_ON_WINDOWS TRUE)
  70. endif ()
  71. set (BASH_ON_WINDOWS ${BASH_ON_WINDOWS} CACHE INTERNAL "Bash on Ubuntu on Windows")
  72. endif ()
  73. if ("$ENV{USE_CCACHE}" AND NOT DEFINED CCACHE_VERSION)
  74. execute_process (COMMAND ccache --version COMMAND head -1 RESULT_VARIABLE CCACHE_EXIT_CODE OUTPUT_VARIABLE CCACHE_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  75. string (REGEX MATCH "[^ .]+\\.[^.]+\\.[^ ]+" CCACHE_VERSION "${CCACHE_VERSION}") # Stringify as it could be empty when an error has occurred
  76. if (CCACHE_EXIT_CODE EQUAL 0)
  77. set (CCACHE_VERSION ${CCACHE_VERSION} CACHE INTERNAL "ccache version")
  78. endif ()
  79. endif ()
  80. endif ()