CheckFlagCommonConfig.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # Do NOT include this module directly into any of your code. It is meant as
  4. # a library for Check*CompilerFlag.cmake and Check*LinkerFlag.cma modules.
  5. # It's content may change in any way between releases.
  6. include_guard(GLOBAL)
  7. cmake_policy(PUSH)
  8. cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
  9. cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST
  10. macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS)
  11. if("${_LANG}" STREQUAL "C")
  12. set(${_SRC} "int main(void) { return 0; }")
  13. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C"
  14. FAIL_REGEX "-Werror=.* argument .* is not valid for C")
  15. elseif("${_LANG}" STREQUAL "CXX")
  16. set(${_SRC} "int main() { return 0; }")
  17. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+"
  18. FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+")
  19. elseif("${_LANG}" STREQUAL "CUDA")
  20. set(${_SRC} "__host__ int main() { return 0; }")
  21. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU
  22. FAIL_REGEX "argument unused during compilation: .*") # Clang
  23. elseif("${_LANG}" STREQUAL "Fortran")
  24. set(${_SRC} " program test\n stop\n end program")
  25. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran")
  26. elseif("${_LANG}" STREQUAL "HIP")
  27. set(${_SRC} "__host__ int main() { return 0; }")
  28. set(${_PATTERNS} FAIL_REGEX "argument unused during compilation: .*") # Clang
  29. elseif("${_LANG}" STREQUAL "OBJC")
  30. set(${_SRC} [=[
  31. #ifndef __OBJC__
  32. # error "Not an Objective-C compiler"
  33. #endif
  34. int main(void) { return 0; }]=])
  35. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU
  36. FAIL_REGEX "argument unused during compilation: .*") # Clang
  37. elseif("${_LANG}" STREQUAL "OBJCXX")
  38. set(${_SRC} [=[
  39. #ifndef __OBJC__
  40. # error "Not an Objective-C++ compiler"
  41. #endif
  42. int main(void) { return 0; }]=])
  43. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU
  44. FAIL_REGEX "argument unused during compilation: .*") # Clang
  45. elseif("${_LANG}" STREQUAL "ISPC")
  46. set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }")
  47. else()
  48. message (SEND_ERROR "${_FUNC}: ${_LANG}: unknown language.")
  49. return()
  50. endif()
  51. get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
  52. if (NOT "${_LANG}" IN_LIST _supported_languages)
  53. message (SEND_ERROR "${_FUNC}: ${_LANG}: needs to be enabled before use.")
  54. return()
  55. endif()
  56. # Normalize locale during test compilation.
  57. set(_locale_vars LC_ALL LC_MESSAGES LANG)
  58. foreach(v IN LISTS _locale_vars)
  59. set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v} "$ENV{${v}}")
  60. set(ENV{${v}} C)
  61. endforeach()
  62. endmacro()
  63. macro(CMAKE_CHECK_FLAG_COMMON_FINISH)
  64. foreach(v IN LISTS _CFCC_locale_vars)
  65. set(ENV{${v}} ${_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v}})
  66. endforeach()
  67. endmacro()
  68. cmake_policy(POP)