| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 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 | |
| James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 20 | # The test executables still depend on Boost |
| 21 | include(BoostMacros) |
| 22 | REQUIRE_BOOST_HEADERS() |
| 23 | set(BOOST_COMPONENTS filesystem program_options random) |
| 24 | REQUIRE_BOOST_LIBRARIES(BOOST_COMPONENTS) |
| 25 | |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 26 | # Contains the thrift specific target_link_libraries |
| Ben Craig | 7207c22 | 2015-07-06 08:40:35 -0500 | [diff] [blame] | 27 | include(ThriftMacros) |
| 28 | |
| Ben Craig | 7207c22 | 2015-07-06 08:40:35 -0500 | [diff] [blame] | 29 | find_package(OpenSSL REQUIRED) |
| 30 | include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") |
| 31 | |
| 32 | find_package(Libevent REQUIRED) # Libevent comes with CMake support from upstream |
| 33 | include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS}) |
| 34 | |
| James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 35 | find_package(ZLIB REQUIRED) |
| 36 | include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS}) |
| 37 | |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 38 | #Make sure gen-cpp files can be included |
| 39 | include_directories("${CMAKE_CURRENT_BINARY_DIR}") |
| 40 | include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp") |
| 41 | include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src") |
| 42 | |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 43 | set(crosstestgencpp_SOURCES |
| James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 44 | gen-cpp/SecondService.cpp |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 45 | gen-cpp/ThriftTest.cpp |
| 46 | gen-cpp/ThriftTest_types.cpp |
| 47 | gen-cpp/ThriftTest_constants.cpp |
| Marco Molteni | 8349425 | 2015-04-16 13:50:20 +0200 | [diff] [blame] | 48 | src/ThriftTest_extras.cpp |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 49 | ) |
| 50 | add_library(crosstestgencpp STATIC ${crosstestgencpp_SOURCES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 51 | target_link_libraries(crosstestgencpp thrift) |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 52 | |
| 53 | set(crossstressgencpp_SOURCES |
| 54 | gen-cpp/Service.cpp |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 55 | ) |
| 56 | add_library(crossstressgencpp STATIC ${crossstressgencpp_SOURCES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 57 | target_link_libraries(crossstressgencpp thrift) |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 58 | |
| Zezeng Wang | 371d92f | 2020-04-28 14:23:15 +0800 | [diff] [blame] | 59 | set(crossspecificnamegencpp_SOURCES |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 60 | gen-cpp/EchoService.cpp |
| Zezeng Wang | 371d92f | 2020-04-28 14:23:15 +0800 | [diff] [blame] | 61 | gen-cpp/SpecificNameTest_types.cpp |
| 62 | ) |
| 63 | add_library(crossspecificnamegencpp STATIC ${crossspecificnamegencpp_SOURCES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 64 | target_link_libraries(crossspecificnamegencpp thrift) |
| Zezeng Wang | 371d92f | 2020-04-28 14:23:15 +0800 | [diff] [blame] | 65 | |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 66 | add_executable(TestServer src/TestServer.cpp) |
| Mario Emmenlauer | 7553fc5 | 2020-11-19 15:19:23 +0100 | [diff] [blame] | 67 | target_link_libraries(TestServer crosstestgencpp ${Boost_LIBRARIES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 68 | target_link_libraries(TestServer thriftnb) |
| 69 | target_link_libraries(TestServer thriftz) |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 70 | |
| 71 | add_executable(TestClient src/TestClient.cpp) |
| Mario Emmenlauer | 7553fc5 | 2020-11-19 15:19:23 +0100 | [diff] [blame] | 72 | target_link_libraries(TestClient crosstestgencpp ${Boost_LIBRARIES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 73 | target_link_libraries(TestClient thriftnb) |
| 74 | target_link_libraries(TestClient thriftz) |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 75 | |
| 76 | add_executable(StressTest src/StressTest.cpp) |
| Mario Emmenlauer | 7553fc5 | 2020-11-19 15:19:23 +0100 | [diff] [blame] | 77 | target_link_libraries(StressTest crossstressgencpp ${Boost_LIBRARIES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 78 | target_link_libraries(StressTest thriftnb) |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 79 | add_test(NAME StressTest COMMAND StressTest) |
| James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 80 | add_test(NAME StressTestConcurrent COMMAND StressTest --client-type=concurrent) |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 81 | |
| Mario Emmenlauer | 8027936 | 2020-04-24 08:51:37 +0200 | [diff] [blame] | 82 | # As of https://jira.apache.org/jira/browse/THRIFT-4282, StressTestNonBlocking |
| 83 | # is broken on Windows. Contributions welcome. |
| 84 | if (NOT WIN32 AND NOT CYGWIN) |
| 85 | add_executable(StressTestNonBlocking src/StressTestNonBlocking.cpp) |
| Mario Emmenlauer | 7553fc5 | 2020-11-19 15:19:23 +0100 | [diff] [blame] | 86 | target_link_libraries(StressTestNonBlocking crossstressgencpp ${Boost_LIBRARIES}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 87 | target_link_libraries(StressTestNonBlocking thriftnb) |
| 88 | target_link_libraries(StressTestNonBlocking thriftz) |
| Mario Emmenlauer | 8027936 | 2020-04-24 08:51:37 +0200 | [diff] [blame] | 89 | add_test(NAME StressTestNonBlocking COMMAND StressTestNonBlocking) |
| 90 | endif() |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 91 | |
| Zezeng Wang | 371d92f | 2020-04-28 14:23:15 +0800 | [diff] [blame] | 92 | add_executable(SpecificNameTest src/SpecificNameTest.cpp) |
| 93 | target_link_libraries(SpecificNameTest crossspecificnamegencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB}) |
| Mario Emmenlauer | bdb54bc | 2021-08-31 14:00:16 +0200 | [diff] [blame] | 94 | target_link_libraries(SpecificNameTest thrift) |
| 95 | target_link_libraries(SpecificNameTest thriftnb) |
| Zezeng Wang | 371d92f | 2020-04-28 14:23:15 +0800 | [diff] [blame] | 96 | add_test(NAME SpecificNameTest COMMAND SpecificNameTest) |
| 97 | |
| Copilot | 1e09a04 | 2026-01-29 10:36:28 -0800 | [diff] [blame^] | 98 | # ForwardSetterTest - tests the forward_setter option |
| 99 | set(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 | ) |
| 104 | add_library(forwardsettertestgencpp STATIC ${forwardsettertestgencpp_SOURCES}) |
| 105 | target_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 | ) |
| 110 | target_link_libraries(forwardsettertestgencpp thrift) |
| 111 | |
| 112 | add_executable(ForwardSetterTest src/ForwardSetterTest.cpp) |
| 113 | target_include_directories(ForwardSetterTest BEFORE PRIVATE |
| 114 | "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward/gen-cpp" |
| 115 | "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward" |
| 116 | ) |
| 117 | target_link_libraries(ForwardSetterTest forwardsettertestgencpp ${Boost_LIBRARIES}) |
| 118 | target_link_libraries(ForwardSetterTest thrift) |
| 119 | add_test(NAME ForwardSetterTest COMMAND ForwardSetterTest) |
| 120 | |
| 121 | # PrivateOptionalTest - tests the private_optional option |
| 122 | set(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 | ) |
| 127 | add_library(privateoptonaltestgencpp STATIC ${privateoptonaltestgencpp_SOURCES}) |
| 128 | target_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 | ) |
| 133 | target_link_libraries(privateoptonaltestgencpp thrift) |
| 134 | |
| 135 | add_executable(PrivateOptionalTest src/PrivateOptionalTest.cpp) |
| 136 | target_include_directories(PrivateOptionalTest BEFORE PRIVATE |
| 137 | "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private/gen-cpp" |
| 138 | "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private" |
| 139 | ) |
| 140 | target_link_libraries(PrivateOptionalTest privateoptonaltestgencpp ${Boost_LIBRARIES}) |
| 141 | target_link_libraries(PrivateOptionalTest thrift) |
| 142 | add_test(NAME PrivateOptionalTest COMMAND PrivateOptionalTest) |
| 143 | |
| 144 | # EnumClassTest - tests the pure_enums=enum_class option |
| 145 | set(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 | ) |
| 150 | add_library(enumclasstestgencpp STATIC ${enumclasstestgencpp_SOURCES}) |
| 151 | target_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 | ) |
| 156 | target_link_libraries(enumclasstestgencpp thrift) |
| 157 | |
| 158 | add_executable(EnumClassTest src/EnumClassTest.cpp) |
| 159 | target_include_directories(EnumClassTest BEFORE PRIVATE |
| 160 | "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass/gen-cpp" |
| 161 | "${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass" |
| 162 | ) |
| 163 | target_link_libraries(EnumClassTest enumclasstestgencpp ${Boost_LIBRARIES}) |
| 164 | target_link_libraries(EnumClassTest thrift) |
| 165 | add_test(NAME EnumClassTest COMMAND EnumClassTest) |
| 166 | |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 167 | # |
| 168 | # Common thrift code generation rules |
| 169 | # |
| 170 | |
| James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 171 | add_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 |
| CJCombrink | 1d886ca | 2024-03-23 21:32:28 +0100 | [diff] [blame] | 172 | COMMAND ${THRIFT_COMPILER} --gen cpp:templates,cob_style -r ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 173 | ) |
| 174 | |
| Copilot | 1e09a04 | 2026-01-29 10:36:28 -0800 | [diff] [blame^] | 175 | # Generate ThriftTest with forward_setter option for ForwardSetterTest |
| 176 | add_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 |
| 177 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-forward |
| 178 | COMMAND ${THRIFT_COMPILER} --gen cpp:moveable_types=forward_setter -o gen-cpp-forward ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift |
| 179 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 180 | ) |
| 181 | |
| 182 | # Generate ThriftTest with private_optional option for PrivateOptionalTest |
| 183 | add_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 |
| 184 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-private |
| 185 | COMMAND ${THRIFT_COMPILER} --gen cpp:private_optional -o gen-cpp-private ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift |
| 186 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 187 | ) |
| 188 | |
| 189 | # Generate ThriftTest with pure_enums=enum_class option for EnumClassTest |
| 190 | add_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 |
| 191 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen-cpp-enumclass |
| 192 | COMMAND ${THRIFT_COMPILER} --gen cpp:pure_enums=enum_class -o gen-cpp-enumclass ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift |
| 193 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 194 | ) |
| 195 | |
| zeshuai007 | 57c2507 | 2020-04-09 11:17:05 +0800 | [diff] [blame] | 196 | add_custom_command(OUTPUT gen-cpp/Service.cpp |
| Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 197 | COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift |
| Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 198 | ) |
| Zezeng Wang | 371d92f | 2020-04-28 14:23:15 +0800 | [diff] [blame] | 199 | |
| 200 | add_custom_command(OUTPUT gen-cpp/EchoService.cpp gen-cpp/SpecificNameTest_types.cpp |
| 201 | COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/SpecificNameTest.thrift |
| 202 | ) |