Переглянути джерело

add the network layer and logger to the single-source distribution

Julius Pfrommer 10 роки тому
батько
коміт
0684df3dad

+ 31 - 47
CMakeLists.txt

@@ -29,12 +29,16 @@ add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat
         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
     else()
         add_definitions(-Wno-gnu-statement-expression)
+    endif()
+    if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s") # Strip binary
     endif()
 	if(NOT WIN32)
 	    add_definitions(-fstack-protector -fPIC -fvisibility=hidden)
 	endif()
 endif()
 
+
 # build the main library
 set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
                      ${PROJECT_SOURCE_DIR}/include/ua_statuscodes.h
@@ -138,19 +142,21 @@ if(BUILD_DEMO_NODESET)
 	add_definitions(-DDEMO_NODESET)
 endif()
 
-if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
-	set(AMALGATED ON)
-    ## build amalgamated source files
-    add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h ${PROJECT_BINARY_DIR}/open62541.c
-                   PRE_BUILD
-                   COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
-                   COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
-                                  ${PROJECT_BINARY_DIR}/src_generated/ua_config.h ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources}
-                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${exported_headers} ${internal_headers}
-                           ${PROJECT_BINARY_DIR}/src_generated/ua_config.h ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
-
+option(ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
+add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h ${PROJECT_BINARY_DIR}/open62541.c
+               PRE_BUILD
+               COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
+                                                                              ${PROJECT_SOURCE_DIR}/examples/networklayer_tcp.h
+                                                                              ${PROJECT_SOURCE_DIR}/examples/logger_stdout.h
+               COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
+                              ${PROJECT_BINARY_DIR}/src_generated/ua_config.h ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources}
+                                                                              ${PROJECT_SOURCE_DIR}/examples/networklayer_tcp.c
+                                                                              ${PROJECT_SOURCE_DIR}/examples/logger_stdout.c
+               DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${exported_headers} ${internal_headers}
+                       ${PROJECT_BINARY_DIR}/src_generated/ua_config.h ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
+if(ENABLE_AMALGAMATION)
     add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c)
-    add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
+    include_directories(${PROJECT_BINARY_DIR})
 else()
     add_definitions(-DNOT_AMALGATED)
     add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
@@ -159,7 +165,7 @@ else()
     include_directories(${PROJECT_SOURCE_DIR}/src)
     include_directories(${PROJECT_BINARY_DIR}/src_generated)
 endif()
-
+add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
 
 # build language bindings for the library
 option(ENABLE_BINDING_LUA "Build Lua bindings" OFF)
@@ -181,10 +187,12 @@ endif()
 # build example server
 option(BUILD_EXAMPLESERVER "Build the example server" OFF)
 if(BUILD_EXAMPLESERVER)
-    add_executable(exampleServer examples/server.c $<TARGET_OBJECTS:open62541-object> examples/networklayer_tcp.c examples/logger_stdout.c)
-    add_executable(exampleServer_simple examples/server_simple.c $<TARGET_OBJECTS:open62541-object> examples/networklayer_tcp.c examples/logger_stdout.c)
-    target_include_directories(exampleServer PRIVATE ${PROJECT_BINARY_DIR})
-    target_include_directories(exampleServer_simple PRIVATE ${PROJECT_BINARY_DIR})
+    set(server_source $<TARGET_OBJECTS:open62541-object>)
+    if(NOT ENABLE_AMALGAMATION)
+        list(APPEND server_source examples/networklayer_tcp.c examples/logger_stdout.c)
+    endif()
+    add_executable(exampleServer examples/server.c ${server_source})
+    add_executable(exampleServer_simple examples/server_simple.c ${server_source})
     if(WIN32)
         target_link_libraries(exampleServer ws2_32)
         target_link_libraries(exampleServer_simple ws2_32)
@@ -196,10 +204,6 @@ if(BUILD_EXAMPLESERVER)
         target_link_libraries(exampleServer urcu-cds urcu urcu-common pthread)
         target_link_libraries(exampleServer_simple urcu-cds urcu urcu-common pthread)
     endif()
