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