Skip to content

Commit 0ea6eec

Browse files
committed
log version; add precompiled headers
1 parent 1dde020 commit 0ea6eec

File tree

5 files changed

+46
-25
lines changed

5 files changed

+46
-25
lines changed

CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ project(websocket_proxy
66
VERSION ${BUILD_VERSION}
77
LANGUAGES CXX)
88

9-
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
10-
configure_file(src/version.h.in include/version.h)
11-
129
set(CMAKE_CXX_STANDARD 20)
1310

1411
if (NOT CMAKE_BUILD_TYPE)
@@ -23,6 +20,10 @@ if (CMAKE_BUILD_TYPE MATCHES Release)
2320
add_definitions(-DNDEBUG)
2421
endif()
2522

23+
set(RELEASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/release")
24+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include" DESTINATION "${RELEASE_DIR}")
25+
configure_file(src/version.h.in release/include/websocket_proxy/version.h)
26+
2627
find_package(boost_beast REQUIRED CONFIG)
2728
find_package(OpenSSL REQUIRED)
2829
find_package(spdlog REQUIRED CONFIG)
@@ -43,13 +44,18 @@ set(SOURCES
4344
)
4445

4546
add_executable(websocket_proxy ${SOURCES})
46-
target_include_directories(websocket_proxy PUBLIC include ${slick_queue_SOURCE_DIR}/include ${spdlog_SOURCE_DIR} ${CMAKE_BINARY_DIR})
47+
target_include_directories(websocket_proxy PUBLIC include ${slick_queue_SOURCE_DIR}/include ${spdlog_SOURCE_DIR} ${RELEASE_DIR}/include)
4748
target_link_libraries(websocket_proxy PRIVATE spdlog::spdlog_header_only Boost::asio Boost::beast OpenSSL::SSL OpenSSL::Crypto)
49+
target_precompile_headers(websocket_proxy PRIVATE src/pch.hpp)
4850

4951
if (MSVC)
5052
add_definitions(-D_WIN32_WINNT=0x0A00)
5153
set(CMAKE_SUPPRESS_REGENERATION true) # supress zero_check
54+
set_target_properties(websocket_proxy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
55+
set_target_properties(websocket_proxy PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/Debug")
56+
set_target_properties(websocket_proxy PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin/Release")
57+
set_target_properties(websocket_proxy PROPERTIES LINK_INCREMENTAL ON)
5258
target_compile_definitions(websocket_proxy PUBLIC _UNICODE) # set CharacterSet to unicode
5359
target_compile_options(websocket_proxy PRIVATE "/bigobj")
5460
set_target_properties(websocket_proxy PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
55-
endif()
61+
endif()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "alpaca_websocket_client.h"
2+
3+
using namespace websocket_proxy;
4+
using namespace alpaca_websocket;
5+
6+
int main(int argc, char* argv[])
7+
{
8+
#ifdef DEBUG
9+
std::string proxy_exe("../Debug/websocket_proxy.exe");
10+
#else
11+
std::string proxy_exe("../Release/websocket_proxy.exe");
12+
#endif
13+
14+
AlpacaWebSocketClient client(proxy_exe);
15+
client.openWebsocket();
16+
}

src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "spdlog/sinks/stdout_color_sinks.h"
1313
#endif
1414
#include "websocket_proxy.h"
15+
#include <websocket_proxy/version.h>
1516

1617
#ifdef _WIN32
1718
#pragma comment(lib, "Ws2_32.lib")
@@ -92,7 +93,7 @@ int main(int argc, char* argv[])
9293

9394
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%F][%t][%l][%s:%#] %v");
9495

95-
SPDLOG_INFO("Start WebsocketProxy...");
96+
SPDLOG_INFO(std::format("Start WebsocketProxy {}.{}.{}.{} ...", WebsocketProxy_VERSION_MAJOR, WebsocketProxy_VERSION_MINOR, WebsocketProxy_VERSION_PATCH, WebsocketProxy_VERSION_TWEAK));
9697
WebsocketProxy proxy(server_queue_size);
9798
proxy.run();
9899
SPDLOG_INFO("WebsocketProxy Exit.");

src/pch.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <atomic>
2+
#include <string>
3+
#include <unordered_map>
4+
#include <unordered_set>
5+
#include <vector>
6+
#include <cstdlib>
7+
#include <format>
8+
#include <boost/beast/core.hpp>
9+
#include <boost/beast/websocket.hpp>
10+
#include <boost/beast/websocket/ssl.hpp>
11+
#include <boost/asio.hpp>
12+
#include <boost/asio/ssl.hpp>
13+
#include <boost/asio/strand.hpp>
14+
#include <boost/asio/spawn.hpp>
15+
#include <boost/asio/signal_set.hpp>
16+
#include <spdlog/spdlog.h>

src/websocket_proxy.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void WebsocketProxy::run() {
129129
boost::asio::signal_set signals(ioc_, SIGINT, SIGTERM);
130130
signals.async_wait([&](auto, auto){ stop(); });
131131

132-
SPDLOG_INFO("\n\nWebsocketProxy started. PID={}\n\n", pid_);
132+
SPDLOG_INFO("\n\nWebsocketProxy started. PID={}\n", pid_);
133133

134134
// start heartbeat
135135
ioc_.post([this]() { startHeartbeat(); });
@@ -156,24 +156,6 @@ void WebsocketProxy::run() {
156156
}
157157
}
158158

159-
// while (run_.load(std::memory_order_relaxed)) {
160-
// auto req = client_queue_.read(client_index_);
161-
// if (req.first) {
162-
// handleClientMessage(reinterpret_cast<Message&>(*req.first));
163-
// }
164-
165-
// removeClosedSockets();
166-
167-
// if (!checkHeartbeats() && !req.first) {
168-
// std::this_thread::yield();
169-
// }
170-
171-
// if (shutdown_time_ && (get_timestamp() - shutdown_time_) >= 60000) {
172-
// run_.store(false, std::memory_order_release);
173-
// break;
174-
// }
175-
// }
176-
177159
SPDLOG_INFO("WebsocketProxy Exit. PID={}", pid_);
178160
}
179161

0 commit comments

Comments
 (0)