CMakeLists.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. include(CheckCXXCompilerFlag)
  2. set(UNITTEST_SOURCES
  3. allocatorstest.cpp
  4. bigintegertest.cpp
  5. documenttest.cpp
  6. dtoatest.cpp
  7. encodedstreamtest.cpp
  8. encodingstest.cpp
  9. fwdtest.cpp
  10. filestreamtest.cpp
  11. itoatest.cpp
  12. istreamwrappertest.cpp
  13. jsoncheckertest.cpp
  14. namespacetest.cpp
  15. pointertest.cpp
  16. prettywritertest.cpp
  17. ostreamwrappertest.cpp
  18. readertest.cpp
  19. regextest.cpp
  20. schematest.cpp
  21. simdtest.cpp
  22. strfunctest.cpp
  23. stringbuffertest.cpp
  24. strtodtest.cpp
  25. unittest.cpp
  26. valuetest.cpp
  27. writertest.cpp)
  28. find_program(CCACHE_FOUND ccache)
  29. if(CCACHE_FOUND)
  30. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  31. set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
  32. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics")
  34. endif()
  35. endif(CCACHE_FOUND)
  36. set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS})
  37. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  38. # If the user is running a newer version of Clang that includes the
  39. # -Wdouble-promotion, we will ignore that warning.
  40. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.7)
  41. CHECK_CXX_COMPILER_FLAG("-Wno-double-promotion" HAS_NO_DOUBLE_PROMOTION)
  42. if (HAS_NO_DOUBLE_PROMOTION)
  43. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion")
  44. endif()
  45. endif()
  46. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  47. # Force to always compile with /W4
  48. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  49. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  50. else()
  51. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  52. endif()
  53. # Force to always compile with /WX
  54. if(CMAKE_CXX_FLAGS MATCHES "/WX-")
  55. string(REGEX REPLACE "/WX-" "/WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  56. else()
  57. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
  58. endif()
  59. endif()
  60. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRAPIDJSON_HAS_STDSTRING=1")
  61. add_library(namespacetest STATIC namespacetest.cpp)
  62. add_executable(unittest ${UNITTEST_SOURCES})
  63. target_link_libraries(unittest ${TEST_LIBRARIES} namespacetest)
  64. add_dependencies(tests unittest)
  65. add_test(NAME unittest
  66. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest
  67. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
  68. if(NOT MSVC)
  69. # Not running SIMD.* unit test cases for Valgrind
  70. add_test(NAME valgrind_unittest
  71. COMMAND valgrind --suppressions=${CMAKE_SOURCE_DIR}/test/valgrind.supp --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest --gtest_filter=-SIMD.*
  72. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
  73. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  74. add_test(NAME symbol_check
  75. COMMAND sh -c "objdump -t -C libnamespacetest.a | grep rapidjson ; test $? -ne 0"
  76. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  77. endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
  78. endif(NOT MSVC)