Julius Pfrommer 10 роки тому
батько
коміт
8861cc0679

+ 4 - 4
.travis.yml

@@ -33,19 +33,19 @@ script:
 - mkdir -p build
 - cd build
 - echo "Cross compile release build for MinGW"
-- cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw32.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON -DBUILD_AMALGAMATION=ON ..
+- cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw32.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON ..
 - make -j
 - zip open62541-win32.zip ../README.md exampleServer_datasource.exe libopen62541.dll open62541.h open62541.c
 - cp open62541-win32.zip ..
 - cd .. && rm build -rf && mkdir -p build && cd build
 - echo "Cross compile release build for 32-bit linux"
-- cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-gcc-m32.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON -DBUILD_AMALGAMATION=ON ..
+- cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-gcc-m32.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON ..
 - make -j
 - tar -pczf open62541-linux32.tar.gz ../README.md exampleServer_datasource libopen62541.so open62541.h open62541.c
 - cp open62541-linux32.tar.gz ..
 - cd .. && rm build -rf && mkdir -p build && cd build
 - echo "Compile release build for 64-bit linux"
-- cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON -DBUILD_AMALGAMATION=ON ..
+- cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON ..
 - make -j
 - tar -pczf open62541-linux64.tar.gz ../README.md exampleServer_datasource libopen62541.so open62541.h open62541.c
 - cp open62541-linux64.tar.gz ..
@@ -81,7 +81,7 @@ before_deploy:
 - git clone https://github.com/raspberrypi/tools
 - cd -
 - export PATH=$PATH:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
-- cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-rpi64.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON -DBUILD_AMALGAMATION=ON..
+- cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-rpi64.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLESERVER=ON ..
 - make -j
 - tar -pczf open62541-raspberrypi.tar.gz ../README.md exampleServer_datasource libopen62541.so open62541.h open62541.c
 - cp open62541-raspberrypi.tar.gz ..

+ 31 - 43
CMakeLists.txt

@@ -21,7 +21,7 @@ endif()
 if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
 add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat
                 -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare -Wmultichar
-                -Wshadow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes # -Wconversion
+                -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes # -Wconversion -Wshadow 
                 -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -ffunction-sections -fdata-sections)
     if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
         add_definitions(-Wformat-nonliteral)
@@ -99,15 +99,21 @@ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
                            ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
 
+## 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})
+
 ## logging
 set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
 
-## set the precompiler flags
-configure_file("src/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
-
 ## multithreading
-option(MULTITHREADING "Enable multithreading" OFF)
-if(MULTITHREADING)
+option(ENABLE_MULTITHREADING "Enable multithreading" OFF)
+if(ENABLE_MULTITHREADING)
     set(UA_MULTITHREADING ON)
     find_package(Threads REQUIRED)
     list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c)
@@ -115,14 +121,8 @@ else()
     list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c)
 endif()
 
-## 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
-                                  ${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_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
+## set the precompiler flags
+configure_file("src/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
 
 ## extensions
 option(EXTENSION_UDP "Enable udp extension" OFF)
@@ -138,26 +138,19 @@ if(EXTENSION_STATELESS)
 	add_definitions(-DEXTENSION_STATELESS)
 endif()
 
-option(DEMO_NODESET "Create a demo node for every built-in datatype" OFF)
-if(DEMO_NODESET)
+option(BUILD_DEMO_NODESET "Create a demo node for every built-in datatype" OFF)
+if(BUILD_DEMO_NODESET)
 	message(STATUS "Enabling demo nodeset")
 	add_definitions(-DDEMO_NODESET)
 endif()
 
-option(BUILD_AMALGAMATION "Build the single-file distribution" ON)
-if(BUILD_AMALGAMATION)
-    add_custom_target(open62541-amalgamation DEPENDS ${PROJECT_BINARY_DIR}/open62541.h ${PROJECT_BINARY_DIR}/open62541.c)
-endif()
-
-option(BUILD_LIBRARY "Build a shared library (.so/.dll)" ON)
-if(BUILD_LIBRARY)
-    add_library(open62541 SHARED ${lib_sources} ${exported_headers} ${internal_headers}) 
-    target_include_directories(open62541 PRIVATE ${PROJECT_SOURCE_DIR}/include)
-    target_include_directories(open62541 PRIVATE ${PROJECT_SOURCE_DIR}/deps)
-    target_include_directories(open62541 PRIVATE ${PROJECT_SOURCE_DIR}/src)
-    target_include_directories(open62541 PRIVATE ${PROJECT_BINARY_DIR}/src_generated)
-    target_compile_definitions(open62541 PRIVATE UA_DYNAMIC_LINKING)
-endif()
+# add_library(open62541-object OBJECT ${lib_sources})
+# include_directories(${PROJECT_SOURCE_DIR}/include)
+# include_directories(${PROJECT_SOURCE_DIR}/deps)
+# include_directories(${PROJECT_SOURCE_DIR}/src)
+# include_directories(${PROJECT_BINARY_DIR}/src_generated)
+add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c)
+add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
 
 # build language bindings for the library
 option(ENABLE_BINDING_LUA "Build Lua bindings" OFF)
@@ -179,8 +172,8 @@ endif()
 # build example server
 option(BUILD_EXAMPLESERVER "Build the example server" OFF)
 if(BUILD_EXAMPLESERVER)
-    add_executable(exampleServer examples/server.c ${PROJECT_BINARY_DIR}/open62541.c examples/networklayer_tcp.c examples/logger_stdout.c)
-    add_executable(exampleServer_datasource examples/server_datasource.c ${PROJECT_BINARY_DIR}/open62541.c examples/networklayer_tcp.c examples/logger_stdout.c)
+    add_executable(exampleServer examples/server.c $<TARGET_OBJECTS:open62541-object> examples/networklayer_tcp.c examples/logger_stdout.c)
+    add_executable(exampleServer_datasource examples/server_datasource.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_datasource PRIVATE ${PROJECT_BINARY_DIR})
     if(WIN32)
@@ -190,7 +183,7 @@ if(BUILD_EXAMPLESERVER)
         target_link_libraries(exampleServer rt)
         target_link_libraries(exampleServer_datasource rt)
     endif()
-    if(MULTITHREADING)
+    if(ENABLE_MULTITHREADING)
         target_link_libraries(exampleServer urcu-cds urcu urcu-common pthread)
         target_link_libraries(exampleServer_datasource urcu-cds urcu urcu-common pthread)
     endif()
@@ -219,18 +212,16 @@ if(BUILD_EXAMPLECLIENT)
 	add_definitions( -DBENCHMARK=1 )
 	add_executable(exampleClient ${PROJECT_BINARY_DIR}/open62541.c examples/client.c)
     target_include_directories(exampleClient PRIVATE ${PROJECT_BINARY_DIR})
-    if(MULTITHREADING)
+    if(ENABLE_MULTITHREADING)
         target_link_libraries(exampleClient 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 exampleClient POST_BUILD
-    		COMMAND ${CMAKE_STRIP} $<TARGET_FILE:exampleClient>
-		)
+    	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})
-        if(MULTITHREADING)
+        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"))
@@ -242,16 +233,13 @@ endif()
 # build unit tests
 option(BUILD_UNIT_TESTS "Run unit tests after building" OFF)
 if(BUILD_UNIT_TESTS)
