CheckFlagCommonConfig.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. elseif("${_LANG}" STREQUAL "Fortran")
  23. set(${_SRC} " program test\n stop\n end program")
  24. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran")
  25. elseif("${_LANG}" STREQUAL "HIP")
  26. set(${_SRC} "__host__ int main() { return 0; }")
  27. elseif("${_LANG}" STREQUAL "OBJC")
  28. set(${_SRC} [=[
  29. #ifndef __OBJC__
  30. # error "Not an Objective-C compiler"
  31. #endif
  32. int main(void) { return 0; }]=])
  33. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C") # GNU
  34. elseif("${_LANG}" STREQUAL "OBJCXX")
  35. set(${_SRC} [=[
  36. #ifndef __OBJC__
  37. # error "Not an Objective-C++ compiler"
  38. #endif
  39. int main(void) { return 0; }]=])
  40. set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+") # GNU
  41. elseif("${_LANG}" STREQUAL "ISPC")
  42. set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }")
  43. elseif("${_LANG}" STREQUAL "Swift")
  44. set(${_SRC} "func blarpy() { }")
  45. else()
  46. message (SEND_ERROR "${_FUNC}: ${_LANG}: unknown language.")
  47. return()
  48. endif()
  49. get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
  50. if (NOT "${_LANG}" IN_LIST _supported_languages)
  51. message (SEND_ERROR "${_FUNC}: ${_LANG}: needs to be enabled before use.")
  52. return()
  53. endif()
  54. # Normalize locale during test compilation.
  55. set(_CFCC_locale_vars LC_ALL LC_MESSAGES LANG)
  56. foreach(v IN LISTS _CFCC_locale_vars)
  57. set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v} "$ENV{${v}}")
  58. set(ENV{${v}} C)
  59. endforeach()
  60. endmacro()
  61. macro(CMAKE_CHECK_FLAG_COMMON_FINISH)
  62. foreach(v IN LISTS _CFCC_locale_vars)
  63. set(ENV{${v}} ${_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v}})
  64. endforeach()
  65. endmacro()
  66. cmake_policy(POP)