Unifiy static and dynamic building
authorHenning Rogge <hrogge@gmail.com>
Sat, 8 Nov 2014 08:12:34 +0000 (09:12 +0100)
committerHenning Rogge <hrogge@gmail.com>
Sat, 8 Nov 2014 08:12:34 +0000 (09:12 +0100)
add "static" and "dynamic" target

CMakeLists.txt
cmake/OONFBuildLibrary.cmake
cmake/link_app.cmake [new file with mode: 0644]
cmake/link_app_dynamic.cmake [deleted file]
cmake/link_app_static.cmake [deleted file]
src-plugins/subsystems/oonf_duplicate_set.h
src-plugins/subsystems/oonf_packet_socket.c
src-plugins/subsystems/oonf_packet_socket.h
src-plugins/subsystems/oonf_stream_socket.h
src/CMakeLists.txt
src/app_config.cmake

index df6d8cf..28c2dc7 100644 (file)
@@ -1,5 +1,5 @@
 project (OONF C)
-cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
+cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
 
 ###########################
 #### API configuration ####
@@ -33,9 +33,6 @@ endif(DOXYGEN_FOUND)
 #### Compile targets ####
 #########################
 
-# initialize target list
-set_property(GLOBAL PROPERTY OONF_TARGETS "") 
-
 # add define for length of base path
 string(LENGTH "${CMAKE_SOURCE_DIR}/" BASELENGTH)
 add_definitions(-DBASEPATH_LENGTH=${BASELENGTH})
@@ -52,6 +49,10 @@ if (NOT OONF_NO_TESTING)
     ENABLE_TESTING()
 endif (NOT OONF_NO_TESTING)
 
+# define static and dynamic target
+add_custom_target(static)
+add_custom_target(dynamic)
+
 # start compiling core and plugins
 add_subdirectory(src-api)
 add_subdirectory(src-plugins)
@@ -59,51 +60,6 @@ add_subdirectory(external)
 # add_subdirectory(examples)
 add_subdirectory(src)
 
-get_property (targets GLOBAL PROPERTY OONF_TARGETS)
-export (TARGETS ${targets} FILE "${PROJECT_BINARY_DIR}/OONFLibraryDepends_api.cmake")
 if (NOT OONF_NO_TESTING)
 #    add_subdirectory(tests)
 endif (NOT OONF_NO_TESTING)
