blob: 47602a1551d6c79c7b401da58b564db8ab0cf1ab [file] [log] [blame]
Roger Meier26593812015-04-12 16:10:35 +02001#
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
James E. King IIIc9ac8d22019-01-07 16:46:45 -050020# 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
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020026# Contains the thrift specific target_link_libraries
Ben Craig7207c222015-07-06 08:40:35 -050027include(ThriftMacros)
28
Ben Craig7207c222015-07-06 08:40:35 -050029find_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
James E. King IIIb2b767e2018-09-15 20:32:04 +000035find_package(ZLIB REQUIRED)
36include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
37
Roger Meier26593812015-04-12 16:10:35 +020038#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
Roger Meier26593812015-04-12 16:10:35 +020043set(crosstestgencpp_SOURCES
James E. King, III58402ff2017-11-17 14:41:46 -050044 gen-cpp/SecondService.cpp
Roger Meier26593812015-04-12 16:10:35 +020045 gen-cpp/ThriftTest.cpp
46 gen-cpp/ThriftTest_types.cpp
47 gen-cpp/ThriftTest_constants.cpp
Marco Molteni83494252015-04-16 13:50:20 +020048 src/ThriftTest_extras.cpp
Roger Meier26593812015-04-12 16:10:35 +020049)
50add_library(crosstestgencpp STATIC ${crosstestgencpp_SOURCES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020051target_link_libraries(crosstestgencpp thrift)
Roger Meier26593812015-04-12 16:10:35 +020052
53set(crossstressgencpp_SOURCES
54 gen-cpp/Service.cpp
Roger Meier26593812015-04-12 16:10:35 +020055)
56add_library(crossstressgencpp STATIC ${crossstressgencpp_SOURCES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020057target_link_libraries(crossstressgencpp thrift)
Roger Meier26593812015-04-12 16:10:35 +020058
Zezeng Wang371d92f2020-04-28 14:23:15 +080059set(crossspecificnamegencpp_SOURCES
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020060 gen-cpp/EchoService.cpp
Zezeng Wang371d92f2020-04-28 14:23:15 +080061 gen-cpp/SpecificNameTest_types.cpp
62)
63add_library(crossspecificnamegencpp STATIC ${crossspecificnamegencpp_SOURCES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020064target_link_libraries(crossspecificnamegencpp thrift)
Zezeng Wang371d92f2020-04-28 14:23:15 +080065
Roger Meier26593812015-04-12 16:10:35 +020066add_executable(TestServer src/TestServer.cpp)
Mario Emmenlauer7553fc52020-11-19 15:19:23 +010067target_link_libraries(TestServer crosstestgencpp ${Boost_LIBRARIES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020068target_link_libraries(TestServer thriftnb)
69target_link_libraries(TestServer thriftz)
Roger Meier26593812015-04-12 16:10:35 +020070
71add_executable(TestClient src/TestClient.cpp)
Mario Emmenlauer7553fc52020-11-19 15:19:23 +010072target_link_libraries(TestClient crosstestgencpp ${Boost_LIBRARIES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020073target_link_libraries(TestClient thriftnb)
74target_link_libraries(TestClient thriftz)
Roger Meier26593812015-04-12 16:10:35 +020075
76add_executable(StressTest src/StressTest.cpp)
Mario Emmenlauer7553fc52020-11-19 15:19:23 +010077target_link_libraries(StressTest crossstressgencpp ${Boost_LIBRARIES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020078target_link_libraries(StressTest thriftnb)
Roger Meier26593812015-04-12 16:10:35 +020079add_test(NAME StressTest COMMAND StressTest)
James E. King III4c57be02019-01-27 11:12:43 -050080add_test(NAME StressTestConcurrent COMMAND StressTest --client-type=concurrent)
Roger Meier26593812015-04-12 16:10:35 +020081
Mario Emmenlauer80279362020-04-24 08:51:37 +020082# 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)
Mario Emmenlauer7553fc52020-11-19 15:19:23 +010086 target_link_libraries(StressTestNonBlocking crossstressgencpp ${Boost_LIBRARIES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020087 target_link_libraries(StressTestNonBlocking thriftnb)
88 target_link_libraries(StressTestNonBlocking thriftz)
Mario Emmenlauer80279362020-04-24 08:51:37 +020089 add_test(NAME StressTestNonBlocking COMMAND StressTestNonBlocking)
90endif()
Roger Meier26593812015-04-12 16:10:35 +020091
Zezeng Wang371d92f2020-04-28 14:23:15 +080092add_executable(SpecificNameTest src/SpecificNameTest.cpp)
93target_link_libraries(SpecificNameTest crossspecificnamegencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020094target_link_libraries(SpecificNameTest thrift)
95target_link_libraries(SpecificNameTest thriftnb)
Zezeng Wang371d92f2020-04-28 14:23:15 +080096add_test(NAME SpecificNameTest COMMAND SpecificNameTest)
97
Copilot1e09a042026-01-29 10:36:28 -080098# ForwardSetterTest - tests the forward_setter option
99set(forwardsettertestgencpp_SOURCES
100 gen-cpp-forward/gen-cpp/ThriftTest_types.cpp
101 gen-cpp-forward/gen-cpp/ThriftTest_constants.cpp
102 src/ThriftTest_extras.cpp
103)
104add_library(forwardsettertestgencpp STATIC ${forwardsettertestgencpp_SOURCES})
105target_include_directories(forwardsettertestgencpp BEFORE PRIVATE
106 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward"
107 "${CMAKE_CURRENT_BINARY_DIR}"
108 "${PROJECT_SOURCE_DIR}/lib/cpp/src"
109)
110target_link_libraries(forwardsettertestgencpp thrift)
111
112add_executable(ForwardSetterTest src/ForwardSetterTest.cpp)
113target_include_directories(ForwardSetterTest BEFORE PRIVATE
114 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward/gen-cpp"
115 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward"
116)
117target_link_libraries(ForwardSetterTest forwardsettertestgencpp ${Boost_LIBRARIES})
118target_link_libraries(ForwardSetterTest thrift)
119add_test(NAME ForwardSetterTest COMMAND ForwardSetterTest)
120
121# PrivateOptionalTest - tests the private_optional option
122set(privateoptonaltestgencpp_SOURCES
123 gen-cpp-private/gen-cpp/ThriftTest_types.cpp
124 gen-cpp-private/gen-cpp/ThriftTest_constants.cpp
125 src/ThriftTest_extras.cpp
126)
127add_library(privateoptonaltestgencpp STATIC ${privateoptonaltestgencpp_SOURCES})
128target_include_directories(privateoptonaltestgencpp BEFORE PRIVATE
129 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private"
130 "${CMAKE_CURRENT_BINARY_DIR}"
131 "${PROJECT_SOURCE_DIR}/lib/cpp/src"
132)
133target_link_libraries(privateoptonaltestgencpp thrift)
134
135add_executable(PrivateOptionalTest src/PrivateOptionalTest.cpp)
136target_include_directories(PrivateOptionalTest BEFORE PRIVATE
137 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private/gen-cpp"
138 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private"
139)
140target_link_libraries(PrivateOptionalTest privateoptonaltestgencpp ${Boost_LIBRARIES})
141target_link_libraries(PrivateOptionalTest thrift)
142add_test(NAME PrivateOptionalTest COMMAND PrivateOptionalTest)
143
144# EnumClassTest - tests the pure_enums=enum_class option
145set(enumclasstestgencpp_SOURCES
146 gen-cpp-enumclass/gen-cpp/ThriftTest_types.cpp
147 gen-cpp-enumclass/gen-cpp/ThriftTest_constants.cpp
148 src/ThriftTest_extras.cpp
149)
150add_library(enumclasstestgencpp STATIC ${enumclasstestgencpp_SOURCES})
151target_include_directories(enumclasstestgencpp BEFORE PRIVATE
152 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass"
153 "${CMAKE_CURRENT_BINARY_DIR}"
154 "${PROJECT_SOURCE_DIR}/lib/cpp/src"
155)
156target_link_libraries(enumclasstestgencpp thrift)
157
158add_executable(EnumClassTest src/EnumClassTest.cpp)
159target_include_directories(EnumClassTest BEFORE PRIVATE
160 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass/gen-cpp"
161 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass"
162)
163target_link_libraries(EnumClassTest enumclasstestgencpp ${Boost_LIBRARIES})
164target_link_libraries(EnumClassTest thrift)
165add_test(NAME EnumClassTest COMMAND EnumClassTest)
166
copilot-swe-agent[bot]c3cdacf2026-02-09 21:30:16 +0000167# TemplateStreamOpTest - tests the template_streamop option
168set(templatestreamoptestgencpp_SOURCES
169 gen-cpp-templatestreamop/gen-cpp/ThriftTest_types.cpp
170 gen-cpp-templatestreamop/gen-cpp/ThriftTest_constants.cpp
171 src/ThriftTest_extras.cpp
172)
173add_library(templatestreamoptestgencpp STATIC ${templatestreamoptestgencpp_SOURCES})
174target_include_directories(templatestreamoptestgencpp BEFORE PRIVATE
175 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-templatestreamop"
176 "${CMAKE_CURRENT_BINARY_DIR}"
177 "${PROJECT_SOURCE_DIR}/lib/cpp/src"
178)
179target_link_libraries(templatestreamoptestgencpp thrift)
180
181add_executable(TemplateStreamOpTest src/TemplateStreamOpTest.cpp)
182target_include_directories(TemplateStreamOpTest BEFORE PRIVATE
183 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-templatestreamop/gen-cpp"
184 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-templatestreamop"
185)
186target_link_libraries(TemplateStreamOpTest templatestreamoptestgencpp ${Boost_LIBRARIES})
187target_link_libraries(TemplateStreamOpTest thrift)
188add_test(NAME TemplateStreamOpTest COMMAND TemplateStreamOpTest)
189
Copilot13cdb442026-03-17 15:08:29 -0700190# PrivateOptionalTemplateStreamOpTest - tests private_optional and template_streamop together
191set(privateopttemplstreamoptestgencpp_SOURCES
192 gen-cpp-private-templatestreamop/gen-cpp/ThriftTest_types.cpp
193 gen-cpp-private-templatestreamop/gen-cpp/ThriftTest_constants.cpp
194 src/ThriftTest_extras.cpp
195)
196add_library(privateopttemplstreamoptestgencpp STATIC ${privateopttemplstreamoptestgencpp_SOURCES})
197target_include_directories(privateopttemplstreamoptestgencpp BEFORE PRIVATE
198 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private-templatestreamop"
199 "${CMAKE_CURRENT_BINARY_DIR}"
200 "${PROJECT_SOURCE_DIR}/lib/cpp/src"
201)
202target_link_libraries(privateopttemplstreamoptestgencpp thrift)
203
204add_executable(PrivateOptionalTemplateStreamOpTest src/PrivateOptionalTemplateStreamOpTest.cpp)
205target_include_directories(PrivateOptionalTemplateStreamOpTest BEFORE PRIVATE
206 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private-templatestreamop/gen-cpp"
207 "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private-templatestreamop"
208)
209target_link_libraries(PrivateOptionalTemplateStreamOpTest privateopttemplstreamoptestgencpp ${Boost_LIBRARIES})
210target_link_libraries(PrivateOptionalTemplateStreamOpTest thrift)
211add_test(NAME PrivateOptionalTemplateStreamOpTest COMMAND PrivateOptionalTemplateStreamOpTest)
212
Roger Meier26593812015-04-12 16:10:35 +0200213#
214# Common thrift code generation rules
215#
216
James E. King, III58402ff2017-11-17 14:41:46 -0500217add_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
CJCombrink1d886ca2024-03-23 21:32:28 +0100218 COMMAND ${THRIFT_COMPILER} --gen cpp:templates,cob_style -r ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
Roger Meier26593812015-04-12 16:10:35 +0200219)
220
Copilot1e09a042026-01-29 10:36:28 -0800221# Generate ThriftTest with forward_setter option for ForwardSetterTest
222add_custom_command(OUTPUT gen-cpp-forward/gen-cpp/ThriftTest_types.cpp gen-cpp-forward/gen-cpp/ThriftTest_types.h gen-cpp-forward/gen-cpp/ThriftTest_types.tcc gen-cpp-forward/gen-cpp/ThriftTest_constants.cpp
223 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward
224 COMMAND ${THRIFT_COMPILER} --gen cpp:moveable_types=forward_setter -o gen-cpp-forward ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
225 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
226)
227
228# Generate ThriftTest with private_optional option for PrivateOptionalTest
229add_custom_command(OUTPUT gen-cpp-private/gen-cpp/ThriftTest_types.cpp gen-cpp-private/gen-cpp/ThriftTest_types.h gen-cpp-private/gen-cpp/ThriftTest_constants.cpp
230 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private
231 COMMAND ${THRIFT_COMPILER} --gen cpp:private_optional -o gen-cpp-private ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
232 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
233)
234
235# Generate ThriftTest with pure_enums=enum_class option for EnumClassTest
236add_custom_command(OUTPUT gen-cpp-enumclass/gen-cpp/ThriftTest_types.cpp gen-cpp-enumclass/gen-cpp/ThriftTest_types.h gen-cpp-enumclass/gen-cpp/ThriftTest_constants.cpp
237 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass
238 COMMAND ${THRIFT_COMPILER} --gen cpp:pure_enums=enum_class -o gen-cpp-enumclass ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
239 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
240)
241
copilot-swe-agent[bot]c3cdacf2026-02-09 21:30:16 +0000242# Generate ThriftTest with template_streamop option for TemplateStreamOpTest
243add_custom_command(OUTPUT gen-cpp-templatestreamop/gen-cpp/ThriftTest_types.cpp gen-cpp-templatestreamop/gen-cpp/ThriftTest_types.h gen-cpp-templatestreamop/gen-cpp/ThriftTest_constants.cpp
244 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-templatestreamop
245 COMMAND ${THRIFT_COMPILER} --gen cpp:template_streamop -o gen-cpp-templatestreamop ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
246 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
247)
248
Copilot13cdb442026-03-17 15:08:29 -0700249# Generate ThriftTest with private_optional,template_streamop options for PrivateOptionalTemplateStreamOpTest
250add_custom_command(OUTPUT gen-cpp-private-templatestreamop/gen-cpp/ThriftTest_types.cpp gen-cpp-private-templatestreamop/gen-cpp/ThriftTest_types.h gen-cpp-private-templatestreamop/gen-cpp/ThriftTest_constants.cpp
251 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private-templatestreamop
252 COMMAND ${THRIFT_COMPILER} --gen cpp:private_optional,template_streamop -o gen-cpp-private-templatestreamop ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
253 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
254)
255
zeshuai00757c25072020-04-09 11:17:05 +0800256add_custom_command(OUTPUT gen-cpp/Service.cpp
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900257 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
Roger Meier26593812015-04-12 16:10:35 +0200258)
Zezeng Wang371d92f2020-04-28 14:23:15 +0800259
260add_custom_command(OUTPUT gen-cpp/EchoService.cpp gen-cpp/SpecificNameTest_types.cpp
261 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/SpecificNameTest.thrift
262)