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