| 1 |
# Test add_compiler_export_flags without deprecation warning. |
| 2 |
set(CMAKE_WARN_DEPRECATED OFF) |
| 3 |
|
| 4 |
project(GenerateExportHeader) |
| 5 |
|
| 6 |
include(CheckCXXCompilerFlag) |
| 7 |
|
| 8 |
set( CMAKE_INCLUDE_CURRENT_DIR ON ) |
| 9 |
|
| 10 |
macro(TEST_FAIL value msg) |
| 11 |
if (${value}) |
| 12 |
message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} ) |
| 13 |
endif () |
| 14 |
endmacro() |
| 15 |
|
| 16 |
macro(TEST_PASS value msg) |
| 17 |
if (NOT ${value}) |
| 18 |
message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} ) |
| 19 |
endif () |
| 20 |
endmacro() |
| 21 |
|
| 22 |
check_cxx_compiler_flag(-Werror HAS_WERROR_FLAG) |
| 23 |
|
| 24 |
if(HAS_WERROR_FLAG) |
| 25 |
set(ERROR_FLAG "-Werror") |
| 26 |
else() |
| 27 |
# MSVC |
| 28 |
# And intel on windows? |
| 29 |
# http://software.intel.com/en-us/articles/how-to-handle-warnings-message-in-compiler/?wapkw=%28compiler+warning+message%29 |
| 30 |
check_cxx_compiler_flag("/WX" HAS_WX_FLAG) |
| 31 |
if(HAS_WX_FLAG) |
| 32 |
set(ERROR_FLAG "/WX") |
| 33 |
else() |
| 34 |
# Sun CC |
| 35 |
# http://www.acsu.buffalo.edu/~charngda/sunstudio.html |
| 36 |
check_cxx_compiler_flag("-errwarn=%all" HAS_ERRWARN_ALL) |
| 37 |
if (HAS_ERRWARN_ALL) |
| 38 |
set(ERROR_FLAG "-errwarn=%all") |
| 39 |
else() |
| 40 |
endif() |
| 41 |
endif() |
| 42 |
endif() |
| 43 |
|
| 44 |
include(GenerateExportHeader) |
| 45 |
|
| 46 |
add_subdirectory(lib_shared_and_static) |
| 47 |
|
| 48 |
if(CMAKE_SYSTEM_NAME MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" |
| 49 |
AND CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY) |
| 50 |
# With GNU 7 on AIX, passing -fvisibility=hidden when driving the |
| 51 |
# linker for a shared library drops the so init/destruct symbols. |
| 52 |
# Just use the modern approach instead of testing the macro. |
| 53 |
set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
| 54 |
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) |
| 55 |
else() |
| 56 |
add_compiler_export_flags() |
| 57 |
endif() |
| 58 |
|
| 59 |
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 60 |
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}) |
| 61 |
|
| 62 |
message(STATUS "COMPILER_HAS_DEPRECATED: " ${COMPILER_HAS_DEPRECATED}) |
| 63 |
message(STATUS "COMPILER_HAS_HIDDEN_VISIBILITY: " ${COMPILER_HAS_HIDDEN_VISIBILITY}) |
| 64 |
message(STATUS "WIN32: " ${WIN32}) |
| 65 |
message(STATUS "HAS_WERROR_FLAG: " ${HAS_WERROR_FLAG}) |
| 66 |
|
| 67 |
set(link_libraries) |
| 68 |
macro(macro_add_test_library name) |
| 69 |
add_subdirectory(${name}) |
| 70 |
include_directories(${name} |
| 71 |
${CMAKE_CURRENT_BINARY_DIR}/${name} # For the export header. |
| 72 |
) |
| 73 |
list(APPEND link_libraries ${name}) |
| 74 |
endmacro() |
| 75 |
|
| 76 |
macro_add_test_library(libshared) |
| 77 |
macro_add_test_library(libstatic) |
| 78 |
|
| 79 |
add_subdirectory(nodeprecated) |
| 80 |
add_subdirectory(includeguard) |
| 81 |
if(NOT BORLAND) |
| 82 |
add_subdirectory(c_identifier) |
| 83 |
endif() |
| 84 |
|
| 85 |
if (CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|LCC)$" OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)) |
| 86 |
# No need to clutter the test output with warnings. |
| 87 |
string(APPEND CMAKE_CXX_FLAGS " -Wno-deprecated-declarations") |
| 88 |
endif() |
| 89 |
|
| 90 |
if(MSVC AND COMPILER_HAS_DEPRECATED) |
| 91 |
add_definitions(/wd4996) |
| 92 |
endif() |
| 93 |
|
| 94 |
add_executable(GenerateExportHeader exportheader_test.cpp) |
| 95 |
|
| 96 |
target_link_libraries(GenerateExportHeader ${link_libraries}) |
| 97 |
if (WIN32 OR CYGWIN) |
| 98 |
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") AND |
| 99 |
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") |
| 100 |
set(_platform Win32-Clang) |
| 101 |
elseif((MSVC OR CMAKE_C_COMPILER_ID STREQUAL "OrangeC") AND COMPILER_HAS_DEPRECATED) |
| 102 |
set(_platform Win32) |
| 103 |
elseif(CYGWIN AND COMPILER_HAS_DEPRECATED) |
| 104 |
set(_platform Cygwin) |
| 105 |
elseif(MINGW AND COMPILER_HAS_DEPRECATED) |
| 106 |
set(_platform MinGW) |
| 107 |
else() |
| 108 |
set(_platform WinEmpty) |
| 109 |
endif() |
| 110 |
elseif(COMPILER_HAS_HIDDEN_VISIBILITY) |
| 111 |
set(_platform UNIX) |
| 112 |
elseif(COMPILER_HAS_DEPRECATED) |
| 113 |
set(_platform UNIX_DeprecatedOnly) |
| 114 |
else() |
| 115 |
set(_platform Empty) |
| 116 |
endif() |
| 117 |
message(STATUS "Testing reference: ${_platform}") |
| 118 |
target_compile_definitions(GenerateExportHeader |
| 119 |
PRIVATE |
| 120 |
"SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/reference/${_platform}\"" |
| 121 |
"BIN_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"" |
| 122 |
) |
| 123 |
|
| 124 |
include(${CMAKE_CURRENT_LIST_DIR}/GEH-failures.cmake) |