1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10#   http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
20# The test executables still depend on Boost
21include(BoostMacros)
22REQUIRE_BOOST_HEADERS()
23set(BOOST_COMPONENTS filesystem program_options random)
24REQUIRE_BOOST_LIBRARIES(BOOST_COMPONENTS)
25
26# Contains the thrift specific target_link_libraries
27include(ThriftMacros)
28
29find_package(OpenSSL REQUIRED)
30include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
31
32find_package(Libevent REQUIRED)  # Libevent comes with CMake support from upstream
33include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
34
35find_package(ZLIB REQUIRED)
36include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
37
38#Make sure gen-cpp files can be included
39include_directories("${CMAKE_CURRENT_BINARY_DIR}")
40include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp")
41include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
42
43set(crosstestgencpp_SOURCES
44    gen-cpp/SecondService.cpp
45    gen-cpp/ThriftTest.cpp
46    gen-cpp/ThriftTest_types.cpp
47    gen-cpp/ThriftTest_constants.cpp
48    src/ThriftTest_extras.cpp
49)
50add_library(crosstestgencpp STATIC ${crosstestgencpp_SOURCES})
51target_link_libraries(crosstestgencpp thrift)
52
53set(crossstressgencpp_SOURCES
54    gen-cpp/Service.cpp
55)
56add_library(crossstressgencpp STATIC ${crossstressgencpp_SOURCES})
57target_link_libraries(crossstressgencpp thrift)
58
59set(crossspecificnamegencpp_SOURCES
60    gen-cpp/EchoService.cpp
61    gen-cpp/SpecificNameTest_types.cpp
62)
63add_library(crossspecificnamegencpp STATIC ${crossspecificnamegencpp_SOURCES})
64target_link_libraries(crossspecificnamegencpp thrift)
65
66add_executable(TestServer src/TestServer.cpp)
67target_link_libraries(TestServer crosstestgencpp ${Boost_LIBRARIES})
68target_link_libraries(TestServer thriftnb)
69target_link_libraries(TestServer thriftz)
70
71add_executable(TestClient src/TestClient.cpp)
72target_link_libraries(TestClient crosstestgencpp ${Boost_LIBRARIES})
73target_link_libraries(TestClient thriftnb)
74target_link_libraries(TestClient thriftz)
75
76add_executable(StressTest src/StressTest.cpp)
77target_link_libraries(StressTest crossstressgencpp ${Boost_LIBRARIES})
78target_link_libraries(StressTest thriftnb)
79add_test(NAME StressTest COMMAND StressTest)
80add_test(NAME StressTestConcurrent COMMAND StressTest --client-type=concurrent)
81
82# As of https://jira.apache.org/jira/browse/THRIFT-4282, StressTestNonBlocking
83# is broken on Windows. Contributions welcome.
84if (NOT WIN32 AND NOT CYGWIN)
85    add_executable(StressTestNonBlocking src/StressTestNonBlocking.cpp)
86    target_link_libraries(StressTestNonBlocking crossstressgencpp ${Boost_LIBRARIES})
87    target_link_libraries(StressTestNonBlocking thriftnb)
88    target_link_libraries(StressTestNonBlocking thriftz)
89    add_test(NAME StressTestNonBlocking COMMAND StressTestNonBlocking)
90endif()
91
92add_executable(SpecificNameTest src/SpecificNameTest.cpp)
93target_link_libraries(SpecificNameTest crossspecificnamegencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB})
94target_link_libraries(SpecificNameTest thrift)
95target_link_libraries(SpecificNameTest thriftnb)
96add_test(NAME SpecificNameTest COMMAND SpecificNameTest)
97
98#
99# Common thrift code generation rules
100#
101
102add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/SecondService.h gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest.h gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_constants.cpp
103    COMMAND ${THRIFT_COMPILER} --gen cpp:templates,cob_style -r ${PROJECT_SOURCE_DIR}/test/v0.16/ThriftTest.thrift
104)
105
106add_custom_command(OUTPUT gen-cpp/Service.cpp
107    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
108)
109
110add_custom_command(OUTPUT gen-cpp/EchoService.cpp gen-cpp/SpecificNameTest_types.cpp
111    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/SpecificNameTest.thrift
112)
113