Browse Source

simplify cmake; make server_readspeed a unit test

Julius Pfrommer 7 years ago
parent
commit
d05087639f
5 changed files with 57 additions and 83 deletions
  1. 25 10
      CMakeLists.txt
  2. 21 55
      examples/CMakeLists.txt
  3. 8 15
      tests/CMakeLists.txt
  4. 0 0
      tests/check_server_readspeed.c
  5. 3 3
      tools/travis/travis_osx_script.sh

+ 25 - 10
CMakeLists.txt

@@ -27,9 +27,9 @@ if(NOT ${OPEN62541_VER_COMMIT} OR ${OPEN62541_VER_COMMIT} STREQUAL "")
     set(OPEN62541_VER_COMMIT "undefined")
 endif()
 
-############
-# Settings #
-############
+#################
+# Build Options #
+#################
 
 # Set default build type.
 if(NOT CMAKE_BUILD_TYPE)
@@ -107,7 +107,19 @@ mark_as_advanced(UA_COMPILE_AS_CXX)
 # Compiler Settings #
 #####################
 
-list(APPEND open62541_LIBRARIES "") # Collect libraries
+# Collect libraries
+list(APPEND open62541_LIBRARIES "")
+if(NOT WIN32)
+  list(APPEND open62541_LIBRARIES pthread)
+  if (NOT APPLE)
+    list(APPEND open62541_LIBRARIES rt)
+  endif()
+else()
+  list(APPEND open62541_LIBRARIES ws2_32)
+endif()
+if(UA_ENABLE_MULTITHREADING)
+  list(APPEND open62541_LIBRARIES urcu-cds urcu urcu-common)
+endif(UA_ENABLE_MULTITHREADING)
 
 if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
     # Compiler
@@ -375,8 +387,8 @@ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJEC
 #####################
 
 if(UA_ENABLE_AMALGAMATION)
+    include_directories(${PROJECT_BINARY_DIR}) # contains open62541.h
     add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
-    target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
     add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
 
     if(UA_COMPILE_AS_CXX)
@@ -390,6 +402,7 @@ else()
     add_library(open62541-plugins OBJECT ${default_plugin_sources} ${exported_headers})
     target_include_directories(open62541-plugins PRIVATE ${PROJECT_SOURCE_DIR}/plugins)
     target_include_directories(open62541-plugins PRIVATE ${PROJECT_BINARY_DIR}/src_generated)
