Imported Upstream version 2.8.11.2
[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 if(DEFINED MSVC12)
41   math(EXPR msvc_total "${msvc_total} + 1")
42 endif()
43
44 echo_var(MSVC)
45 echo_var(MSVC60)
46 echo_var(MSVC70)
47 echo_var(MSVC71)
48 echo_var(MSVC80)
49 echo_var(MSVC90)
50 echo_var(MSVC10)
51 echo_var(MSVC11)
52 echo_var(MSVC12)
53 echo_var(MSVC_IDE)
54
55 if(MSVC)
56   #
57   # MSVC is set in cl.cmake when cl is the compiler...
58   #
59   # Exactly one of the numbered variables should also be set
60   # indicating which version of the cl compiler / Visual Studio
61   # is in use...
62   #
63   if(msvc_total EQUAL 1)
64     message("test passes: exactly one MSVC** variable is defined...")
65   else()
66     message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 1 expected")
67   endif()
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})!")
74   endif()
75 else()
76   #
77   # The compiler is something other than cl... None of the MSVC** variables
78   # should be defined...
79   #
80   if(msvc_total EQUAL 0)
81     message("test passes: no MSVC** variables are defined on non-MSVC build...")
82   else()
83     message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 0 expected")
84   endif()
85   if(DEFINED MSVC_IDE)
86     message(FATAL_ERROR "MSVC_IDE is defined but should not be!")
87   endif()
88 endif()
89
90
91 #
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...
94 #
95
96 file(WRITE
97   "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
98   "int main() { return 0; }
99 "
100   )
101
102 add_executable(
103   CheckCompilerRelatedVariables
104   "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
105   )