CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. cmake_minimum_required(VERSION 2.8)
  2. project(CheckCompilerRelatedVariables)
  3. function(echo_var var)
  4. if(DEFINED ${var})
  5. message("${var}='${${var}}' is defined")
  6. else()
  7. message("${var}='${${var}}' is NOT defined")
  8. endif()
  9. endfunction()
  10. #
  11. # Check that the correct number of MSVC** variables are defined...
  12. #
  13. set(msvc_total 0)
  14. if(DEFINED MSVC60)
  15. math(EXPR msvc_total "${msvc_total} + 1")
  16. endif()
  17. if(DEFINED MSVC70)
  18. math(EXPR msvc_total "${msvc_total} + 1")
  19. endif()
  20. if(DEFINED MSVC71)
  21. math(EXPR msvc_total "${msvc_total} + 1")
  22. endif()
  23. if(DEFINED MSVC80)
  24. math(EXPR msvc_total "${msvc_total} + 1")
  25. endif()
  26. if(DEFINED MSVC90)
  27. math(EXPR msvc_total "${msvc_total} + 1")
  28. endif()
  29. if(DEFINED MSVC10)
  30. math(EXPR msvc_total "${msvc_total} + 1")
  31. endif()
  32. echo_var(MSVC)
  33. echo_var(MSVC60)
  34. echo_var(MSVC70)
  35. echo_var(MSVC71)
  36. echo_var(MSVC80)
  37. echo_var(MSVC90)
  38. echo_var(MSVC10)
  39. if(MSVC)
  40. #
  41. # MSVC is set in cl.cmake when cl is the compiler...
  42. #
  43. # Exactly one of the numbered variables should also be set
  44. # indicating which version of the cl compiler / Visual Studio
  45. # is in use...
  46. #
  47. if(msvc_total EQUAL 1)
  48. message("test passes: exactly one MSVC** variable is defined...")
  49. else()
  50. message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 1 expected")
  51. endif()
  52. else()
  53. #
  54. # The compiler is something other than cl... None of the MSVC** variables
  55. # should be defined...
  56. #
  57. if(msvc_total EQUAL 0)
  58. message("test passes: no MSVC** variables are defined on non-MSVC build...")
  59. else()
  60. message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 0 expected")
  61. endif()
  62. endif()
  63. #
  64. # This is a no-op executable... If this test is going to fail, it fails during
  65. # the configure step while cmake is configuring this CMakeLists.txt file...
  66. #
  67. file(WRITE
  68. "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  69. "int main() { return 0; }
  70. "
  71. )
  72. add_executable(
  73. CheckCompilerRelatedVariables
  74. "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  75. )