CheckFlagCommonConfig.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. elseif("${_LANG}" STREQUAL "Swift")
  48. set(${_SRC} "func blarpy() { }")
  49. else()
  50. message (SEND_ERROR "${_FUNC}: ${_LANG}: unknown language.")
  51. return()
  52. endif()
  53. get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
  54. if (NOT "${_LANG}" IN_LIST _supported_languages)
  55. message (SEND_ERROR "${_FUNC}: ${_LANG}: needs to be enabled before use.")
  56. return()
  57. endif()
  58. # Normalize locale during test compilation.
  59. set(_CFCC_locale_vars LC_ALL LC_MESSAGES LANG)
  60. foreach(v IN LISTS _CFCC_locale_vars)
  61. set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v} "$ENV{${v}}")
  62. set(ENV{${v}} C)
  63. endforeach()
  64. endmacro()
  65. macro(CMAKE_CHECK_FLAG_COMMON_FINISH)
  66. foreach(v IN LISTS _CFCC_locale_vars)
  67. set(ENV{${v}} ${_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v}})
  68. endforeach()
  69. endmacro()
  70. cmake_policy(POP)