-
-###############################
-#### Installation handling ####
-###############################
-
-# get list of include directories
-get_property (INCLUDE_LIST DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
-
-# Export the package for use from the build-tree
-# (this registers the build-tree with a global CMake-registry)
-if (NOT OONF_DO_NOT_REGISTER_PACKAGE)
-    export(PACKAGE OONF)
-endif (NOT OONF_DO_NOT_REGISTER_PACKAGE)
-
-# Create a OONFBuildTreeSettings.cmake file for the use from the build tree
-configure_file (./cmake/files/OONFBuildTreeSettings.cmake.in
-    "${PROJECT_BINARY_DIR}/OONFBuildTreeSettings.cmake" @ONLY)
-
-# Create the OONFConfig.cmake and OONFConfigVersion files
-file (RELATIVE_PATH CONF_REL_INCLUDE_DIR "/${INSTALL_CMAKE_DIR}"
-   "/${INSTALL_INCLUDE_DIR}")
-file (RELATIVE_PATH CONF_REL_LIB_DIR "/${INSTALL_CMAKE_DIR}"
-   "/${INSTALL_LIB_DIR}")
-configure_file (./cmake/files/OONFConfig.cmake.in
-    "${PROJECT_BINARY_DIR}/OONFConfig.cmake" @ONLY)
-configure_file (./cmake/files/OONFConfigVersion.cmake.in
-    "${PROJECT_BINARY_DIR}/OONFConfigVersion.cmake" @ONLY)
-
-# Copy OONFBuildLibrary to build directory
-file (COPY ./cmake/OONFBuildLibrary.cmake
-     DESTINATION ${PROJECT_BINARY_DIR})
-file (COPY ./cmake/OONFLibraryDepends.cmake
-     DESTINATION ${PROJECT_BINARY_DIR})
-
-# install cmake files
-install (FILES ${PROJECT_BINARY_DIR}/OONFBuildLibrary.cmake
-               ${PROJECT_BINARY_DIR}/OONFConfig.cmake
-               ${PROJECT_BINARY_DIR}/OONFConfigVersion.cmake
-         DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT dev)
-
-# Install the export set for use with the install-tree
-install (EXPORT OONFLibraryDepends DESTINATION
-    "${INSTALL_CMAKE_DIR}" COMPONENT dev)
index 0c1ffce..5f1b137 100644 (file)
@@ -1,21 +1,26 @@
 # generic oonf library creation
 
-function (oonf_internal_create_plugin prefix libname source include link_internal linkto_external)
-    add_library(${prefix}_${libname} SHARED ${source})
-    add_library(${prefix}_static_${libname} STATIC ${source})
+function (oonf_internal_create_plugin libname source include link_internal linkto_external)
+    # create static and dynamic library
+    add_library(oonf_${libname} SHARED ${source})
+    add_library(oonf_static_${libname} OBJECT ${source})
 
+    # add libraries to global static/dynamic target
+    add_dependencies(dynamic oonf_${libname})
+    add_dependencies(static oonf_static_${libname})
+    
+    # and link their dependencies
     if(WIN32)
-        target_link_libraries(${prefix}_${libname} ws2_32 iphlpapi)
+        target_link_libraries(oonf_${libname} ws2_32 iphlpapi)
     endif(WIN32)
 
-    set_target_properties(${prefix}_${libname} PROPERTIES SOVERSION "${OONF_VERSION}")
+    set_target_properties(oonf_${libname} PROPERTIES SOVERSION "${OONF_VERSION}")
 
     if (linkto_internal)
-        target_link_libraries(${prefix}_${libname} ${linkto_internal})
+        target_link_libraries(oonf_${libname} ${linkto_internal})
     endif (linkto_internal)
     if (linkto_external)
-        target_link_libraries(${prefix}_${libname} ${linkto_external})
-        target_link_libraries(${prefix}_static_${libname} ${linkto_external})
+        target_link_libraries(oonf_${libname} ${linkto_external})
     endif (linkto_external)
     
     foreach(inc ${include})
@@ -32,26 +37,7 @@ function (oonf_internal_create_plugin prefix libname source include link_interna
 endfunction (oonf_internal_create_plugin)
 
 function (oonf_create_library libname source include linkto_internal linkto_external)
-    oonf_internal_create_plugin("oonf" "${libname}" "${source}" "${include}" "${linkto_internal}" "${linkto_external}")
-    
-    install (TARGETS oonf_${libname}
-        # IMPORTANT: Add the library to the "export-set"
-        EXPORT OONFLibraryDepends
-        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib
-            COMPONENT dev)
-
-    install (TARGETS oonf_static_${libname}
-        # IMPORTANT: Add the static library to the "export-set"
-        EXPORT OONFLibraryDepends
-        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT stlib
-            COMPONENT dev)
-   
-    get_property (targets GLOBAL PROPERTY OONF_TARGETS)
-    SET (targets ${targets} oonf_${libname} oonf_static_${libname})
-    set_property(GLOBAL PROPERTY OONF_TARGETS "${targets}") 
-    
-#    export (TARGETS oonf_${libname} oonf_static_${libname} ${linkto_internal}
-#            FILE "${PROJECT_BINARY_DIR}/OONFLibraryDepends_${libname}.cmake")
+    oonf_internal_create_plugin("${libname}" "${source}" "${include}" "${linkto_internal}" "${linkto_external}")
 endfunction (oonf_create_library)
 
 function (oonf_create_plugin libname source include linkto_external)
diff --git a/cmake/link_app.cmake b/cmake/link_app.cmake
new file mode 100644 (file)
index 0000000..001f9ae
--- /dev/null
@@ -0,0 +1,64 @@
+# the order of static libraries is important
+# earlier libraries can use the functions of later, not the
+# other way around
+
+# link static plugins
+message ("Static plugins for executables:")
+
+# standard static linked targets
+SET(OBJECT_TARGETS )
+SET(EXTERNAL_LIBRARIES )
+
+# run through list of static plugins
+FOREACH(plugin ${OONF_STATIC_PLUGINS})
+    IF(TARGET oonf_static_${plugin})
+        message ("    Found target: oonf_static_${plugin}")  
+
+        # Remember object targets for static plugin
+        SET(OBJECT_TARGETS ${OBJECT_TARGETS} $<TARGET_OBJECTS:oonf_static_${plugin}>)
+        
+        # add static plugins to global dynamic target
+        ADD_DEPENDENCIES(dynamic oonf_static_${plugin})
+        
+        # extract external libraries of plugin 
+        get_property(value TARGET oonf_${plugin} PROPERTY LINK_LIBRARIES)
+        FOREACH(lib ${value})
+            IF(NOT "${lib}" MATCHES "^oonf_")
+                message ("        Library: ${lib}")
+                SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${lib})
+            ENDIF()
+        ENDFOREACH(lib)
+    ELSE (TARGET oonf_static_${plugin})
+        message (FATAL_ERROR "    Did not found target: oonf_static_${plugin}")
+    ENDIF(TARGET oonf_static_${plugin})
+ENDFOREACH(plugin)
+
+# create executables
+ADD_EXECUTABLE(${OONF_EXE}_dynamic ${OONF_SRCS}
+                                   ${OBJECT_TARGETS})
+ADD_EXECUTABLE(${OONF_EXE}_static  ${OONF_SRCS}
+                                   ${OBJECT_TARGETS}
+                                   $<TARGET_OBJECTS:oonf_static_common> 
+                                   $<TARGET_OBJECTS:oonf_static_config>
+                                   $<TARGET_OBJECTS:oonf_static_core>)
+
+# Add executables to static/dynamic target
+ADD_DEPENDENCIES(dynamic ${OONF_EXE}_dynamic)
+ADD_DEPENDENCIES(static  ${OONF_EXE}_static)
+
+# add path to install target
+INSTALL (TARGETS ${OONF_EXE}_dynamic DESTINATION bin)
+INSTALL (TARGETS ${OONF_EXE}_static  DESTINATION bin)
+
+# link framework libraries to dynamic executable
+TARGET_LINK_LIBRARIES(${OONF_EXE}_dynamic PUBLIC oonf_core
+                                                 oonf_config
+                                                 oonf_common)
+
+# link external libraries directly to executable
+TARGET_LINK_LIBRARIES(${OONF_EXE}_dynamic PUBLIC ${EXTERNAL_LIBRARIES})
+TARGET_LINK_LIBRARIES(${OONF_EXE}_static  PUBLIC ${EXTERNAL_LIBRARIES})
+
+# link dlopen() library
+TARGET_LINK_LIBRARIES(${OONF_EXE}_dynamic PUBLIC ${CMAKE_DL_LIBS})
+TARGET_LINK_LIBRARIES(${OONF_EXE}_static  PUBLIC ${CMAKE_DL_LIBS})
diff --git a/cmake/link_app_dynamic.cmake b/cmake/link_app_dynamic.cmake
deleted file mode 100644 (file)
index 79f89e3..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-# link static plugins
-message ("Compiling project with dynamic libraries")
-message ("Static plugins:")
-FOREACH(plugin ${OONF_STATIC_PLUGINS})
-    IF(TARGET oonf_static_${plugin})
-        message ("    Found target: oonf_static_${plugin}")  
-        TARGET_LINK_LIBRARIES(${OONF_EXE} -Wl,--whole-archive oonf_static_${plugin} -Wl,--no-whole-archive)
-    ELSE (TARGET oonf_static_${plugin})
-        message (FATAL_ERROR "    Did not found target: oonf_static_${plugin} or ${OONF_APP_LIBPREFIX}_static_${plugin}")
-    ENDIF(TARGET oonf_static_${plugin})
-ENDFOREACH(plugin)
-
-# link core, config and common
-TARGET_LINK_LIBRARIES(${OONF_EXE} oonf_core)
-TARGET_LINK_LIBRARIES(${OONF_EXE} oonf_config)
-TARGET_LINK_LIBRARIES(${OONF_EXE} oonf_common)
-
-# link dlopen() library
-TARGET_LINK_LIBRARIES(${OONF_EXE} ${CMAKE_DL_LIBS})
-
-# link extra win32 libs
-IF(WIN32)
-    TARGET_LINK_LIBRARIES(${OONF_EXE} oonf_regex)
-
-    SET_TARGET_PROPERTIES(${OONF_EXE} PROPERTIES ENABLE_EXPORTS true)
-    TARGET_LINK_LIBRARIES(${OONF_EXE} ws2_32 iphlpapi)
-ENDIF(WIN32)
diff --git a/cmake/link_app_static.cmake b/cmake/link_app_static.cmake
deleted file mode 100644 (file)
index 3f5130e..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-# the order of static libraries is important
-# earlier libraries can use the functions of later, not the
-# other way around
-
-# link static plugins
-message ("Compiling project with static libraries")
-message ("Static plugins:")
-FOREACH(plugin ${OONF_STATIC_PLUGINS})
-    IF(TARGET oonf_static_${plugin})
-        message ("    Found target: oonf_static_${plugin}")  
-        TARGET_LINK_LIBRARIES(${OONF_EXE} -Wl,--whole-archive oonf_static_${plugin} -Wl,--no-whole-archive)
-    ELSE (TARGET oonf_static_${plugin})
-        message (FATAL_ERROR "    Did not found target: oonf_static_${plugin} or ${OONF_APP_LIBPREFIX}_static_${plugin}")
-    ENDIF(TARGET oonf_static_${plugin})
-ENDFOREACH(plugin)
-
-# link core, config and common API
-TARGET_LINK_LIBRARIES(${OONF_EXE} -Wl,--whole-archive oonf_static_core -Wl,--no-whole-archive)
-TARGET_LINK_LIBRARIES(${OONF_EXE} -Wl,--whole-archive oonf_static_config -Wl,--no-whole-archive)
-TARGET_LINK_LIBRARIES(${OONF_EXE} -Wl,--whole-archive oonf_static_common -Wl,--no-whole-archive)
-
-# link dlopen() library
-TARGET_LINK_LIBRARIES(${OONF_EXE} ${CMAKE_DL_LIBS})
-
-# link extra win32 libs
-IF(WIN32)
-    TARGET_LINK_LIBRARIES(${OONF_EXE} -Wl,--whole-archive static_regex -Wl,--no-whole-archive)
-
-    SET_TARGET_PROPERTIES(${OONF_EXE} PROPERTIES ENABLE_EXPORTS true)
-    TARGET_LINK_LIBRARIES(${OONF_EXE} ws2_32 iphlpapi)
-ENDIF(WIN32)
index 4132d63..ed26e0d 100644 (file)
@@ -47,7 +47,7 @@
 #include "common/netaddr.h"
 #include "subsystems/oonf_timer.h"
 
-#define OONF_DUPSET_SUBSYSTEM "dupset"
+#define OONF_DUPSET_SUBSYSTEM "duplicate_set"
 
 enum { OONF_DUPSET_MAXIMUM_TOO_OLD = 8 };
 
index 2007e31..e64aa49 100644 (file)
@@ -85,7 +85,7 @@ static const char *_dependencies[] = {
 };
 
 static struct oonf_subsystem _oonf_packet_socket_subsystem = {
-  .name = "packet",
+  .name = OONF_PACKET_SUBSYSTEM,
   .dependencies = _dependencies,
   .dependencies_count = ARRAYSIZE(_dependencies),
   .init = _init,
index 19d022c..8c800d3 100644 (file)
@@ -56,7 +56,7 @@
 #define IF_NAMESIZE 16
 #endif
 
-#define OONF_PACKET_SUBSYSTEM "packet"
+#define OONF_PACKET_SUBSYSTEM "packet_socket"
 
 struct oonf_packet_socket;
 
index 7d95987..4fb72b0 100644 (file)
@@ -53,7 +53,7 @@
 #include "subsystems/oonf_socket.h"
 #include "subsystems/oonf_timer.h"
 
-#define OONF_STREAM_SUBSYSTEM "stream"
+#define OONF_STREAM_SUBSYSTEM "stream_socket"
 
 enum oonf_stream_session_state {
   STREAM_SESSION_ACTIVE,
index 16a533a..68cf700 100644 (file)
@@ -9,15 +9,5 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/app_data.c.in ${PROJECT_BINARY_DIR}/a
 set(OONF_SRCS main.c 
               ${PROJECT_BINARY_DIR}/app_data.c)
 
-# create executable
-ADD_EXECUTABLE(${OONF_EXE} ${OONF_SRCS})
-
-# add path to install target
-INSTALL (TARGETS ${OONF_EXE} DESTINATION bin)
-
-# link framework libraries (choose one)
-IF (OONF_FRAMEWORD_DYNAMIC)
-    include(../cmake/link_app_dynamic.cmake)
-ELSE (OONF_FRAMEWORD_DYNAMIC)
-    include(../cmake/link_app_static.cmake)
-endif(OONF_FRAMEWORD_DYNAMIC)
+# link framework libraries
+include(../cmake/link_app.cmake)
index 46e5961..8791aaa 100644 (file)
@@ -13,15 +13,11 @@ set (OONF_HELP_SUFFIX "Visit http://www.olsr.org\\n")
 # setup custom text after version string
 set (OONF_VERSION_TRAILER "Visit http://www.olsr.org\\n")
 
-# choose if framework should be linked static or dynamic
-set (OONF_FRAMEWORD_DYNAMIC false)
-
 # set to true to stop application running without root privileges (true/false)
 set (OONF_NEED_ROOT true)
 
 # name of default configuration handler
-set (OONF_APP_DEFAULT_CFG_HANDLER Compact CACHE STRING
-     "Name of default configuration handler")
+set (OONF_APP_DEFAULT_CFG_HANDLER Compact)
 
 #################################
 ####  set static subsystems  ####
@@ -42,4 +38,5 @@ set (OONF_STATIC_PLUGINS class
                          os_clock
                          os_net
                          os_routing
-                         os_system)
+                         os_system
+                         )