Update build system to allow custom install targets
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Fri, 30 Jan 2015 11:48:16 +0000 (12:48 +0100)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Fri, 30 Jan 2015 11:48:16 +0000 (12:48 +0100)
CMakeLists.txt
cmake/OONFBuildLibrary.cmake
cmake/generate_builddata.cmake [deleted file]
cmake/get_version.cmake [new file with mode: 0644]
cmake/link_app.cmake
cmake/version.cmake.in [new file with mode: 0644]
src-api/core/CMakeLists.txt
src/dlep-radio/CMakeLists.txt
src/olsrd2/CMakeLists.txt
src/oonf/CMakeLists.txt

index 523b1fa..5d1c366 100644 (file)
@@ -1,5 +1,5 @@
 project (OONF C)
-cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
 
 ###########################
 #### API configuration ####
@@ -30,6 +30,10 @@ endif(DOXYGEN_FOUND)
 #### Compile targets ####
 #########################
 
+# get repository tag and version
+include (cmake/get_version.cmake)
+include (${PROJECT_BINARY_DIR}/version.cmake)
+
 # add define for length of base path
 string(LENGTH "${CMAKE_SOURCE_DIR}/" BASELENGTH)
 add_definitions(-DBASEPATH_LENGTH=${BASELENGTH})
