From 6635061edd3c5fc15e81c9af4fb4725c27fbf8f9 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Thu, 5 Nov 2026 21:49:23 -0600 Subject: [PATCH] Fix build with CMake 4 and Boost >= 1.89 - Boost.System is header-only and Boost 1.89 removed its CMake package, so request it as an optional component and fall back to Boost::headers. - Replace Asio APIs removed in Boost 1.87: address(_v4)::from_string -> make_address(_v4), io_context::reset -> restart, io_service -> io_context. The replacements are available since Boost 1.66. - Update iso22133 submodule with its CMake 4 fix (RI-SE/iso22133#54). Co-Authored-By: Claude Opus 5.5 --- CMakeLists.txt | 11 +++++++++-- inc/tcpServer.hpp | 4 ++-- inc/udpServer.hpp | 2 +- iso22133 | 2 +- src/iso22133object.cpp | 2 +- tests/isoObject.cpp | 8 ++++---- tests/test_tcpServer.cpp | 6 +++--- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9451b6..a00d941 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,14 @@ if (BUILDING_FOR_ANDROID) # Boost is found in variables set by android toolchain include_directories(${ANDROID_BOOST_INCLUDE_DIR}) else() # Find boost normally - find_package(Boost REQUIRED COMPONENTS system) + # Boost.System is header-only since Boost 1.69 and its CMake package was + # removed in Boost 1.89, so only request the component on older versions. + find_package(Boost REQUIRED OPTIONAL_COMPONENTS system) + if (TARGET Boost::system) + set(BOOST_SYSTEM_TARGET Boost::system) + else() + set(BOOST_SYSTEM_TARGET Boost::headers) + endif() endif() # Library target @@ -68,7 +75,7 @@ target_include_directories(${ISOOBJECT_LIBRARY} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/iso22133 ) set(ISO_OBJ_LIBS - ${ISO22133_LIBRARY} atomic pthread Boost::system) + ${ISO22133_LIBRARY} atomic pthread ${BOOST_SYSTEM_TARGET}) set(ISO_OBJ_LIBS_ANDROID ${ISO22133_LIBRARY} atomic ${boost_system}) if (BUILDING_FOR_ANDROID) diff --git a/inc/tcpServer.hpp b/inc/tcpServer.hpp index c90ad6f..da49ff8 100644 --- a/inc/tcpServer.hpp +++ b/inc/tcpServer.hpp @@ -15,7 +15,7 @@ class TcpServer { public: TcpServer(std::string ip, std::uint32_t port) : - acceptor(context, boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string(ip), port)), + acceptor(context, boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address_v4(ip), port)), socket(context), acceptIncoming(true) { setBufferSize(defaultBufferSize); @@ -39,7 +39,7 @@ class TcpServer { socket.shutdown(boost::asio::socket_base::shutdown_both); socket.close(); } - context.reset(); + context.restart(); } catch (boost::system::system_error& e) { std::cerr << "Error when closing socket: " << e.what() << std::endl; } diff --git a/inc/udpServer.hpp b/inc/udpServer.hpp index 77e7db1..ab0670e 100644 --- a/inc/udpServer.hpp +++ b/inc/udpServer.hpp @@ -16,7 +16,7 @@ class UdpServer { public: UdpServer(const std::string& ip, std::uint32_t port) : - socket(context, boost::asio::ip::udp::endpoint(boost::asio::ip::address_v4::from_string(ip), port)) { + socket(context, boost::asio::ip::udp::endpoint(boost::asio::ip::make_address_v4(ip), port)) { setBufferSize(defaultBufferSize); } UdpServer() : diff --git a/iso22133 b/iso22133 index 6bbcee7..4b37798 160000 --- a/iso22133 +++ b/iso22133 @@ -1 +1 @@ -Subproject commit 6bbcee765aa503c8b6349ffb25b0f3c3253e1db8 +Subproject commit 4b37798ede1a27f84b4fb6049783a3786ab11513 diff --git a/src/iso22133object.cpp b/src/iso22133object.cpp index 2a0dafb..0906e36 100644 --- a/src/iso22133object.cpp +++ b/src/iso22133object.cpp @@ -290,7 +290,7 @@ int TestObject::handleTCPMessage(char* buffer, int bufferLen) { int TestObject::handleUDPMessage(char* buffer, int bufferLen, int udpSocket, char* addr, const std::uint32_t port) { if (awaitingFirstHeab) { boost::asio::ip::udp::endpoint udpEp = - boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string(addr), port); + boost::asio::ip::udp::endpoint(boost::asio::ip::make_address(addr), port); processChannel.setEndpoint(udpSocket, udpEp); ; this->startSendMonr(); diff --git a/tests/isoObject.cpp b/tests/isoObject.cpp index 2fdb99b..93f3db3 100644 --- a/tests/isoObject.cpp +++ b/tests/isoObject.cpp @@ -42,7 +42,7 @@ class ControlCenterEmulator { void connect() { try { tcpSocket.connect( - ip::tcp::endpoint(ip::address_v4::from_string(listenIP), ISO_22133_DEFAULT_OBJECT_TCP_PORT)); + ip::tcp::endpoint(ip::make_address_v4(listenIP), ISO_22133_DEFAULT_OBJECT_TCP_PORT)); } catch (boost::system::system_error err) { EXPECT_EQ(1, 2) << "TCP Connection failed"; } @@ -51,7 +51,7 @@ class ControlCenterEmulator { tcpSocket.send(buffer(data)); } void sendUDP(const std::vector& data) { - ip::udp::endpoint receiverEP(ip::address_v4::from_string(listenIP), ISO_22133_OBJECT_UDP_PORT); + ip::udp::endpoint receiverEP(ip::make_address_v4(listenIP), ISO_22133_OBJECT_UDP_PORT); udpSocket.send_to(buffer(data), receiverEP); } void disconnect() { @@ -161,8 +161,8 @@ class ControlCenterEmulator { class ControllerEmulator { public: ControllerEmulator(const std::string& listenIP = "127.0.0.1") : - acceptor(context, ip::tcp::endpoint(ip::address_v4::from_string(listenIP), ISO_22133_DEFAULT_OBJECT_TCP_PORT)), - udpSocket(context, ip::udp::endpoint(ip::address_v4::from_string(listenIP), ISO_22133_OBJECT_UDP_PORT)) {} + acceptor(context, ip::tcp::endpoint(ip::make_address_v4(listenIP), ISO_22133_DEFAULT_OBJECT_TCP_PORT)), + udpSocket(context, ip::udp::endpoint(ip::make_address_v4(listenIP), ISO_22133_OBJECT_UDP_PORT)) {} virtual ~ControllerEmulator() = default; /* * Remember to delete the socket after!! diff --git a/tests/test_tcpServer.cpp b/tests/test_tcpServer.cpp index 6f0de05..7ef47ab 100644 --- a/tests/test_tcpServer.cpp +++ b/tests/test_tcpServer.cpp @@ -40,9 +40,9 @@ class tcpServer_connect_new_socket : public ::testing::Test { TEST_F(tcpServer_connect_new_socket, connect) { // Connect to server - io_service io_service; + io_context io_service; ip::tcp::socket socket(io_service); - ip::tcp::endpoint endpoint(ip::address::from_string("127.0.0.1"), 1234); + ip::tcp::endpoint endpoint(ip::make_address("127.0.0.1"), 1234); try { socket.connect(endpoint); } catch (boost::system::system_error& e) { @@ -59,7 +59,7 @@ class tcpServer_on_existing_socket : public ::testing::Test { server = NULL; std::shared_future readyFuture(readyPromise.get_future()); // Start server - ip::tcp::endpoint ep(ip::address_v4::from_string("127.0.0.1"), 1234); + ip::tcp::endpoint ep(ip::make_address_v4("127.0.0.1"), 1234); listener.open(ep.protocol()); listener.set_option(ip::tcp::acceptor::reuse_address(true)); listener.bind(ep);