CMakeLists.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. if(DEFINED MSVC11)
  33. math(EXPR msvc_total "${msvc_total} + 1")
  34. endif()
  35. echo_var(MSVC)
  36. echo_var(MSVC60)
  37. echo_var(MSVC70)
  38. echo_var(MSVC71)
  39. echo_var(MSVC80)
  40. echo_var(MSVC90)
  41. echo_var(MSVC10)
  42. echo_var(MSVC11)
  43. if(MSVC)
  44. #
  45. # MSVC is set in cl.cmake when cl is the compiler...
  46. #
  47. # Exactly one of the numbered variables should also be set
  48. # indicating which version of the cl compiler / Visual Studio
  49. # is in use...
  50. #
  51. if(msvc_total EQUAL 1)
  52. message("test passes: exactly one MSVC** variable is defined...")
  53. else()
  54. message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 1 expected")
  55. endif()
  56. else()
  57. #
  58. # The compiler is something other than cl... None of the MSVC** variables
  59. # should be defined...
  60. #
  61. if(msvc_total EQUAL 0)
  62. message("test passes: no MSVC** variables are defined on non-MSVC build...")
  63. else()
  64. message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 0 expected")
  65. endif()
  66. endif()
  67. #
  68. # This is a no-op executable... If this test is going to fail, it fails during
  69. # the configure step while cmake is configuring this CMakeLists.txt file...
  70. #
  71. file(WRITE
  72. "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  73. "int main() { return 0; }
  74. "
  75. )
  76. add_executable(
  77. CheckCompilerRelatedVariables
  78. "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  79. )