Browse Source

build a shared lib with only selected "userland" symbols visible

Julius Pfrommer 10 years ago
parent
commit
bea30a06fc
2 changed files with 14 additions and 9 deletions
  1. 6 4
      CMakeLists.txt
  2. 8 5
      tests/CMakeLists.txt

+ 6 - 4
CMakeLists.txt

@@ -39,7 +39,7 @@ set(lib_sources src/ua_types.c
 
 # compiler flags
 if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
-add_definitions(-std=c99 -pedantic -pipe -fvisibility=hidden -Wall -Wextra -Werror -Wformat
+add_definitions(-std=c99 -pedantic -pipe -fvisibility=hidden -fPIC -Wall -Wextra -Werror -Wformat
                 -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare -Wmultichar
                 -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -ffunction-sections -fdata-sections)
     if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
@@ -111,7 +111,8 @@ else()
     list(APPEND lib_sources src/server/ua_nodestore.c)
 endif()
 
-add_library(open62541 SHARED ${lib_sources}) # we can add more files to lib_sources later on
+add_library(open62541-objects OBJECT ${lib_sources}) # static version that exports all symbols
+add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-objects>)
 
 ## logging
 set(UA_LOGLEVEL 400 CACHE STRING "Level at which logs shall be reported")
@@ -154,8 +155,9 @@ option(CLIENT "Build a test client" OFF)
 if(CLIENT)
 	message(STATUS "Extensions: enabling client")
 	add_definitions( -DBENCHMARK=1 )
-	add_executable(exampleClient examples/opcuaClient.c)
-	target_link_libraries(exampleClient open62541)
+    # the client is built directly with the .o files as it currently uses
+    # internal functions that are not exported to the shared lib.
+	add_executable(exampleClient $<TARGET_OBJECTS:open62541-objects> examples/opcuaClient.c)
 endif()
 
 # build example server

+ 8 - 5
tests/CMakeLists.txt

@@ -1,7 +1,7 @@
 find_package(Check REQUIRED)
 find_package(Threads REQUIRED)
 
-set(LIBS open62541 ${CHECK_LIBRARIES} m)
+set(LIBS ${CHECK_LIBRARIES})
 if(NOT WIN32)
     list(APPEND LIBS rt pthread)
 endif(NOT WIN32)
@@ -9,11 +9,14 @@ if(ENABLE_MULTITHREADING)
     list(APPEND LIBS urcu-cds urcu)
 endif(ENABLE_MULTITHREADING)
 
-add_executable(check_builtin check_builtin.c)
+# the unit test are built directly on the open62541 object files. so they can
+# access symbols that are hidden/not exported to the shared library
+
+add_executable(check_builtin $<TARGET_OBJECTS:open62541-objects> check_builtin.c)
 target_link_libraries(check_builtin ${LIBS})
 add_test(builtin ${CMAKE_CURRENT_BINARY_DIR}/check_builtin)
 
-add_executable(check_memory check_memory.c)
+add_executable(check_memory $<TARGET_OBJECTS:open62541-objects> check_memory.c)
 target_link_libraries(check_memory ${LIBS})
 add_test(memory ${CMAKE_CURRENT_BINARY_DIR}/check_memory)
 
@@ -25,11 +28,11 @@ add_test(memory ${CMAKE_CURRENT_BINARY_DIR}/check_memory)
 # target_link_libraries(check_base64 ${LIBS})
 # add_test(base64 ${CMAKE_CURRENT_BINARY_DIR}/check_base64)
 
-add_executable(check_services_view check_services_view.c)
+add_executable(check_services_view $<TARGET_OBJECTS:open62541-objects> check_services_view.c)
 target_link_libraries(check_services_view ${LIBS})
 add_test(services_view ${CMAKE_CURRENT_BINARY_DIR}/check_services_view)
 
-add_executable(check_nodestore check_nodestore.c)
+add_executable(check_nodestore $<TARGET_OBJECTS:open62541-objects> check_nodestore.c)
 target_link_libraries(check_nodestore ${LIBS})
 add_test(namespace ${CMAKE_CURRENT_BINARY_DIR}/check_nodestore)