1 cmake_minimum_required(VERSION 2.8)
2 project(CheckCompilerRelatedVariables)
7 message("${var}='${${var}}' is defined")
9 message("${var}='${${var}}' is NOT defined")
15 # Check that the correct number of MSVC** variables are defined...
20 math(EXPR msvc_total "${msvc_total} + 1")
23 math(EXPR msvc_total "${msvc_total} + 1")
26 math(EXPR msvc_total "${msvc_total} + 1")
29 math(EXPR msvc_total "${msvc_total} + 1")
32 math(EXPR msvc_total "${msvc_total} + 1")
35 math(EXPR msvc_total "${msvc_total} + 1")
38 math(EXPR msvc_total "${msvc_total} + 1")
41 math(EXPR msvc_total "${msvc_total} + 1")
57 # MSVC is set in cl.cmake when cl is the compiler...
59 # Exactly one of the numbered variables should also be set
60 # indicating which version of the cl compiler / Visual Studio
63 if(msvc_total EQUAL 1)
64 message("test passes: exactly one MSVC** variable is defined...")
66 message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 1 expected")
68 if(NOT DEFINED MSVC_IDE)
69 message(FATAL_ERROR "MSVC_IDE not defined but should be!")
70 elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND NOT MSVC_IDE)
71 message(FATAL_ERROR "MSVC_IDE is not true but should be (${CMAKE_GENERATOR})!")
72 elseif(NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND MSVC_IDE)
73 message(FATAL_ERROR "MSVC_IDE is true but should not be (${CMAKE_GENERATOR})!")
77 # The compiler is something other than cl... None of the MSVC** variables
78 # should be defined...
80 if(msvc_total EQUAL 0)
81 message("test passes: no MSVC** variables are defined on non-MSVC build...")
83 message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 0 expected")
86 message(FATAL_ERROR "MSVC_IDE is defined but should not be!")
92 # This is a no-op executable... If this test is going to fail, it fails during
93 # the configure step while cmake is configuring this CMakeLists.txt file...
97 "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
98 "int main() { return 0; }
103 CheckCompilerRelatedVariables
104 "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"