index 0e2b3ee..ad3a864 100644 (file)
@@ -4,11 +4,11 @@ function (oonf_create_library libname source include link_internal linkto_extern
     # 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(oonf_${libname} ws2_32 iphlpapi)
@@ -23,23 +23,27 @@ function (oonf_create_library libname source include link_internal linkto_extern
         target_link_libraries(oonf_${libname} ${linkto_external})
     endif (linkto_external)
     
-    install(TARGETS oonf_${libname} DESTINATION lib)
-
-    foreach(inc ${include})
-        get_filename_component(path "${inc}" PATH)
-        
-        if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${inc}")
-            install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${inc}
-                     DESTINATION ${INSTALL_INCLUDE_DIR}/${libname}/${path})
-        ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${inc}")
-            install (FILES ${CMAKE_BINARY_DIR}/${libname}/${inc}
-                     DESTINATION ${INSTALL_INCLUDE_DIR}/${libname}/${path})
-        ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${inc}")
-    endforeach(inc)
+    install(TARGETS oonf_${libname} LIBRARY
+                                    DESTINATION lib
+                                    COMPONENT component_oonf_${libname})
+    
+    ADD_CUSTOM_TARGET(install_oonf_${libname}
+                      COMMAND ${CMAKE_COMMAND} 
+                      -DBUILD_TYPE=${CMAKE_BUILD_TYPE}
+                      -DCOMPONENT=component_oonf_${libname}
+                      -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
+    ADD_DEPENDENCIES(install_oonf_${libname}   oonf_${libname})
+    
+    if (linkto_internal)
+        FOREACH(lib ${linkto_internal})
+            ADD_DEPENDENCIES(install_oonf_${libname} ${lib})
+            ADD_DEPENDENCIES(install_oonf_${libname} install_${lib})
+        ENDFOREACH(lib)
+    endif (linkto_internal)
 endfunction (oonf_create_library)
 
 function (oonf_create_plugin libname source include linkto_external)
     SET (linkto_internal oonf_core oonf_config oonf_common)
     
-    oonf_create_library("${libname}" "${source}" "" "${linkto_internal}" "${linkto_external}")
+    oonf_create_library("${libname}" "${source}" "${include}" "${linkto_internal}" "${linkto_external}")
 endfunction (oonf_create_plugin)
diff --git a/cmake/generate_builddata.cmake b/cmake/generate_builddata.cmake
deleted file mode 100755 (executable)
index fd123a4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/cmake
-
-# look for git executable
-IF(NOT OONF_LIB_GIT)
-  SET(found_git false) 
-  find_program(found_git git)
-
-  SET(OONF_LIB_GIT "cannot read git repository")
-
-  IF(NOT ${found_git} STREQUAL "found_git-NOTFOUND")
-         # get git description WITH dirty flag
-         execute_process(COMMAND git describe --always --long --tags --dirty --match "v[0-9]*"
-                 OUTPUT_VARIABLE OONF_LIB_GIT OUTPUT_STRIP_TRAILING_WHITESPACE)
-  ENDIF()
-ENDIF()
-
-IF(NOT OONF_VERSION)
-  SET(found_git false)
-  find_program(found_git git)
-
-  SET(OONF_VERSION "cannot read git repository")
-
-  IF(NOT ${found_git} STREQUAL "found_git-NOTFOUND")
-    # get git description WITH dirty flag
-    execute_process(COMMAND git describe --abbrev=0 --match "v[0-9]*"
-      OUTPUT_VARIABLE OONF_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
-  ENDIF()
-ENDIF()
-
-message ("Git commit: ${OONF_LIB_GIT}")
-
-# create builddata file
-configure_file (${SRC} ${DST})
diff --git a/cmake/get_version.cmake b/cmake/get_version.cmake
new file mode 100644 (file)
index 0000000..15ce8c5
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/cmake
+
+# look for git executable
+IF(NOT OONF_LIB_GIT AND NOT OONF_VERSION)
+  SET(found_git false) 
+  find_program(found_git git)
+
+  SET(OONF_LIB_GIT "cannot read git repository")
+
+  IF(NOT ${found_git} STREQUAL "found_git-NOTFOUND")
+    # get git description WITH dirty flag
+    execute_process(COMMAND git describe --always --long --tags --dirty --match "v[0-9]*"
+      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+      OUTPUT_VARIABLE LIB_GIT OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+    # get git description WITH dirty flag
+    execute_process(COMMAND git describe --abbrev=0 --match "v[0-9]*"
+      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+      OUTPUT_VARIABLE VERSION_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
+    
+    # strip "v" from tag
+    string(SUBSTRING ${VERSION_TAG} 1 -1 VERSION)
+  ENDIF()
+ENDIF()
+
+message ("Git commit: ${LIB_GIT}, Git version: ${VERSION}")
+configure_file (${CMAKE_SOURCE_DIR}/cmake/version.cmake.in ${PROJECT_BINARY_DIR}/version.cmake)
index 425f50c..3ab30b6 100644 (file)
@@ -2,15 +2,33 @@
 # earlier libraries can use the functions of later, not the
 # other way around
 
+function (oonf_create_install_target name)
+    ADD_CUSTOM_TARGET(install_${name}
+                      COMMAND ${CMAKE_COMMAND} 
+                      -DBUILD_TYPE=${CMAKE_BUILD_TYPE}
+                      -DCOMPONENT=component_${name}
+                      -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
+    ADD_DEPENDENCIES(install_${name}   ${name})
+    
+    get_property(value TARGET ${name} PROPERTY LINK_LIBRARIES)
+    FOREACH(lib ${value})
+        IF (TARGET ${lib})
+            ADD_DEPENDENCIES(install_${name} ${lib})
+            ADD_DEPENDENCIES(install_${name} install_${lib})
+        ENDIF(TARGET ${lib})
+    ENDFOREACH(lib)     
+endfunction (oonf_create_install_target)
+    
 function (oonf_create_app executable static_plugins)
     message (STATUS "Static plugins for ${executable} app:")
 
     # standard static linked targets
     SET(OBJECT_TARGETS )
     SET(EXTERNAL_LIBRARIES )
-
+    SET(STATIC_PLUGIN_LIST )
+    
     # generate configuration file
-    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../app_data.c.in ${PROJECT_BINARY_DIR}/${executable}_app_data.c)
+    configure_file(${CMAKE_SOURCE_DIR}/src/app_data.c.in ${PROJECT_BINARY_DIR}/${executable}_app_data.c)
 
     # run through list of static plugins
     FOREACH(plugin ${static_plugins})
@@ -20,9 +38,6 @@ function (oonf_create_app executable static_plugins)
             # 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})
@@ -37,10 +52,10 @@ function (oonf_create_app executable static_plugins)
     ENDFOREACH(plugin)
 
     # create executables
-    ADD_EXECUTABLE(${executable}_dynamic ${CMAKE_CURRENT_SOURCE_DIR}/../main.c
+    ADD_EXECUTABLE(${executable}_dynamic ${CMAKE_SOURCE_DIR}/src/main.c
                                          ${PROJECT_BINARY_DIR}/${executable}_app_data.c
                                          ${OBJECT_TARGETS})
-    ADD_EXECUTABLE(${executable}_static  ${CMAKE_CURRENT_SOURCE_DIR}/../main.c
+    ADD_EXECUTABLE(${executable}_static  ${CMAKE_SOURCE_DIR}/src/main.c
                                          ${PROJECT_BINARY_DIR}/${executable}_app_data.c
                                          ${OBJECT_TARGETS}
                                          $<TARGET_OBJECTS:oonf_static_common>
@@ -50,11 +65,7 @@ function (oonf_create_app executable static_plugins)
     # Add executables to static/dynamic target
     ADD_DEPENDENCIES(dynamic ${executable}_dynamic)
     ADD_DEPENDENCIES(static  ${executable}_static)
-
-    # add path to install target
-    INSTALL (TARGETS ${executable}_dynamic DESTINATION bin)
-    INSTALL (TARGETS ${executable}_static  DESTINATION bin COMPONENT static_exe)
-
+    
     # link framework libraries to dynamic executable
     TARGET_LINK_LIBRARIES(${executable}_dynamic PUBLIC oonf_core
                                                        oonf_config
@@ -67,4 +78,38 @@ function (oonf_create_app executable static_plugins)
     # link dlopen() library
     TARGET_LINK_LIBRARIES(${executable}_dynamic PUBLIC ${CMAKE_DL_LIBS})
     TARGET_LINK_LIBRARIES(${executable}_static  PUBLIC ${CMAKE_DL_LIBS})
+    
+    # create install targets
+    INSTALL (TARGETS ${executable}_dynamic RUNTIME 
+                                           DESTINATION bin 
+                                           COMPONENT component_${executable}_dynamic)
+    INSTALL (TARGETS ${executable}_static  RUNTIME
+                                           DESTINATION bin 
+                                           COMPONENT component_${executable}_static)
+
+    # add custom install targets
+    oonf_create_install_target("${executable}_dynamic")
+    oonf_create_install_target("${executable}_static")
+    
+#    ADD_CUSTOM_TARGET(install_${executable}_dynamic
+#                      COMMAND ${CMAKE_COMMAND} 
+#                      -DBUILD_TYPE=${CMAKE_BUILD_TYPE}
+#                      -DCOMPONENT=component_${executable}_dynamic 
+#                      -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
+#    ADD_DEPENDENCIES(install_${executable}_dynamic  ${executable}_dynamic
+#                                                    oonf_core
+#                                                    oonf_config
+#                                                    oonf_common)
+#    get_property(value TARGET ${executable}_dynamic PROPERTY LINK_LIBRARIES)
+#    message("${executable}_dynamic dependencies: ${value}")
+
+#    ADD_CUSTOM_TARGET(install_${executable}_static
+#                      COMMAND ${CMAKE_COMMAND} 
+#                      -DBUILD_TYPE=${CMAKE_BUILD_TYPE}
+#                      -DCOMPONENT=component_${executable}_static 
+#                      -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
+#    ADD_DEPENDENCIES(install_${executable}_static   ${executable}_static)
+#    
+#    get_property(value TARGET ${executable}_static PROPERTY LINK_LIBRARIES)
+#    message("${executable}_static dependencies: ${value}")
 endfunction(oonf_create_app)
diff --git a/cmake/version.cmake.in b/cmake/version.cmake.in
new file mode 100644 (file)
index 0000000..4218de7
--- /dev/null
@@ -0,0 +1,2 @@
+SET (OONF_VERSION @VERSION@)
+SET (OONF_LIB_GIT @LIB_GIT@)
index c8cd4cf..80b30d9 100644 (file)
@@ -1,25 +1,6 @@
 # make sure that oonf_libdata is rebuild everytimes 
 SET(GEN_DATA_C ${PROJECT_BINARY_DIR}/oonf_libdata.c)
-
-ADD_CUSTOM_TARGET(LibCleanData ALL
-    COMMAND ${CMAKE_COMMAND} -E remove ${GEN_DATA_C}
-    COMMENT "Remove old library builddata"
-)
-
-ADD_CUSTOM_COMMAND (
-    OUTPUT ${GEN_DATA_C}
-    COMMAND ${CMAKE_COMMAND}
-        -DSRC=${CMAKE_CURRENT_SOURCE_DIR}/oonf_libdata.c.in
-        -DDST=${GEN_DATA_C}
-        -DOONF_VERSION=${OONF_VERSION}
-        -DCMAKE_SHARED_LIBRARY_PREFIX=${CMAKE_SHARED_LIBRARY_PREFIX}
-        -DCMAKE_SHARED_LIBRARY_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX}
-        -DOONF_LIB_GIT=${OONF_LIB_GIT}
-        -P ${CMAKE_SOURCE_DIR}/cmake/generate_builddata.cmake
-    DEPENDS LibCleanData
-    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
-    COMMENT "Create new library builddata"
-)
+configure_file (${CMAKE_CURRENT_SOURCE_DIR}/oonf_libdata.c.in ${GEN_DATA_C})
 
 SET(OONF_CORE_SRCS oonf_cfg.c
                    oonf_logging.c
index 0bfc2b4..7af1fb5 100644 (file)
@@ -23,26 +23,28 @@ set (OONF_APP_DEFAULT_CFG_HANDLER Compact)
 ####  set static subsystems  ####
 #################################
 
-set (OONF_STATIC_PLUGINS class
-                         clock
-                         interface
-                         layer2
-                         packet_socket
-                         socket
-                         stream_socket
-                         telnet
-                         timer
-                         viewer
-                         os_clock
-                         os_socket
-                         os_interface
-                         os_system
-                         cfg_compact
-                         layer2info
-                         nl80211_listener
-                         systeminfo
-                         dlep_radio
-                         )
+IF (NOT OONF_STATIC_PLUGINS)
+    set (OONF_STATIC_PLUGINS class
+                             clock
+                             interface
+                             layer2
+                             packet_socket
+                             socket
+                             stream_socket
+                             telnet
+                             timer
+                             viewer
+                             os_clock
+                             os_socket
+                             os_interface
+                             os_system
+                             cfg_compact
+                             layer2info
+                             nl80211_listener
+                             systeminfo
+                             dlep_radio
+                             )
+ENDIF (NOT OONF_STATIC_PLUGINS)
 
 ##################################
 #### link framework libraries ####
index 2bce13c..adff053 100644 (file)
@@ -23,35 +23,37 @@ set (OONF_APP_DEFAULT_CFG_HANDLER Compact)
 ####  set static subsystems  ####
 #################################
 
-set (OONF_STATIC_PLUGINS class
-                         clock
-                         duplicate_set
-                         interface
-                         layer2
-                         packet_socket
-                         rfc5444
-                         socket
-                         stream_socket
-                         telnet
-                         timer
-                         viewer
-                         os_clock
-                         os_socket
-                         os_interface
-                         os_routing
-                         os_system
-                         cfg_compact
-                         layer2info
-                         nl80211_listener
-                         systeminfo
-                         nhdp
-                         ff_dat_metric
-                         link_config
-                         neighbor_probing
-                         nhdpinfo
-                         olsrv2
-                         olsrv2info
-                         )
+IF (NOT OONF_STATIC_PLUGINS)
+    set (OONF_STATIC_PLUGINS class
+                             clock
+                             duplicate_set
+                             interface
+                             layer2
+                             packet_socket
+                             rfc5444
+                             socket
+                             stream_socket
+                             telnet
+                             timer
+                             viewer
+                             os_clock
+                             os_socket
+                             os_interface
+                             os_routing
+                             os_system
+                             cfg_compact
+                             layer2info
+                             nl80211_listener
+                             systeminfo
+                             nhdp
+                             ff_dat_metric
+                             link_config
+                             neighbor_probing
+                             nhdpinfo
+                             olsrv2
+                             olsrv2info
+                             )
+ENDIF (NOT OONF_STATIC_PLUGINS)
 
 ##################################
 #### link framework libraries ####
index 4dc5874..3d20450 100644 (file)
@@ -7,7 +7,7 @@ set (OONF_APP "Minimal OONF Daemon")
 set (OONF_EXE oonf)
 
 # setup custom text before and after default help message
-set (OONF_HELP_PREFIX "OONF Daemon daemon\\n")
+set (OONF_HELP_PREFIX "OONF daemon\\n")
 set (OONF_HELP_SUFFIX "Visit http://www.olsr.org\\n")
 
 # setup custom text after version string
@@ -23,7 +23,9 @@ set (OONF_APP_DEFAULT_CFG_HANDLER Compact)
 ####  set static subsystems  ####
 #################################
 
-set (OONF_STATIC_PLUGINS cfg_compact)
+IF (NOT OONF_STATIC_PLUGINS)
+    set (OONF_STATIC_PLUGINS cfg_compact)
+ENDIF (NOT OONF_STATIC_PLUGINS)
 
 ##################################
 #### link framework libraries ####