summaryrefslogtreecommitdiffstats
path: root/Tests/Module/GenerateExportHeader/CMakeLists.txt
blob: 56f0f28aff18ab87d75e3856416bc84df7529ebf (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
cmake_policy(SET CMP0054 NEW)

project(GenerateExportHeader)

# Prevent timeout on Watcom by not running the tests.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES Watcom)
  file(WRITE
    "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
    "int main() { return 0; }
  "
  )

  add_executable(
    GenerateExportHeader
    "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  )
  return()
endif()

include(CheckCXXCompilerFlag)

set( CMAKE_INCLUDE_CURRENT_DIR ON )

macro(TEST_FAIL value msg)
  if (${value})
    message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
  endif ()
endmacro()

macro(TEST_PASS value msg)
  if (NOT ${value})
    message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
  endif ()
endmacro()

check_cxx_compiler_flag(-Werror HAS_WERROR_FLAG)

if(HAS_WERROR_FLAG)
  set(ERROR_FLAG "-Werror")
else()
  # MSVC
  # And intel on windows?
  # http://software.intel.com/en-us/articles/how-to-handle-warnings-message-in-compiler/?wapkw=%28compiler+warning+message%29
  check_cxx_compiler_flag("/WX" HAS_WX_FLAG)
  if(HAS_WX_FLAG)
    set(ERROR_FLAG "/WX")
  else()
    # Sun CC
    # http://www.acsu.buffalo.edu/~charngda/sunstudio.html
    check_cxx_compiler_flag("-errwarn=%all" HAS_ERRWARN_ALL)
    if (HAS_ERRWARN_ALL)
      set(ERROR_FLAG "-errwarn=%all")
    else()
    endif()
  endif()
endif()

include(GenerateExportHeader)

set(CMAKE_CXX_STANDARD 98)

# Those versions of the HP compiler that need a flag to get proper C++98
# template support also need a flag to use the newer C++ library.
if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
    CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
  string(APPEND CMAKE_CXX_FLAGS " -AA")
endif ()

# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
    CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
  set(CMAKE_CXX_STANDARD 11)
endif()

add_subdirectory(lib_shared_and_static)

add_compiler_export_flags()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

message("#### COMPILER_HAS_DEPRECATED: " ${COMPILER_HAS_DEPRECATED})
message("#### COMPILER_HAS_HIDDEN_VISIBILITY: " ${COMPILER_HAS_HIDDEN_VISIBILITY})
message("#### WIN32: " ${WIN32})
message("#### HAS_WERROR_FLAG: " ${HAS_WERROR_FLAG})

set(link_libraries)
macro(macro_add_test_library name)
  add_subdirectory(${name})
  include_directories(${name}
            ${${name}_BINARY_DIR} # For the export header.
  )
  list(APPEND link_libraries ${name})
endmacro()

macro_add_test_library(libshared)
macro_add_test_library(libstatic)

add_subdirectory(nodeprecated)
if(NOT BORLAND)
  add_subdirectory(c_identifier)
endif()

if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
  # No need to clutter the test output with warnings.
  string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated-declarations")
endif()

if(MSVC AND COMPILER_HAS_DEPRECATED)
  add_definitions(/wd4996)
endif()

add_executable(GenerateExportHeader exportheader_test.cpp)

target_link_libraries(GenerateExportHeader ${link_libraries})
if (WIN32 OR CYGWIN)
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
    CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
    set(_platform Win32-Clang)
  elseif(MSVC AND COMPILER_HAS_DEPRECATED)
    set(_platform Win32)
  elseif((MINGW OR CYGWIN) AND COMPILER_HAS_DEPRECATED)
    set(_platform MinGW)
  else()
    set(_platform WinEmpty)
  endif()
elseif(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
  set(_platform UNIX)
elseif(COMPILER_HAS_DEPRECATED)
  set(_platform UNIX_DeprecatedOnly)
else()
  set(_platform Empty)
endif()
message("#### Testing reference: ${_platform}")
target_compile_definitions(GenerateExportHeader
  PRIVATE
    "SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/reference/${_platform}\""
    "BIN_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\""
)