File: CMakeLists.txt

package info (click to toggle)
cmake 2.8.11.1-1~bpo70+1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 37,056 kB
  • sloc: cpp: 157,219; ansic: 137,155; yacc: 3,254; sh: 2,745; xml: 2,483; lex: 1,028; lisp: 215; python: 199; objc: 134; f90: 105; perl: 99; fortran: 93; makefile: 65; tcl: 55; asm: 28; php: 25; ruby: 22; java: 20
file content (101 lines) | stat: -rw-r--r-- 2,624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
cmake_minimum_required(VERSION 2.8)
project(CheckCompilerRelatedVariables)


function(echo_var var)
  if(DEFINED ${var})
    message("${var}='${${var}}' is defined")
  else()
    message("${var}='${${var}}' is NOT defined")
  endif()
endfunction()


#
# Check that the correct number of MSVC** variables are defined...
#
set(msvc_total 0)

if(DEFINED MSVC60)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()
if(DEFINED MSVC70)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()
if(DEFINED MSVC71)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()
if(DEFINED MSVC80)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()
if(DEFINED MSVC90)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()
if(DEFINED MSVC10)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()
if(DEFINED MSVC11)
  math(EXPR msvc_total "${msvc_total} + 1")
endif()

echo_var(MSVC)
echo_var(MSVC60)
echo_var(MSVC70)
echo_var(MSVC71)
echo_var(MSVC80)
echo_var(MSVC90)
echo_var(MSVC10)
echo_var(MSVC11)
echo_var(MSVC_IDE)

if(MSVC)
  #
  # MSVC is set in cl.cmake when cl is the compiler...
  #
  # Exactly one of the numbered variables should also be set
  # indicating which version of the cl compiler / Visual Studio
  # is in use...
  #
  if(msvc_total EQUAL 1)
    message("test passes: exactly one MSVC** variable is defined...")
  else()
    message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 1 expected")
  endif()
  if(NOT DEFINED MSVC_IDE)
    message(FATAL_ERROR "MSVC_IDE not defined but should be!")
  elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND NOT MSVC_IDE)
    message(FATAL_ERROR "MSVC_IDE is not true but should be (${CMAKE_GENERATOR})!")
  elseif(NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio" AND MSVC_IDE)
    message(FATAL_ERROR "MSVC_IDE is true but should not be (${CMAKE_GENERATOR})!")
  endif()
else()
  #
  # The compiler is something other than cl... None of the MSVC** variables
  # should be defined...
  #
  if(msvc_total EQUAL 0)
    message("test passes: no MSVC** variables are defined on non-MSVC build...")
  else()
    message(FATAL_ERROR "error: ${msvc_total} MSVC** variables are defined -- exactly 0 expected")
  endif()
  if(DEFINED MSVC_IDE)
    message(FATAL_ERROR "MSVC_IDE is defined but should not be!")
  endif()
endif()


#
# This is a no-op executable... If this test is going to fail, it fails during
# the configure step while cmake is configuring this CMakeLists.txt file...
#

file(WRITE
  "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  "int main() { return 0; }
"
  )

add_executable(
  CheckCompilerRelatedVariables
  "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  )