[freeopcua] add a new port (#5590)

* [freeopcua] new port

* [freeopcua] work-in-progress build on windows

* [freeopcua] fixes for windows
This commit is contained in:
Stefano Sinigardi 2019-03-08 00:28:49 +01:00 committed by Phil Christensen
parent a8502ca793
commit a675e048df
8 changed files with 516 additions and 0 deletions

4
ports/freeopcua/CONTROL Normal file
View File

@ -0,0 +1,4 @@
Source: freeopcua
Version: 20190125
Description: OPC-UA server and client library written in C++ and with a lot of code auto-generated from xml specification using python.
Build-Depends: boost-asio,boost-system,boost-program-options,boost-filesystem,boost-thread,boost-format,boost-foreach,boost-property-tree,boost-date-time

View File

@ -0,0 +1,204 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index de03564..2637355 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,8 @@ if( NOT CMAKE_BUILD_TYPE )
endif()
project(freeopcua)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(BUILD_CLIENT "Build Client" ON)
option(BUILD_SERVER "Build Server" ON)
@@ -16,28 +18,6 @@ option(BUILD_PYTHON "Build Python bindings" ON)
option(BUILD_TESTING "Build and run tests" OFF)
OPTION(BUILD_SHARED_LIBS "Build shared libraries." ON)
-IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
- SET(CMAKE_INSTALL_LIBDIR lib)
-ENDIF ()
-
-SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY
- ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
- CACHE PATH
- ""
- )
-
-SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY
- ${PROJECT_BINARY_DIR}/bin
- CACHE PATH
- ""
- )
-
-SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY
- ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
- CACHE PATH
- ""
- )
-
# Helper function to generate a pkg-config file for a single library
# Takes the filename of the .pc file as a parameter and replaces all
# placeholders in the .pc.in file with the actual values
@@ -60,23 +40,12 @@ function(generate_pkgconfig BASENAME)
endif()
endfunction(generate_pkgconfig)
if(MSVC)
- SET(STATIC_LIBRARY_CXX_FLAGS /MDd CACHE STRING "")
- SET(EXECUTABLE_CXX_FLAGS /MDd CACHE STRING "")
- SET(DYNAMIC_LIBRARY_CXX_FLAGS /MDd CACHE STRING "")
- SET(D /D)
-
- add_definitions(/D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_WIN32 /D_WINDOWS /FS /D_WIN32_WINNT=0x0600)
- add_compile_options(/Zi /Od /EHsc /W4)
-else(MSVC)
- set(CMAKE_CXX_FLAGS_DEBUG " -Wall -ggdb -o0 ${CMAKE_CXX_FLAGS_DEBUG}")
-
- SET(STATIC_LIBRARY_CXX_FLAGS)
- SET(EXECUTABLE_CXX_FLAGS)
- SET(DYNAMIC_LIBRARY_CXX_FLAGS)
- SET(D -D)
- set(CMAKE_CXX_FLAGS " -std=c++11 -Wall -fPIC ${CMAKE_CXX_FLAGS} ")
- SET (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS})
- #set(CMAKE_SHARED_LINKER_FLAGS "--no-undefined" )
+ add_definitions(-D_SCL_SECURE_NO_WARNINGS)
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+ add_definitions(-D_WIN32)
+ add_definitions(-D_WINDOWS)
+ add_definitions(-D_WIN32_WINNT=0x0600)
+ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
if(WIN32)
@@ -105,7 +74,7 @@ else(WIN32)
endif(WIN32)
-find_package( Boost COMPONENTS system program_options filesystem thread REQUIRED )
+find_package( Boost COMPONENTS system program_options filesystem thread date_time REQUIRED )
include_directories( ${Boost_INCLUDE_DIRS} )
link_directories( ${Boost_LIBRARY_DIRS} )
message(STATUS "Boost INCLUDE DIR IS: " ${Boost_INCLUDE_DIRS})
@@ -185,9 +154,6 @@ add_library(opcuaprotocol
src/protocol/subscriptions.cpp
)
-if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(opcuaprotocol PUBLIC ${STATIC_LIBRARY_CXX_FLAGS})
-endif ()
target_link_libraries(opcuaprotocol ${ADDITIONAL_LINK_LIBRARIES})
target_include_directories(opcuaprotocol PUBLIC $<INSTALL_INTERFACE:include>)
install(TARGETS opcuaprotocol EXPORT FreeOpcUa
@@ -227,10 +193,6 @@ if (BUILD_TESTING)
gtest_main
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(test_opcuaprotocol PUBLIC ${EXECUTABLE_CXX_FLAGS})
- endif ()
-
add_test(NAME opcuaprotocol COMMAND test_opcuaprotocol)
endif()
@@ -266,11 +228,7 @@ SET(opcuacore_SOURCES
add_library(opcuacore ${opcuacore_SOURCES})
-if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(opcuacore PUBLIC ${STATIC_LIBRARY_CXX_FLAGS})
-endif ()
-
-target_link_libraries(opcuacore ${ADDITIONAL_LINK_LIBRARIES} opcuaprotocol ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})
+target_link_libraries(opcuacore ${ADDITIONAL_LINK_LIBRARIES} opcuaprotocol ${Boost_LIBRARIES})
target_include_directories(opcuacore PUBLIC $<INSTALL_INTERFACE:include>)
install(TARGETS opcuacore EXPORT FreeOpcUa
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -306,7 +264,7 @@ if (BUILD_TESTING)
)
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(test_opcuacore PUBLIC ${D}DYNAMIC_ADDON_PATH="${DYNAMIC_ADDON_PATH}" ${D}TEST_CORE_CONFIG_PATH="${TEST_CORE_CONFIG_PATH}" ${EXECUTABLE_CXX_FLAGS})
+ target_compile_options(test_opcuacore PUBLIC ${D}DYNAMIC_ADDON_PATH="${DYNAMIC_ADDON_PATH}" ${D}TEST_CORE_CONFIG_PATH="${TEST_CORE_CONFIG_PATH}" )
endif ()
add_test(NAME opcuacore COMMAND test_opcuacore)
@@ -327,9 +285,6 @@ if (BUILD_CLIENT)
src/client/client.cpp
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(opcuaclient PUBLIC ${STATIC_LIBRARY_CXX_FLAGS})
- endif ()
target_link_libraries(opcuaclient
opcuacore
${ADDITIONAL_LINK_LIBRARIES}
@@ -371,9 +326,6 @@ if (BUILD_CLIENT)
opcuacore
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(opcuaclient PUBLIC ${EXECUTABLE_CXX_FLAGS})
- endif ()
endif(BUILD_CLIENT)
@@ -423,10 +375,7 @@ if(BUILD_SERVER)
src/server/subscription_service_internal.cpp
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(opcuaserver PUBLIC ${STATIC_LIBRARY_CXX_FLAGS})
- endif ()
- target_link_libraries(opcuaserver ${ADDITIONAL_LINK_LIBRARIES} opcuacore opcuaprotocol ${Boost_SYSTEM_LIBRARY})
+ target_link_libraries(opcuaserver ${ADDITIONAL_LINK_LIBRARIES} opcuacore opcuaprotocol ${Boost_LIBRARIES})
target_include_directories(opcuaserver PUBLIC $<INSTALL_INTERFACE:include>)
install(TARGETS opcuaserver EXPORT FreeOpcUa
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -481,7 +430,7 @@ if(BUILD_SERVER)
target_include_directories(test_opcuaserver PUBLIC .)
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(test_opcuaserver PUBLIC ${D}TEST_CORE_CONFIG_PATH="${TEST_CORE_CONFIG_PATH}" ${STATIC_LIBRARY_CXX_FLAGS})
+ target_compile_options(test_opcuaserver PUBLIC ${D}TEST_CORE_CONFIG_PATH="${TEST_CORE_CONFIG_PATH}")
endif ()
add_test(NAME opcuaserverapp COMMAND test_opcuaserver)
@@ -510,9 +459,6 @@ if(BUILD_SERVER)
opcuaserver
${Boost_PROGRAM_OPTIONS_LIBRARY}
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(opcuaserverapp PUBLIC ${EXECUTABLE_CXX_FLAGS})
- endif ()
endif(BUILD_SERVER)
@@ -533,9 +479,6 @@ if (BUILD_CLIENT)
${SSL_SUPPORT_LINK_LIBRARIES}
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(example_client PUBLIC ${EXECUTABLE_CXX_FLAGS})
- endif ()
endif (BUILD_CLIENT)
@@ -555,9 +498,6 @@ if(BUILD_SERVER)
opcuaserver
)
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_compile_options(example_server PUBLIC ${EXECUTABLE_CXX_FLAGS})
- endif ()
if(MSVC)
set_target_properties(example_server PROPERTIES LINK_FLAGS /STACK:3000000)
endif(MSVC)
@@ -572,7 +512,7 @@ if (BUILD_PYTHON)
add_subdirectory(python)
endif (BUILD_PYTHON)
-install(EXPORT FreeOpcUa DESTINATION lib/cmake/FreeOpcUa FILE FreeOpcUaConfig.cmake)
+install(EXPORT FreeOpcUa DESTINATION share/freeopcua FILE FreeOpcUaConfig.cmake)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "FreeOpcUa")

View File

@ -0,0 +1,54 @@
diff --git a/include/opc/ua/services/services.h b/include/opc/ua/services/services.h
index f138831..4732a59 100644
--- a/include/opc/ua/services/services.h
+++ b/include/opc/ua/services/services.h
@@ -26,20 +26,7 @@
#include <vector>
#include <boost/version.hpp>
-
-
-namespace boost
-{
-namespace asio
-{
-#if BOOST_VERSION < 106600
- class io_service;
-#else
- class io_context;
- typedef io_context io_service;
-#endif
-}
-}
+#include <boost/asio/io_service.hpp>
namespace OpcUa
{
diff --git a/src/server/internal_subscription.cpp b/src/server/internal_subscription.cpp
index edf4715..69ef74a 100644
--- a/src/server/internal_subscription.cpp
+++ b/src/server/internal_subscription.cpp
@@ -14,7 +14,7 @@ InternalSubscription::InternalSubscription(SubscriptionServiceInternal & service
, CurrentSession(SessionAuthenticationToken)
, Callback(callback)
, io(service.GetIOService())
- , Timer(io, boost::posix_time::milliseconds(data.RevisedPublishingInterval))
+ , Timer(io, boost::posix_time::milliseconds((int)data.RevisedPublishingInterval))
, LifeTimeCount(data.RevisedLifetimeCount)
, Logger(logger)
{
@@ -105,7 +105,7 @@ void InternalSubscription::PublishResults(const boost::system::error_code & erro
}
TimerStopped = false;
- Timer.expires_at(Timer.expires_at() + boost::posix_time::milliseconds(Data.RevisedPublishingInterval));
+ Timer.expires_at(Timer.expires_at() + boost::posix_time::milliseconds((int)Data.RevisedPublishingInterval));
std::shared_ptr<InternalSubscription> self = shared_from_this();
Timer.async_wait([self](const boost::system::error_code & error) { self->PublishResults(error); });
}
@@ -615,5 +615,3 @@ std::vector<Variant> InternalSubscription::GetEventFields(const EventFilter & fi
}
}
-
-

View File

@ -0,0 +1,138 @@
diff --git a/src/core/subscription.cpp b/src/core/subscription.cpp
index b690d3a..fdac2f3 100644
--- a/src/core/subscription.cpp
+++ b/src/core/subscription.cpp
@@ -17,11 +17,10 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
******************************************************************************/
-
-#include <opc/ua/subscription.h>
+#include <boost/asio.hpp>
#include <opc/ua/protocol/string_utils.h>
+#include <opc/ua/subscription.h>
-#include <boost/asio.hpp>
#include <iostream>
namespace OpcUa
diff --git a/src/server/asio_addon.cpp b/src/server/asio_addon.cpp
index 795a6b2..532ac3c 100644
--- a/src/server/asio_addon.cpp
+++ b/src/server/asio_addon.cpp
@@ -17,9 +17,9 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
******************************************************************************/
+#include <boost/asio.hpp>
#include <opc/ua/server/addons/asio_addon.h>
-#include <boost/asio.hpp>
#include <iostream>
#include <thread>
diff --git a/src/server/internal_subscription.h b/src/server/internal_subscription.h
index d42aa65..dd193a9 100644
--- a/src/server/internal_subscription.h
+++ b/src/server/internal_subscription.h
@@ -1,6 +1,7 @@
#pragma once
+#include <boost/asio.hpp>
//#include "address_space_internal.h"
#include "subscription_service_internal.h"
@@ -11,7 +12,6 @@
#include <opc/ua/protocol/string_utils.h>
#include <opc/ua/services/attributes.h>
-#include <boost/asio.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <chrono>
#include <iostream>
@@ -115,5 +115,3 @@ private:
}
}
-
-
diff --git a/src/server/opc_tcp_async.cpp b/src/server/opc_tcp_async.cpp
index dc700c2..f3a66b8 100644
--- a/src/server/opc_tcp_async.cpp
+++ b/src/server/opc_tcp_async.cpp
@@ -17,6 +17,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
******************************************************************************/
+#include <boost/asio.hpp>
#include "opc_tcp_processor.h"
#include <opc/ua/server/opc_tcp_async.h>
@@ -29,7 +30,6 @@
#include <opc/ua/protocol/input_from_buffer.h>
#include <array>
-#include <boost/asio.hpp>
#include <future>
#include <iostream>
#include <set>
diff --git a/src/server/subscription_service_internal.h b/src/server/subscription_service_internal.h
index 6b16e1d..f7e5dfe 100644
--- a/src/server/subscription_service_internal.h
+++ b/src/server/subscription_service_internal.h
@@ -9,6 +9,7 @@
#pragma once
+#include <boost/asio.hpp>
#include "address_space_addon.h"
#include "internal_subscription.h"
@@ -20,7 +21,6 @@
#include <opc/ua/protocol/strings.h>
#include <opc/ua/protocol/string_utils.h>
-#include <boost/asio.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <ctime>
#include <limits>
@@ -76,4 +76,3 @@ private:
}
}
-
diff --git a/src/server/tcp_server.cpp b/src/server/tcp_server.cpp
index b4f2000..2430820 100644
--- a/src/server/tcp_server.cpp
+++ b/src/server/tcp_server.cpp
@@ -8,9 +8,6 @@
/// http://www.gnu.org/licenses/lgpl.html)
///
-#ifdef _WIN32
-#include <windows.h>
-#endif
#include "tcp_server.h"
@@ -34,8 +31,18 @@
#include <string.h>
#include <sys/types.h>
-
#ifdef _WIN32
+#include <WinSock2.h>
+#include <windows.h>
+#if !defined SHUT_RD && defined SD_RECEIVE
+#define SHUT_RD SD_RECEIVE
+#endif
+#if !defined SHUT_WR && defined SD_SEND
+#define SHUT_WR SD_SEND
+#endif
+#if !defined SHUT_RDWR && defined SD_BOTH
+#define SHUT_RDWR SD_BOTH
+#endif
#else
#include <arpa/inet.h>
#include <netdb.h>

