CheckFlagCommonConfig.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst 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. macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS)
  8. if("${_LANG}" STREQUAL "C")
  9. set(${_SRC} "int main(void) { return 0; }")
  10. set(${_PATTERNS}
  11. FAIL_REGEX "command[ -]line option .* is valid for .* but not for C"
  12. FAIL_REGEX "-Werror=.* argument .* is not valid for C"
  13. )
  14. elseif("${_LANG}" STREQUAL "CXX")
  15. set(${_SRC} "int main() { return 0; }")
  16. set(${_PATTERNS}
  17. FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+"
  18. FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+"
  19. )
  20. elseif("${_LANG}" STREQUAL "CUDA")
  21. set(${_SRC} "__host__ int main() { return 0; }")
  22. set(${_PATTERNS}
  23. FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU
  24. FAIL_REGEX "argument unused during compilation: .*" # Clang
  25. )
  26. elseif("${_LANG}" STREQUAL "Fortran")
  27. set(${_SRC} " program test\n stop\n end program")
  28. set(${_PATTERNS}
  29. FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran"
  30. FAIL_REGEX "argument unused during compilation: .*" # LLVMFlang
  31. )
  32. elseif("${_LANG}" STREQUAL "HIP")
  33. set(${_SRC} "__host__ int main() { return 0; }")
  34. set(${_PATTERNS}
  35. FAIL_REGEX "argument unused during compilation: .*" # Clang
  36. )
  37. elseif("${_LANG}" STREQUAL "OBJC")
  38. set(${_SRC} [=[
  39. #ifndef __OBJC__
  40. # error "Not an Objective-C compiler"
  41. #endif
  42. int main(void) { return 0; }]=])
  43. set(${_PATTERNS}
  44. FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU
  45. FAIL_REGEX "argument unused during compilation: .*" # Clang
  46. )
  47. elseif("${_LANG}" STREQUAL "OBJCXX")
  48. set(${_SRC} [=[
  49. #ifndef __OBJC__
  50. # error "Not an Objective-C++ compiler"
  51. #endif
  52. int main(void) { return 0; }]=])
  53. set(${_PATTERNS}
  54. FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU
  55. FAIL_REGEX "argument unused during compilation: .*" # Clang
  56. )
  57. elseif("${_LANG}" STREQUAL "ISPC")
  58. set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }")
  59. elseif("${_LANG}" STREQUAL "Swift")
  60. set(${_SRC} "func blarpy() { }")
  61. else()
  62. message (SEND_ERROR "${_FUNC}: ${_LANG}: unknown language.")
  63. return()
  64. endif()
  65. get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
  66. if (NOT "${_LANG}" IN_LIST _supported_languages)
  67. message (SEND_ERROR "${_FUNC}: ${_LANG}: needs to be enabled before use.")
  68. return()
  69. endif()
  70. # Normalize locale during test compilation.
  71. set(_CFCC_locale_vars LC_ALL LC_MESSAGES LANG)
  72. foreach(v IN LISTS _CFCC_locale_vars)
  73. set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v} "$ENV{${v}}")
  74. set(ENV{${v}} C)
  75. endforeach()
  76. endmacro()
  77. macro(CMAKE_CHECK_FLAG_COMMON_FINISH)
  78. foreach(v IN LISTS _CFCC_locale_vars)
  79. set(ENV{${v}} ${_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v}})
  80. endforeach()
  81. endmacro()