CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
  2. project(GenerateExportHeader)
  3. # Prevent timeout on Watcom by not running the tests.
  4. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES Watcom)
  5. file(WRITE
  6. "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  7. "int main() { return 0; }
  8. "
  9. )
  10. add_executable(
  11. GenerateExportHeader
  12. "${CMAKE_CURRENT_BINARY_DIR}/main.cxx"
  13. )
  14. return()
  15. endif()
  16. include(CheckCXXCompilerFlag)
  17. set( CMAKE_INCLUDE_CURRENT_DIR ON )
  18. macro(TEST_FAIL value msg)
  19. if (${value})
  20. message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
  21. endif ()
  22. endmacro()
  23. macro(TEST_PASS value msg)
  24. if (NOT ${value})
  25. message (SEND_ERROR "Test fail:" "${msg}\n" ${Out} )
  26. endif ()
  27. endmacro()
  28. check_cxx_compiler_flag(-Werror HAS_WERROR_FLAG)
  29. if(HAS_WERROR_FLAG)
  30. set(ERROR_FLAG "-Werror")
  31. else()
  32. # MSVC
  33. # And intel on windows?
  34. # http://software.intel.com/en-us/articles/how-to-handle-warnings-message-in-compiler/?wapkw=%28compiler+warning+message%29
  35. check_cxx_compiler_flag("/WX" HAS_WX_FLAG)
  36. if(HAS_WX_FLAG)
  37. set(ERROR_FLAG "/WX")
  38. else()
  39. # Sun CC
  40. # http://www.acsu.buffalo.edu/~charngda/sunstudio.html
  41. check_cxx_compiler_flag("-errwarn=%all" HAS_ERRWARN_ALL)
  42. if (HAS_ERRWARN_ALL)
  43. set(ERROR_FLAG "-errwarn=%all")
  44. else()
  45. endif()
  46. endif()
  47. endif()
  48. include(GenerateExportHeader)
  49. add_subdirectory(lib_shared_and_static)
  50. add_compiler_export_flags()
  51. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  52. message("#### COMPILER_HAS_DEPRECATED: " ${COMPILER_HAS_DEPRECATED})
  53. message("#### COMPILER_HAS_HIDDEN_VISIBILITY: " ${COMPILER_HAS_HIDDEN_VISIBILITY})
  54. message("#### WIN32: " ${WIN32})
  55. message("#### HAS_WERROR_FLAG: " ${HAS_WERROR_FLAG})
  56. set(link_libraries)
  57. macro(macro_add_test_library name)
  58. add_subdirectory(${name})
  59. include_directories(${name}
  60. ${${name}_BINARY_DIR} # For the export header.
  61. )
  62. list(APPEND link_libraries ${name})
  63. endmacro()
  64. macro_add_test_library(libshared)
  65. macro_add_test_library(libstatic)
  66. add_subdirectory(nodeprecated)
  67. if(NOT BORLAND)
  68. add_subdirectory(c_identifier)
  69. endif()
  70. if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
  71. # No need to clutter the test output with warnings.
  72. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
  73. endif()
  74. if(MSVC AND COMPILER_HAS_DEPRECATED)
  75. add_definitions(/wd4996)
  76. endif()
  77. add_executable(GenerateExportHeader exportheader_test.cpp)
  78. target_link_libraries(GenerateExportHeader ${link_libraries})
  79. if (WIN32)
  80. if(MSVC AND COMPILER_HAS_DEPRECATED)
  81. set(_platform Win32)
  82. elseif(MINGW AND COMPILER_HAS_DEPRECATED)
  83. set(_platform MinGW)
  84. else()
  85. set(_platform WinEmpty)
  86. endif()
  87. elseif(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
  88. set(_platform UNIX)
  89. elseif(COMPILER_HAS_DEPRECATED)
  90. set(_platform UNIX_DeprecatedOnly)
  91. else()
  92. set(_platform Empty)
  93. endif()
  94. message("#### Testing reference: ${_platform}")
  95. target_compile_definitions(GenerateExportHeader
  96. PRIVATE
  97. "SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}/reference/${_platform}"
  98. "BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}"
  99. )