Просмотр исходного кода

Separate install-as-lib and building of shared libs

This change separates the build + install as shared library, allowing
the user to select installable OpENer (as static library by default),
and another setting to toggle static or shared.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Joachim Wiberg 3 лет назад
Родитель
Сommit
b8387a2100

+ 2 - 2
README.md

@@ -64,8 +64,8 @@ OpENer also now has a real-time capable POSIX startup via the OpENer_RT option,
 If you want to use OpENer_RT, instead of step 2, the  ``sudo setcap cap_net_raw,cap_ipc_lock,cap_sys_nice+ep ./src/ports/POSIX/OpENer
 `` has to be run to grant OpENEr ``CAP_SYS_NICE``, ``CAP_IPC_LOCK``, and the ``CAP_NET_RAW`` capabilities, needed for the RT mode
 
-Shared library support has been added to CMakeLists file and is enabled by setting `-DBUILD_SHARED_LIBS=ON` when calling cmake.
-It has only been tested under Linux/POSIX platform.
+OpENer can also be built and installed as a library by setting the CMake flag `-DOPENER_INSTALL_AS_LIB`.  To build a shared library,
+the global option `-DBUILD_SHARED_LIBS=ON` should also be set.  It has only been tested under Linux/POSIX platform.
 
 
 Compile for Windows XP/7/8 via Visual Studio:

+ 2 - 1
source/CMakeLists.txt

@@ -36,7 +36,8 @@ INCLUDE( ${OpENer_BUILDSUPPORT_DIR}/OpENer.cmake )
 
 option(OPENER_PRODUCED_DATA_HAS_RUN_IDLE_HEADER "Shall produced data from OpENer also include a run idle header?" FALSE)
 option(OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER "Will consumed data from OpENer also include a run idle header?" TRUE)
-option(BUILD_SHARED_LIBS "Builds OpENer as separate lib and sample application" FALSE)
+option(OPENER_INSTALL_AS_LIB "Build and install OpENer as a library" FALSE)
+option(BUILD_SHARED_LIBS "Build OpENer as shared library" FALSE)
 
 if(OPENER_PRODUCED_DATA_HAS_RUN_IDLE_HEADER)
   add_definitions(-DOPENER_PRODUCED_DATA_HAS_RUN_IDLE_HEADER)

+ 1 - 1
source/src/CMakeLists.txt

@@ -18,7 +18,7 @@ opener_common_includes()
 
 opener_platform_support( "INCLUDES" )
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   install(DIRECTORY .
     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
     FILES_MATCHING PATTERN "*.h"

+ 1 - 1
source/src/cip/CMakeLists.txt

@@ -16,7 +16,7 @@ set( CIP_SRC appcontype.c cipassembly.c cipclass3connection.c cipcommon.c cipcon
 
 add_library( CIP ${CIP_SRC} )
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   target_link_libraries(CIP ENET_ENCAP)
   install(TARGETS CIP
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

+ 1 - 1
source/src/enet_encap/CMakeLists.txt

@@ -16,7 +16,7 @@ opener_platform_support("INCLUDES")
 
 add_library( ENET_ENCAP ${ENET_ENCAP_SRC} )
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   install(TARGETS ENET_ENCAP
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

+ 1 - 1
source/src/ports/CMakeLists.txt

@@ -19,7 +19,7 @@ set( PLATFORM_GENERIC_SRC generic_networkhandler.c socket_timer.c  udp_protocol.
 
 add_library( PLATFORM_GENERIC ${PLATFORM_GENERIC_SRC} )
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   install(TARGETS PLATFORM_GENERIC
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

+ 1 - 1
source/src/ports/POSIX/CMakeLists.txt

@@ -32,7 +32,7 @@ opener_platform_support("INCLUDES")
 add_library( ${OpENer_PLATFORM}PLATFORM ${PLATFORM_SPEC_SRC})
 # Mark executables and/or libraries for installation
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   install(TARGETS ${OpENer_PLATFORM}PLATFORM
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

+ 1 - 1
source/src/ports/nvdata/CMakeLists.txt

@@ -16,7 +16,7 @@ opener_platform_support("INCLUDES")
 
 add_library( NVDATA ${NVDATA_SRC} )
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   install(TARGETS NVDATA
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

+ 1 - 1
source/src/trace.h

@@ -12,7 +12,7 @@
 
 #ifdef OPENER_WITH_TRACES
 
-#ifndef BUILD_SHARED_LIBS
+#ifndef OPENER_INSTALL_AS_LIB
 #include "opener_user_conf.h"
 #endif
 

+ 1 - 1
source/src/utils/CMakeLists.txt

@@ -6,7 +6,7 @@ set( UTILS_SRC random.c xorshiftrandom.c doublylinkedlist.c  enipmessage.c)
 
 add_library( Utils ${UTILS_SRC} )
 
-if( BUILD_SHARED_LIBS )
+if( OPENER_INSTALL_AS_LIB )
   install(TARGETS Utils
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}