Kaynağa Gözat

add building a static library, link the examples statically

Julius Pfrommer 9 yıl önce
ebeveyn
işleme
d154dd4e3d
2 değiştirilmiş dosya ile 8 ekleme ve 6 silme
  1. 7 5
      CMakeLists.txt
  2. 1 1
      examples/CMakeLists.txt

+ 7 - 5
CMakeLists.txt

@@ -250,16 +250,12 @@ option(ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h
 add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
                PRE_BUILD
                COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
-
-
                DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${exported_headers} ${internal_headers})
 
 add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
                PRE_BUILD
-
                COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${GIT_COMMIT_ID} ${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 ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
 
 if(ENABLE_AMALGAMATION)
@@ -275,13 +271,19 @@ else()
     include_directories(${PROJECT_BINARY_DIR}/src_generated)
 endif()
 target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING)
+
 add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
+add_library(open62541-static STATIC $<TARGET_OBJECTS:open62541-object>)
 target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING)
+target_compile_definitions(open62541-static PRIVATE -DUA_DYNAMIC_LINKING)
 if(WIN32)
-    target_link_libraries(open62541 ws2_32) #since networklayer_tcp is linked into the amalgate
+    # since networklayer_tcp is linked into the amalgate
+    target_link_libraries(open62541 ws2_32)
+    target_link_libraries(open62541-static ws2_32)
 endif()
 if(ENABLE_MULTITHREADING)
   target_link_libraries(open62541 urcu-cds urcu urcu-common pthread)
+  target_link_libraries(open62541-static urcu-cds urcu urcu-common pthread)
 endif()
 
 # build language bindings for the library

+ 1 - 1
examples/CMakeLists.txt

@@ -1,7 +1,7 @@
 include_directories(${PROJECT_SOURCE_DIR}/include)
 include_directories(${PROJECT_BINARY_DIR}/src_generated)
 
-set(LIBS open62541)
+set(LIBS open62541-static)
 if(NOT WIN32)
     list(APPEND LIBS pthread)
     if (NOT APPLE)