Browse Source

quick fix for static example compilation for msvs

Stasik0 9 years ago
parent
commit
a22ee9b7a0
4 changed files with 68 additions and 8 deletions
  1. 53 1
      CMakeLists.txt
  2. 3 3
      appveyor.yml
  3. 8 4
      examples/client_firstSteps.c
  4. 4 0
      examples/server_firstSteps.c

+ 53 - 1
CMakeLists.txt

@@ -379,7 +379,59 @@ endif()
 
 option(BUILD_EXAMPLES "Build example servers and clients" OFF)
 if(BUILD_EXAMPLES)
-    add_subdirectory(examples)
+    #add_subdirectory(examples)
+    #FIXME: we had problem with static linking for msvs, here a quick and dirty workaround
+    #http://stackoverflow.com/questions/3704374/linking-error-lnk2019-in-msvc-unresolved-symbols-with-imp-prefix-but-shoul
+    #http://stackoverflow.com/questions/1089828/same-header-file-for-both-dll-and-static-library
+    if(NOT WIN32)
+		list(APPEND LIBS pthread)
+		if (NOT APPLE)
+		    list(APPEND LIBS rt)
+		endif()
+	else()
+		list(APPEND LIBS ws2_32)
+	endif()
+	if(ENABLE_MULTITHREADING)
+		list(APPEND LIBS urcu-cds urcu urcu-common)
+	endif(ENABLE_MULTITHREADING)
+
+    add_executable(server_variable ${PROJECT_SOURCE_DIR}/examples/server_variable.c $<TARGET_OBJECTS:open62541-object>)
+	target_link_libraries(server_variable ${LIBS})
+
+	add_executable(server_datasource ${PROJECT_SOURCE_DIR}/examples/server_datasource.c $<TARGET_OBJECTS:open62541-object>)
+	target_link_libraries(server_datasource ${LIBS})
+
+	add_executable(server_firstSteps ${PROJECT_SOURCE_DIR}/examples/server_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
+	target_link_libraries(server_firstSteps ${LIBS})
+
+	add_executable(client_firstSteps ${PROJECT_SOURCE_DIR}/examples/client_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
+	target_link_libraries(client_firstSteps ${LIBS})
+
+	add_executable(server_repeated_job ${PROJECT_SOURCE_DIR}/examples/server_repeated_job.c $<TARGET_OBJECTS:open62541-object>)
+	target_link_libraries(server_repeated_job ${LIBS})
+
+	if(NOT ENABLE_AMALGAMATION AND NOT MSVC)
+		add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
+				       PRE_BUILD
+				       COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml ${PROJECT_BINARY_DIR}/src_generated/nodeset
+				       DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
+				               ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
+				               ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
+				       
+		add_executable(server_nodeset ${PROJECT_SOURCE_DIR}/examples/server_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/nodeset.c $<TARGET_OBJECTS:open62541-object>)
+		target_link_libraries(server_nodeset ${LIBS})
+	endif()
+
+	if(ENABLE_METHODCALLS)
+	  add_executable(server_method ${PROJECT_SOURCE_DIR}/examples/server_method.c $<TARGET_OBJECTS:open62541-object>)
+	  target_link_libraries(server_method ${LIBS})
+	endif()
 endif()
 
 # build documentation

+ 3 - 3
appveyor.yml

@@ -7,14 +7,14 @@ build_script:
 - cd c:\projects\open62541
 - md build
 - cd build
-- cmake -DBUILD_EXAMPLESERVER:BOOL=ON -DBUILD_EXAMPLECLIENT:BOOL=ON -G"Visual Studio 12 2013" ..
+- cmake -DBUILD_EXAMPLESERVER:BOOL=ON -DBUILD_EXAMPLECLIENT:BOOL=ON -DBUILD_EXAMPLES:BOOL=ON -G"Visual Studio 12 2013" ..
 - msbuild open62541.sln
 - echo "Testing amalgamation"
 - cd ..
 - rd /s /q build
 - md build
 - cd build
-- cmake -DBUILD_EXAMPLESERVER:BOOL=ON -DBUILD_EXAMPLECLIENT:BOOL=ON -DENABLE_AMALGAMATION:BOOL=ON -G"Visual Studio 12 2013" ..
+- cmake -DBUILD_EXAMPLESERVER:BOOL=ON -DBUILD_EXAMPLECLIENT:BOOL=ON -DBUILD_EXAMPLES:BOOL=ON -DENABLE_AMALGAMATION:BOOL=ON -G"Visual Studio 12 2013" ..
 - msbuild open62541.sln 
 - cp C:\projects\open62541\build\open62541.c C:\projects\open62541\build\Debug\open62541.c
 - cp C:\projects\open62541\build\open62541.h C:\projects\open62541\build\Debug\open62541.h
@@ -22,7 +22,7 @@ build_script:
 - echo "Win 64 build"
 - md build64
 - cd build64
-- cmake -DBUILD_EXAMPLESERVER:BOOL=ON -DBUILD_EXAMPLECLIENT:BOOL=ON -DENABLE_AMALGAMATION:BOOL=ON -G"Visual Studio 12 2013 Win64" ..
+- cmake -DBUILD_EXAMPLESERVER:BOOL=ON -DBUILD_EXAMPLECLIENT:BOOL=ON -DBUILD_EXAMPLES:BOOL=ON -DENABLE_AMALGAMATION:BOOL=ON -G"Visual Studio 12 2013 Win64" ..
 - msbuild open62541.sln 
 - cp C:\projects\open62541\build64\open62541.c C:\projects\open62541\build64\Debug\open62541.c
 - cp C:\projects\open62541\build64\open62541.h C:\projects\open62541\build64\Debug\open62541.h

+ 8 - 4
examples/client_firstSteps.c

@@ -3,10 +3,14 @@
 
 #include <stdio.h>
 
-#include "ua_types.h"
-#include "ua_server.h"
-#include "logger_stdout.h"
-#include "networklayer_tcp.h"
+#ifdef UA_NO_AMALGAMATION
+# include "ua_types.h"
+# include "ua_server.h"
+# include "logger_stdout.h"
+# include "networklayer_tcp.h"
+#else
+# include "open62541.h"
+#endif
 
 int main(void) {
     UA_Client *client = UA_Client_new(UA_ClientConfig_standard, Logger_Stdout_new());

+ 4 - 0
examples/server_firstSteps.c

@@ -4,10 +4,14 @@
 #include <stdio.h>
 #include <signal.h>
 
+#ifdef UA_NO_AMALGAMATION
 # include "ua_types.h"
 # include "ua_server.h"
 # include "logger_stdout.h"
 # include "networklayer_tcp.h"
+#else
+# include "open62541.h"
+#endif
 
 UA_Boolean running;
 UA_Logger logger;