-    if(NOT BUILD_LIBRARY)
-        message(SEND_ERROR "Can't build unit tests without building the library")
-    endif()
     enable_testing()
     add_subdirectory(tests)
 endif()
 
 # build documentation
-option(GENERATE_DOCUMENTATION "Generate doxygen documentation" OFF)
-if(GENERATE_DOCUMENTATION)
+option(BUILD_DOCUMENTATION "Generate doxygen documentation" OFF)
+if(BUILD_DOCUMENTATION)
     find_package(Doxygen)
         if(NOT DOXYGEN_FOUND)
             message(FATAL_ERROR "Doxygen is not installed or not properly configured")

+ 1 - 7
src/server/ua_nodestore_concurrent.c

@@ -1,11 +1,5 @@
-#define _LGPL_SOURCE
-#include <urcu.h>
-#include <urcu/compiler.h> // for caa_container_of
-#include <urcu/uatomic.h>
-#include <urcu/rculfhash.h>
-
-#include "ua_nodestore.h"
 #include "ua_util.h"
+#include "ua_nodestore.h"
 
 #define ALIVE_BIT (1 << 15) /* Alive bit in the refcount */
 

+ 1 - 2
src/server/ua_server_internal.h

@@ -1,8 +1,7 @@
 #ifndef UA_SERVER_INTERNAL_H_
 #define UA_SERVER_INTERNAL_H_
 
-#include "ua_config.h"
-
+#include "ua_util.h"
 #include "ua_server.h"
 #include "ua_session_manager.h"
 #include "ua_securechannel_manager.h"

+ 1 - 0
src/server/ua_server_worker.c

@@ -1,3 +1,4 @@
+#include "ua_util.h"
 #include "ua_server_internal.h"
 
 /**

+ 5 - 0
src/ua_config.h.in

@@ -1,3 +1,6 @@
+#ifndef UA_CONFIG_H_
+#define UA_CONFIG_H_
+
 /* Buid options and configuration (set by cmake) */
 
 #define UA_LOGLEVEL ${UA_LOGLEVEL}
@@ -25,3 +28,5 @@
 #    define UA_EXPORT
 #  endif
 #endif
+
+#endif /* UA_CONFIG_H_ */

+ 7 - 3
src/ua_util.h

@@ -10,6 +10,7 @@
 #endif
 #ifndef _POSIX_SOURCE
 # define _POSIX_SOURCE
+# define _POSIX_C_SOURCE 199309L
 #endif
 #ifndef _BSD_SOURCE
 # define _BSD_SOURCE
@@ -79,9 +80,12 @@
 #endif
 
 #ifdef UA_MULTITHREADING
-#define _LGPL_SOURCE
-#include <urcu.h>
-#include <urcu/wfcqueue.h>
+# define _LGPL_SOURCE
+# include <urcu.h>
+# include <urcu/wfcqueue.h>
+# include <urcu/compiler.h> // for caa_container_of
+# include <urcu/uatomic.h>
+# include <urcu/rculfhash.h>
 #endif
 
 #endif /* UA_UTIL_H_ */

+ 1 - 1
tools/amalgamate.py

@@ -64,7 +64,7 @@ else:
 # define UA_DYNAMIC_LINKING
 #endif\n\n''')
     for fname in args.inputs:
-        if "util.h" in fname:
+        if "ua_config.h" in fname or "ua_util.h" in fname:
             with open(fname) as infile:
                 for line in infile:
                     file.write(line)