CMakeLists.txt 3.72 KB
Newer Older
1
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
2
cmake_policy(SET CMP0054 NEW)
3 4 5

project(GenerateExportHeader)

6
# Prevent timeout on Watcom by not running the tests.
7
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES Watcom)
8 9 10 11 12 13 14 15 16 17 18 19 20
  file(WRITE
    "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
    "int main() { return 0; }
  "
  )

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

21 22
include(CheckCXXCompilerFlag)

23 24 25 26
set( CMAKE_INCLUDE_CURRENT_DIR ON )

macro(TEST_FAIL value msg)
  if (${value})
27
    message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
28 29 30 31 32
  endif ()
endmacro()

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

37 38
check_cxx_compiler_flag(-Werror HAS_WERROR_FLAG)

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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()

59 60
include(GenerateExportHeader)

61 62 63 64 65 66
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")
67
  string(APPEND CMAKE_CXX_FLAGS " -AA")
68 69
endif ()

70 71 72 73 74 75
# 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()

76
add_subdirectory(lib_shared_and_static)
77

78 79
add_compiler_export_flags()

80 81
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

82 83 84
message("#### COMPILER_HAS_DEPRECATED: " ${COMPILER_HAS_DEPRECATED})
message("#### COMPILER_HAS_HIDDEN_VISIBILITY: " ${COMPILER_HAS_HIDDEN_VISIBILITY})
message("#### WIN32: " ${WIN32})
85
message("#### HAS_WERROR_FLAG: " ${HAS_WERROR_FLAG})
86

87 88 89 90 91 92 93 94 95 96 97 98
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)

99
add_subdirectory(nodeprecated)
100 101 102
if(NOT BORLAND)
  add_subdirectory(c_identifier)
endif()
103

Stephen Kelly's avatar
Stephen Kelly committed
104
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
105
  # No need to clutter the test output with warnings.
106
  string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated-declarations")
107 108
endif()

109
if(MSVC AND COMPILER_HAS_DEPRECATED)
110 111 112 113 114 115
  add_definitions(/wd4996)
endif()

add_executable(GenerateExportHeader exportheader_test.cpp)

target_link_libraries(GenerateExportHeader ${link_libraries})
116
if (WIN32 OR CYGWIN)
117 118 119 120
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
    CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
    set(_platform Win32-Clang)
  elseif(MSVC AND COMPILER_HAS_DEPRECATED)
121
    set(_platform Win32)
122
  elseif((MINGW OR CYGWIN) AND COMPILER_HAS_DEPRECATED)
123 124 125 126 127 128 129 130 131 132 133 134 135 136
    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
137 138
    "SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/reference/${_platform}\""
    "BIN_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\""
139
)