+    target_compile_definitions(open62541-plugins PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
 
     add_library(open62541 $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
 
@@ -398,18 +411,20 @@ else()
         set_source_files_properties(${default_plugin_sources} PROPERTIES LANGUAGE CXX)
     endif()
 endif()
-target_link_libraries(open62541 ${open62541_LIBRARIES})
 
+# Export Symbols
 target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
 target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
 
+# DLL requires linking to dependencies
+target_link_libraries(open62541 ${open62541_LIBRARIES})
+
+# Always generate the amalgamated header
+add_dependencies(open62541 open625451_amalgamation)
+
 # Generate properly versioned shared library links on Linux
 SET_TARGET_PROPERTIES(open62541 PROPERTIES SOVERSION 0 VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")
 
-if(WIN32)
-    target_link_libraries(open62541 ws2_32)
-endif()
-
 ##########################
 # Build Selected Targets #
 ##########################

+ 21 - 55
examples/CMakeLists.txt

@@ -1,74 +1,47 @@
-include_directories(${PROJECT_SOURCE_DIR}/include)
-include_directories(${PROJECT_SOURCE_DIR}/plugins)
-include_directories(${PROJECT_BINARY_DIR})
-
-if(UA_ENABLE_AMALGAMATION)
-    include_directories(${PROJECT_BINARY_DIR}) # contains open62541.h
-else()
-    add_definitions(-DUA_NO_AMALGAMATION)
-endif()
-
-list(APPEND LIBS open62541 ${open62541_LIBRARIES})
-if(NOT WIN32)
-  list(APPEND LIBS pthread)
-  if (NOT APPLE)
-    list(APPEND LIBS rt)
-  endif()
-else()
-  list(APPEND LIBS ws2_32)
-endif()
-if(UA_ENABLE_MULTITHREADING)
-  list(APPEND LIBS urcu-cds urcu urcu-common)
-endif(UA_ENABLE_MULTITHREADING)
+include_directories(${PROJECT_BINARY_DIR}
+                    ${PROJECT_BINARY_DIR}/src_generated
+                    ${PROJECT_SOURCE_DIR}/plugins)
 
 #############
 # Tutorials #
 #############
 
 add_executable(tutorial_datatypes tutorial_datatypes.c)
-add_dependencies(tutorial_datatypes open625451_amalgamation)
-target_link_libraries(tutorial_datatypes ${LIBS})
+target_link_libraries(tutorial_datatypes open62541 ${open62541_LIBRARIES})
 
 add_executable(tutorial_server_firststeps tutorial_server_firststeps.c)
-add_dependencies(tutorial_server_firststeps open625451_amalgamation)
-target_link_libraries(tutorial_server_firststeps ${LIBS})
+target_link_libraries(tutorial_server_firststeps open62541 ${open62541_LIBRARIES})
 
 add_executable(tutorial_server_variable tutorial_server_variable.c)
-add_dependencies(tutorial_server_variable open625451_amalgamation)
-target_link_libraries(tutorial_server_variable ${LIBS})
+target_link_libraries(tutorial_server_variable open62541 ${open62541_LIBRARIES})
 
 add_executable(tutorial_server_datasource tutorial_server_datasource.c)
-add_dependencies(tutorial_server_datasource open625451_amalgamation)
-target_link_libraries(tutorial_server_datasource ${LIBS})
+target_link_libraries(tutorial_server_datasource open62541 ${open62541_LIBRARIES})
 
 add_executable(tutorial_server_variabletype tutorial_server_variabletype.c)
-add_dependencies(tutorial_server_variabletype open625451_amalgamation)
-target_link_libraries(tutorial_server_variabletype ${LIBS})
+target_link_libraries(tutorial_server_variabletype open62541 ${open62541_LIBRARIES})
 
 add_executable(tutorial_server_object tutorial_server_object.c)
-add_dependencies(tutorial_server_object open625451_amalgamation)
-target_link_libraries(tutorial_server_object ${LIBS})
+target_link_libraries(tutorial_server_object open62541 ${open62541_LIBRARIES})
 
 if(UA_ENABLE_METHODCALLS)
   add_executable(tutorial_server_method tutorial_server_method.c)
-  add_dependencies(tutorial_server_method open625451_amalgamation)
-  target_link_libraries(tutorial_server_method ${LIBS})
+  target_link_libraries(tutorial_server_method open62541 ${open62541_LIBRARIES})
 endif()
 
 add_executable(tutorial_client_firststeps tutorial_client_firststeps.c)
-add_dependencies(tutorial_client_firststeps open625451_amalgamation)
-target_link_libraries(tutorial_client_firststeps ${LIBS})
+target_link_libraries(tutorial_client_firststeps open62541 ${open62541_LIBRARIES})
 
 ##################
 # Example Server #
 ##################
 
 add_executable(server server.c)
-target_link_libraries(server ${LIBS})
+target_link_libraries(server open62541 ${open62541_LIBRARIES})
 
 if(UA_ENABLE_NONSTANDARD_UDP)
   add_executable(server_udp server_udp.c ${PROJECT_SOURCE_DIR}/plugins/ua_network_udp.c)
-  target_link_libraries(server_udp ${LIBS})
+  target_link_libraries(server_udp open62541 ${open62541_LIBRARIES})
 endif()
 
 ##################
@@ -76,28 +49,28 @@ endif()
 ##################
 
 add_executable(client client.c)
-target_link_libraries(client ${LIBS})
+target_link_libraries(client open62541 ${open62541_LIBRARIES})
 
 ####################
 # Feature Examples #
 ####################
 
 add_executable(server_mainloop server_mainloop.c)
-target_link_libraries(server_mainloop ${LIBS})
+target_link_libraries(server_mainloop open62541 ${open62541_LIBRARIES})
 
 add_executable(server_instantiation server_instantiation.c)
-target_link_libraries(server_instantiation ${LIBS})
+target_link_libraries(server_instantiation open62541 ${open62541_LIBRARIES})
 
 add_executable(server_repeated_job server_repeated_job.c)
-target_link_libraries(server_repeated_job ${LIBS})
+target_link_libraries(server_repeated_job open62541 ${open62541_LIBRARIES})
 
 add_executable(server_inheritance server_inheritance.c)
-target_link_libraries(server_inheritance ${LIBS})
+target_link_libraries(server_inheritance open62541 ${open62541_LIBRARIES})
 
-if(NOT BUILD_SHARED_LIBS AND UA_BUILD_EXAMPLES_NODESET_COMPILER)
+if(NOT BUILD_SHARED_open62541_LIBRARIES AND UA_BUILD_EXAMPLES_NODESET_COMPILER)
   # needs internal methods which are not exported in the dynamic lib
   add_executable(server_nodeset server_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/nodeset.c)
-  target_link_libraries(server_nodeset ${LIBS})
+  target_link_libraries(server_nodeset open62541 ${open62541_LIBRARIES})
   target_include_directories(server_nodeset PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
 endif()
 
@@ -111,12 +84,5 @@ if(UA_BUILD_SELFSIGNED_CERTIFICATE)
   add_custom_target(selfsigned ALL DEPENDS server_cert.der ca.crt)
 
   add_executable(server_certificate server_certificate.c server_cert.der ca.crt)
-  target_link_libraries(server_certificate ${LIBS})
-endif()
-
-if(NOT BUILD_SHARED_LIBS)
-  # needs internal methods which are not exported in the dynamic lib
-  add_executable(server_readspeed server_readspeed.c)
-  target_include_directories(server_readspeed PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
-  target_link_libraries(server_readspeed ${LIBS})
+  target_link_libraries(server_certificate open62541 ${open62541_LIBRARIES})
 endif()

+ 8 - 15
tests/CMakeLists.txt

@@ -12,6 +12,8 @@ if(UA_ENABLE_VALGRIND_UNIT_TESTS)
     find_package(Valgrind REQUIRED)
 endif()
 
+set(LIBS ${CHECK_LIBRARIES} ${open62541_LIBRARIES})
+
 # Build the plugins used for testing
 set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
                         ${PROJECT_SOURCE_DIR}/tests/testing_clock.c
@@ -21,22 +23,8 @@ set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
 
 add_library(open62541-testplugins OBJECT ${test_plugin_sources})
 add_dependencies(open62541-testplugins open62541)
-target_include_directories(open62541-testplugins PRIVATE ${PROJECT_SOURCE_DIR}/plugins)
-target_include_directories(open62541-testplugins PRIVATE ${PROJECT_BINARY_DIR}/src_generated)
-
-set(LIBS ${CHECK_LIBRARIES} ${open62541_LIBRARIES})
-if(NOT WIN32)
-  list(APPEND LIBS pthread m)
-  if(NOT APPLE)
-    list(APPEND LIBS rt subunit)
-  endif()
-else()
-    list(APPEND LIBS ws2_32)
-endif()
-if(UA_ENABLE_MULTITHREADING)
-    list(APPEND LIBS urcu-cds urcu urcu-common)
-endif()
 
+# Workaround some clang warnings in the uni tests
 if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
     add_definitions(-Wno-sign-conversion)
 endif()
@@ -108,6 +96,11 @@ add_executable(check_server_userspace check_server_userspace.c $<TARGET_OBJECTS:
 target_link_libraries(check_server_userspace ${LIBS})
 add_test_valgrind(check_server_userspace ${CMAKE_CURRENT_BINARY_DIR}/check_server_userspace)
 
+# Readspeed server
+add_executable(check_server_readspeed check_server_readspeed.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
+target_link_libraries(check_server_readspeed ${LIBS})
+add_test_valgrind(check_server_readspeed ${CMAKE_CURRENT_BINARY_DIR}/check_server_readspeed)
+
 # Test server with network dumps from files
 
 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin

examples/server_readspeed.c → tests/check_server_readspeed.c


+ 3 - 3
tools/travis/travis_osx_script.sh

@@ -12,7 +12,7 @@ else
 
     echo "Documentation and certificate build"  && echo -en 'travis_fold:start:script.build.doc\\r'
     mkdir -p build && cd build
-    cmake -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_DOCUMENTATION=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
+    cmake -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
     make selfsigned
     ls examples
     cp examples/server_cert.der ../
@@ -40,14 +40,14 @@ else
 
     echo "Compile multithreaded version" && echo -en 'travis_fold:start:script.build.multithread\\r'
     mkdir -p build && cd build
-    cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLESERVER=ON -DUA_BUILD_EXAMPLES=ON ..
+    cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
     make -j
     cd .. && rm -rf build
 	echo -en 'travis_fold:end:script.build.multithread\\r'
 
     echo "Debug build and unit tests with valgrind" && echo -en 'travis_fold:start:script.build.unit_test\\r'
     mkdir -p build && cd build
-    cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF -DUA_ENABLE_VALGRIND_UNIT_TESTS=OFF ..
+    cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=ON ..
     make -j && make test ARGS="-V"
     cd .. && rm -rf build
 	echo -en 'travis_fold:end:script.build.unit_test\\r'