View File

@ -0,0 +1,35 @@
include(vcpkg_common_functions)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO FreeOpcUa/freeopcua
REF 2f2c886eb2da46b9dc8944c8f79ac31a9f116a81
SHA512 f19c1489eb116224ac3192e646c08cf3967c9a07064a09c4cbdef89d93e98c7541bb3edd030be22f6daf3f831ff92a324bc3734a8fe34cdd9d5a5ff7cb7f2f19
HEAD_REF master
PATCHES
cmakelists_fixes.patch
improve_compatibility_with_recent_boost.patch
use_another_implementation_of_has_begin_end.patch
uri_facade_win.patch
serverObj.patch
include_asio_first.patch
)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
-DBUILD_PYTHON=OFF
-DBUILD_TESTING=OFF
-DSSL_SUPPORT_MBEDTLS=OFF
)
vcpkg_install_cmake()
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/share/freeopcua/FreeOpcUaConfig-debug.cmake ${CURRENT_PACKAGES_DIR}/share/freeopcua/FreeOpcUaConfig-debug.cmake)
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/share/freeopcua/FreeOpcUaConfig.cmake ${CURRENT_PACKAGES_DIR}/share/freeopcua/FreeOpcUaConfig.cmake)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
#Handle copyright
file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/freeopcua RENAME copyright)

