Fixes RigtorpMPMC test case
[libcds.git] / test / CMakeLists.txt
1
2 INCLUDE(CheckCXXSourceCompiles)
3
4 if (NOT GTEST_INCLUDE_DIRS)
5    find_package(GTest REQUIRED)
6 endif()
7 message("GTest: ${GTEST_INCLUDE_DIRS}, lib: ${GTEST_LIBRARIES}")
8
9 include_directories(
10     ${CMAKE_CURRENT_SOURCE_DIR}/include
11     ${GTEST_INCLUDE_DIRS}
12 )
13
14 set(CDS_TEST_LIBRARIES
15     ${CDS_SHARED_LIBRARY}
16     ${GTEST_LIBRARIES}
17     ${Boost_THREAD_LIBRARY}
18     ${Boost_SYSTEM_LIBRARY}
19     ${CMAKE_THREAD_LIBS_INIT}
20     ${EXTERNAL_SYSTEM_LIBS}
21 )
22
23 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_LANG_CXX11") 
24
25 # Check if gtest INSTANTIATE_TEST_CASE_P macro supports 4th arg
26 # The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
27 # to specify a function or functor that generates custom test name suffixes
28 # based on the test parameters. The function should accept one argument of
29 # type testing::TestParamInfo<class ParamType>, and return std::string.
30 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
31 set(OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
32 set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
33 set(CMAKE_REQUIRED_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE ${CMAKE_EXE_LINKER_FLAGS}")
34 set(CMAKE_REQUIRED_INCLUDES ${GTEST_INCLUDE_DIRS} )
35 set(CMAKE_REQUIRED_LIBRARIES ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${EXTERNAL_SYSTEM_LIBS} )
36 CHECK_CXX_SOURCE_COMPILES("
37 #include <gtest/gtest.h>
38 class fixture: public ::testing::Test, public ::testing::WithParamInterface< int >
39 {
40 public:
41     static std::vector< int > get_test_parameters()
42     {
43         std::vector< int > v{ 1, 2 };
44         return v;
45     }
46     static std::string get_test_parameter_name( ::testing::TestParamInfo<int> const& )
47     {
48         return std::string();
49     }
50 };
51
52 INSTANTIATE_TEST_CASE_P( a,
53     fixture,
54     ::testing::ValuesIn( fixture::get_test_parameters()),
55     fixture::get_test_parameter_name );
56
57 int main( int argc, char **argv ) 
58 {
59     ::testing::InitGoogleTest( &argc, argv );
60     return RUN_ALL_TESTS();
61 }
62 " GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG )
63 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
64 set(CMAKE_REQUIRED_INCLUDES ${OLD_CMAKE_REQUIRED_INCLUDES})
65 set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
66
67 if(GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG)
68     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_LANG_CXX11 -DCDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG") 
69 endif()
70
71 # Check if there is byteswap.h (needed for cityhash)
72 CHECK_CXX_SOURCE_COMPILES("
73 #include <byteswap.h>
74 int main( int argc, char **argv ) 
75 {
76     return 0;
77 }
78 " CDSTEST_HAVE_BYTESWAP_H )
79
80 if(CDSTEST_HAVE_BYTESWAP_H)
81     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCDSTEST_HAVE_BYTESWAP_H") 
82 endif()
83
84 if(ENABLE_UNIT_TEST)
85     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit)
86 endif()
87 if(ENABLE_STRESS_TEST)
88     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/stress)
89 endif()
90
91 file(GLOB SANITIZER_OPTION_FILES ${PROJECT_SOURCE_DIR}/tools/tsan-suppression)
92 file(COPY ${SANITIZER_OPTION_FILES} DESTINATION ${EXECUTABLE_OUTPUT_PATH})