-    if((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
-    	add_custom_command(TARGET exampleServer POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleServer>)
-		add_custom_command(TARGET exampleServer_simple POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleServer_simple>)
-	endif()
 endif()
 
 ## self-signed certificates
@@ -217,42 +221,22 @@ endif()
 # build example client
 option(BUILD_EXAMPLECLIENT "Build a test client" OFF)
 if(BUILD_EXAMPLECLIENT)
-	message(STATUS "Extensions: enabling client")
-	add_definitions( -DBENCHMARK=1 )
-	if(NOT AMALGATED)
-		add_executable(exampleClient_legacy $<TARGET_OBJECTS:open62541-object> examples/client_legacy.c)
-	endif()
-	add_executable(exampleClient $<TARGET_OBJECTS:open62541-object> examples/client.c examples/networklayer_tcp.c)
-    if(NOT AMALGATED)
-    	target_include_directories(exampleClient_legacy PRIVATE ${PROJECT_BINARY_DIR})
+	add_definitions(-DBENCHMARK)
+    set(client_source $<TARGET_OBJECTS:open62541-object>)
+    if(NOT ENABLE_AMALGAMATION)
+        list(APPEND client_source examples/networklayer_tcp.c examples/logger_stdout.c)
     endif()
-    target_include_directories(exampleClient PRIVATE ${PROJECT_BINARY_DIR})
+	add_executable(exampleClient examples/client.c ${client_source})
     if(WIN32)
-    	if(NOT AMALGATED)
-        	target_link_libraries(exampleClient_legacy ws2_32)
-        endif()
         target_link_libraries(exampleClient ws2_32)
     else()
-   		if(NOT AMALGATED)
-        	target_link_libraries(exampleClient_legacy rt)
-        endif()
         target_link_libraries(exampleClient rt)
     endif()
-    if ((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
-       if(NOT AMALGATED)
-       		add_custom_command(TARGET exampleClient_legacy POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleClient_legacy>)
-	   endif()
-	   add_custom_command(TARGET exampleClient POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleClient>)
-	endif()
     if(EXTENSION_STATELESS)
-        add_executable(statelessClient ${PROJECT_BINARY_DIR}/open62541.c examples/client_stateless.c)
-        target_include_directories(statelessClient PRIVATE ${PROJECT_BINARY_DIR})
+        add_executable(statelessClient examples/client_stateless.c ${client_source})
         if(ENABLE_MULTITHREADING)
             target_link_libraries(statelessClient urcu-cds urcu urcu-common pthread)
         endif()
-        if ((CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
-    	add_custom_command(TARGET statelessClient POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:statelessClient>)
-		endif()
     endif()
 endif()
 

Різницю між файлами не показано, бо вона завелика
+ 5 - 12
README.md


+ 2 - 3
examples/client_stateless.c

@@ -1,5 +1,5 @@
 /*
-	C ECHO client example using sockets
+ * C ECHO client example using sockets
  */
 #include <stdio.h>	//printf
 #include <string.h>	//strlen
@@ -8,10 +8,9 @@
 #include <unistd.h> // for close
 #include <stdlib.h> // pulls in declaration of malloc, free
 
-#include "ua_transport_generated.h"
 #include "ua_util.h"
 #include "ua_types_encoding_binary.h"
-
+#include "ua_transport_generated.h"
 
 int main(int argc , char *argv[])
 {

+ 24 - 24
examples/networklayer_tcp.c

@@ -2,40 +2,40 @@
  * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  */
+
+/* amalgamation removes these includes */
 #define _XOPEN_SOURCE 500 //some users need this for some reason
 #define __USE_BSD
 #include <stdlib.h> // malloc, free
-#ifdef _WIN32
-#include <malloc.h>
-#include <winsock2.h>
-#include <sys/types.h>
-#include <windows.h>
-#include <ws2tcpip.h>
-#define CLOSESOCKET(S) closesocket(S)
-#else
-#include <sys/select.h> 
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <sys/socketvar.h>
-#include <sys/ioctl.h>
-#include <netdb.h> //gethostbyname for the client
-#include <unistd.h> // read, write, close
-#include <arpa/inet.h>
-#define CLOSESOCKET(S) close(S)
-#endif
-
 #include <stdio.h>
-#include <errno.h> // errno, EINTR
-#include <fcntl.h> // fcntl
 #include <string.h> // memset
-
 #include "networklayer_tcp.h" // UA_MULTITHREADING is defined in here
-
 #ifdef UA_MULTITHREADING
-#include <urcu/uatomic.h>
+# include <urcu/uatomic.h>
 #endif
 
+/* with a space so amalgamation does not remove the includes */
+# include <errno.h> // errno, EINTR
+# include <fcntl.h> // fcntl
 
+#ifdef _WIN32
+# include <malloc.h>
+# include <winsock2.h>
+# include <sys/types.h>
+# include <windows.h>
+# include <ws2tcpip.h>
+# define CLOSESOCKET(S) closesocket(S)
+#else
+# include <sys/select.h> 
+# include <netinet/in.h>
+# include <netinet/tcp.h>
+# include <sys/socketvar.h>
+# include <sys/ioctl.h>
+# include <netdb.h> //gethostbyname for the client
+# include <unistd.h> // read, write, close
+# include <arpa/inet.h>
+# define CLOSESOCKET(S) close(S)
+#endif
 
 struct ServerNetworklayer_TCP;
 

+ 4 - 4
examples/networklayer_tcp.h

@@ -11,10 +11,10 @@ extern "C" {
 #endif
 
 #ifdef NOT_AMALGATED
-    #include "ua_server.h"
-	#include "ua_client.h"
+#include "ua_server.h"
+#include "ua_client.h"
 #else
-    #include "open62541.h"
+#include "open62541.h"
 #endif
 
 /** @brief Create the TCP networklayer and listen to the specified port */
@@ -25,4 +25,4 @@ UA_ClientNetworkLayer ClientNetworkLayerTCP_new(UA_ConnectionConfig conf);
 } // extern "C"
 #endif
 
-#endif /* NETWORKLAYERTCP_H_ */
+#endif /* NETWORKLAYERTCP_H_ */

+ 27 - 23
examples/networklayer_udp.c

@@ -3,33 +3,37 @@
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  */
 
+#define _XOPEN_SOURCE 500 //some users need this for some reason
+#define __USE_BSD
 #include <stdlib.h> // malloc, free
-#ifdef _WIN32
-#include <malloc.h>
-#include <winsock2.h>
-#include <sys/types.h>
-#include <windows.h>
-#include <ws2tcpip.h>
-#define CLOSESOCKET(S) closesocket(S)
-#else
-#include <strings.h> //bzero
-#include <sys/select.h> 
-#include <netinet/in.h>
-#include <sys/socketvar.h>
-#include <sys/ioctl.h>
-#include <unistd.h> // read, write, close
-#include <arpa/inet.h>
-#define CLOSESOCKET(S) close(S)
-#endif
-
 #include <stdio.h>
-#include <errno.h> // errno, EINTR
-#include <fcntl.h> // fcntl
+#include <string.h> // memset
+#include "networklayer_udp.h"
+#ifdef UA_MULTITHREADING
+# include <urcu/uatomic.h>
+#endif
 
-#include "networklayer_udp.h" // UA_MULTITHREADING is defined in here
+/* with a space so amalgamation does not remove the includes */
+# include <errno.h> // errno, EINTR
+# include <fcntl.h> // fcntl
 
-#ifdef UA_MULTITHREADING
-#include <urcu/uatomic.h>
+#ifdef _WIN32
+# include <malloc.h>
+# include <winsock2.h>
+# include <sys/types.h>
+# include <windows.h>
+# include <ws2tcpip.h>
+# define CLOSESOCKET(S) closesocket(S)
+#else
+# include <strings.h> //bzero
+# include <sys/select.h> 
+# include <netinet/in.h>
+# include <netinet/tcp.h>
+# include <sys/socketvar.h>
+# include <sys/ioctl.h>
+# include <unistd.h> // read, write, close
+# include <arpa/inet.h>
+# define CLOSESOCKET(S) close(S)
 #endif
 
 #define MAXBACKLOG 100

+ 3 - 3
examples/networklayer_udp.h

@@ -11,9 +11,9 @@ extern "C" {
 #endif
 
 #ifdef NOT_AMALGATED
-    #include "ua_server.h"
+# include "ua_server.h"
 #else
-    #include "open62541.h"
+# include "open62541.h"
 #endif
 
 /** @brief Create the UDP networklayer and listen to the specified port */
@@ -23,4 +23,4 @@ UA_ServerNetworkLayer ServerNetworkLayerUDP_new(UA_ConnectionConfig conf, UA_UIn
 } // extern "C"
 #endif
 
-#endif /* NETWORKLAYERUDP_H_ */
+#endif /* NETWORKLAYERUDP_H_ */

+ 11 - 12
examples/server.c

@@ -2,25 +2,24 @@
  * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  */
-#ifdef NOT_AMALGATED
-    #include "ua_types.h"
-    #include "ua_server.h"
-#else
-    #include "open62541.h"
-#endif
 
-#include <time.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h> 
-#include <signal.h>
 #define __USE_XOPEN2K
 #ifdef UA_MULTITHREADING
-#include <pthread.h>
+# include <pthread.h>
 #endif
 
-// provided by the user, implementations available in the /examples folder
-#include "logger_stdout.h"
-#include "networklayer_tcp.h"
+#ifdef NOT_AMALGATED
+# include <time.h>
+# include "ua_types.h"
+# include "ua_server.h"
+# include "logger_stdout.h"
+# include "networklayer_tcp.h"
+#else
+# include "open62541.h"
+#endif
 
 /****************************/
 /* Server-related variables */

+ 5 - 4
tests/CMakeLists.txt

@@ -54,10 +54,11 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
                    DEPENDS ${PROJECT_SOURCE_DIR}/tools/hex2bin.py
                            ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_HELOPN.hex)
 
-add_executable(check_server_interaction_fileinput check_server_interaction_fileinput.c
-                                                  testing_networklayers.c
-                                                  ${PROJECT_SOURCE_DIR}/examples/logger_stdout.c
-                                                  $<TARGET_OBJECTS:open62541-object>)
+set(check_fileinput_source check_server_interaction_fileinput.c testing_networklayers.c $<TARGET_OBJECTS:open62541-object>)
+if(NOT ENABLE_AMALGAMATION)
+    list(APPEND check_fileinput_source ${PROJECT_SOURCE_DIR}/examples/logger_stdout.c)
+endif()
+add_executable(check_server_interaction_fileinput ${check_fileinput_source})
 
 target_include_directories(check_server_interaction_fileinput PRIVATE ${PROJECT_SOURCE_DIR}/examples)
 target_include_directories(check_server_interaction_fileinput PRIVATE ${PROJECT_BINARY_DIR})

+ 15 - 20
tools/.deployDoxygen.sh

@@ -1,27 +1,22 @@
 #!/bin/bash
 
 #
-# This sciprt is run by travis-ci and pushes generated
+# This script is run by travis-ci and pushes generated
 # Doxygen docs to open62541-www
 #
 
 git fetch origin coverity_scan
-COMMITS=`git log --oneline --since=today.midnight | wc -l`
-if [[ "$COMMITS" -le "1" ]]; then
-   git clone --depth=50 -b gh-pages https://$GITAUTH@github.com/acplt/open62541-www
-   cd open62541-www
-   git rm -rf doc
-   cp -r ../build/doc ./
-   git add -A doc/*
-   cp ../build/open62541.* ./
-   git add open62541.*
-   git config --global user.email "open62541-travis-ci@users.noreply.github.com"
-   git config --global user.name "Open62541 travis-ci"
-   git config --global push.default simple
-   git commit -am "doxygen updated by travis-ci"
-   git push https://$GITAUTH@github.com/acplt/open62541-www
-   cd ..
-   rm -rf open62541-www
-else
-    echo "Not the first commit of the day - no doxygen update required"
-fi
+git clone --depth=5 -b gh-pages https://$GITAUTH@github.com/acplt/open62541-www
+cd open62541-www
+git rm -rf doc
+cp -r ../build/doc ./
+git add -A doc/*
+cp ../build/open62541.* ./
+git add open62541.*
+git config --global user.email "open62541-travis-ci@users.noreply.github.com"
+git config --global user.name "Open62541 travis-ci"
+git config --global push.default simple
+git commit -am "doxygen updated by travis-ci"
+git push https://$GITAUTH@github.com/acplt/open62541-www
+cd ..
+rm -rf open62541-www