View File

@ -0,0 +1,14 @@
diff --git a/src/server/server_object.cpp b/src/server/server_object.cpp
index f35b168..b6c816a 100644
--- a/src/server/server_object.cpp
+++ b/src/server/server_object.cpp
@@ -25,9 +25,6 @@
#include <functional>
#include <iostream>
-#ifdef WIN32
-#undef GetObject
-#endif
namespace
{

View File

@ -0,0 +1,28 @@
diff --git a/src/core/common/uri_facade_win.cpp b/src/core/common/uri_facade_win.cpp
index 1a807fb..c579e2d 100644
--- a/src/core/common/uri_facade_win.cpp
+++ b/src/core/common/uri_facade_win.cpp
@@ -19,7 +19,7 @@
namespace Common
{
-void Uri::Initialize(const char * uriString, std::size_t size)
+void Uri::Initialize(const std::string& uriString)
{
URL_COMPONENTS url = {0};
url.dwStructSize = sizeof(url);
@@ -31,7 +31,7 @@ void Uri::Initialize(const char * uriString, std::size_t size)
// TODO msdn says do not use this function in services and in server patforms. :(
// TODO http://msdn.microsoft.com/en-us/library/windows/desktop/aa384376(v=vs.85).aspx
- if (!InternetCrackUrl(uriString, size, options, &url))
+ if (!InternetCrackUrl(uriString.c_str(), uriString.size(), options, &url))
{
THROW_ERROR1(CannotParseUri, uriString);
}
@@ -50,5 +50,3 @@ void Uri::Initialize(const char * uriString, std::size_t size)
}
} // namespace Common
-
-

View File

@ -0,0 +1,39 @@
diff --git a/include/opc/ua/protocol/variant.h b/include/opc/ua/protocol/variant.h
index 9dc5b15..317cb17 100644
--- a/include/opc/ua/protocol/variant.h
+++ b/include/opc/ua/protocol/variant.h
@@ -76,22 +76,25 @@ public:
template <typename T>
struct has_begin_end
{
- template<typename C> static char (&f(typename std::enable_if <
- std::is_same<decltype(static_cast<typename C::const_iterator(C::*)() const>(&C::begin)),
- typename C::const_iterator(C::*)() const>::value, void >::type *))[1];
+ struct Dummy { typedef void const_iterator; };
+ typedef typename std::conditional<has_const_iterator<T>::value, T, Dummy>::type TType;
+ typedef typename TType::const_iterator iter;
- template<typename C> static char (&f(...))[2];
+ struct Fallback { iter begin() const; iter end() const; };
+ struct Derived : TType, Fallback { };
- template<typename C> static char (&g(typename std::enable_if <
- std::is_same<decltype(static_cast<typename C::const_iterator(C::*)() const>(&C::end)),
- typename C::const_iterator(C::*)() const>::value, void >::type *))[1];
+ template<typename C, C> struct ChT;
+ template<typename C> static char (&f(ChT<iter (Fallback::*)() const, &C::begin>*))[1];
+ template<typename C> static char (&f(...))[2];
+ template<typename C> static char (&g(ChT<iter (Fallback::*)() const, &C::end>*))[1];
template<typename C> static char (&g(...))[2];
- static bool const beg_value = sizeof(f<T>(0)) == 1;
- static bool const end_value = sizeof(g<T>(0)) == 1;
+ static bool const beg_value = sizeof(f<Derived>(0)) == 2;
+ static bool const end_value = sizeof(g<Derived>(0)) == 2;
};
+
template<typename T>
struct is_container_not_string : std::integral_constant < bool, has_const_iterator<T>::value && has_begin_end<T>::beg_value && has_begin_end<T>::end_value >
{ };