Generating static dependencies from dynamic ones
authoragrigora <alina.grigoras@cern.ch>
Thu, 20 Nov 2014 16:56:37 +0000 (17:56 +0100)
committeragrigora <alina.grigoras@cern.ch>
Mon, 15 Dec 2014 12:51:59 +0000 (13:51 +0100)
ACORDE/ACORDEbase/CMakeLists.txt
cmake/CMakeALICE.cmake

index 6f3f4f0..839f967 100644 (file)
@@ -53,17 +53,24 @@ string(REPLACE ".cxx" ".h" HDRS "${SRCS}")
 get_directory_property(incdirs INCLUDE_DIRECTORIES)
 generate_dictionary("${MODULE}" "${MODULE}LinkDef.h" "${HDRS}" "${incdirs}")
 
+# Setting the dependencies
+set(ROOT_DEPENDENCIES)
+set(ALIROOT_DEPENDENCIES STEERBase STEER CDB ESD RAWDatabase RAWDatarec RAWDatasim)
+
 # Generate the ROOT map
 # Dependecies
-set(LIBDEPS STEERBase STEER CDB ESD RAWDatabase RAWDatarec RAWDatasim)
+set(LIBDEPS ${ALIROOT_DEPENDENCIES} ${ROOT_DEPENDENCIES})
 generate_rootmap("${MODULE}" "${LIBDEPS}" "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}LinkDef.h")
 
 # Create an object to be reused in case of static libraries 
 # Otherwise the sources will be compiled twice
-add_library(ACORDEbase-object OBJECT ${SRCS} G__${MODULE}.cxx)
+add_library(${MODULE}-object OBJECT ${SRCS} G__${MODULE}.cxx)
 # Add a library to the project using the object
-add_library(ACORDEbase SHARED $<TARGET_OBJECTS:ACORDEbase-object>)
-target_link_libraries(ACORDEbase STEERBase STEER CDB ESD RAWDatabase RAWDatarec RAWDatasim)
+add_library(${MODULE} SHARED $<TARGET_OBJECTS:ACORDEbase-object>)
+target_link_libraries(${MODULE} ${ALIROOT_DEPENDENCIES} ${ROOT_DEPENDENCIES})
+
+
+message(STATUS "STATIC ${STATIC_ALIROOT_DEPENDENCIES}")
 
 # Additional compilation flags for the object
 set_target_properties(${MODULE}-object PROPERTIES COMPILE_FLAGS "-fPIC -O -g")
@@ -84,7 +91,10 @@ install(FILES ${HDRS} DESTINATION include)
 if(ALIROOT_STATIC)
     add_library(${MODULE}-static STATIC $<TARGET_OBJECTS:ACORDEbase-object>)
     set_target_properties(${MODULE}-static PROPERTIES OUTPUT_NAME ${MODULE})
-    target_link_libraries(${MODULE}-static STEERBase-static STEER-static ESD-static CDB-static RAWDatabase-static RAWDatarec-static RAWDatasim-static Root)
+
+    # list of shared dependencies / the name of the variable containing the list of static ones
+    generate_static_dependencies("${ALIROOT_DEPENDENCIES}" "STATIC_ALIROOT_DEPENDENCIES")
+    target_link_libraries(${MODULE}-static ${STATIC_ALIROOT_DEPENDENCIES} Root)
     set_target_properties(${MODULE}-static PROPERTIES LINK_FLAGS "-Wl,--whole-archive")
 
     # Installation
index 43bb57f..1e0e0b3 100644 (file)
@@ -79,4 +79,20 @@ macro(generate_rootmap LIBNAME LIBDEPS LINKDEF)
     add_custom_target(lib${LIBNAME}.rootmap ALL DEPENDS  ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap)
     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap DESTINATION lib)
     
-endmacro(generate_rootmap)
\ No newline at end of file
+endmacro(generate_rootmap)
+
+# Generate the static dependecies from dynamic list
+# @ shared_list - list of shared libraries
+# @ static_list - the name of the variable that will contain the list of static libraries
+macro(generate_static_dependencies shared_list static_list)
+message(STATUS "list ${shared_list}")
+    set(static_list_tmp "")
+    foreach(shared_lib ${shared_list})
+        set(static_list_tmp ${static_list_tmp} "${shared_lib}-static")
+    endforeach()
+    
+    # create the variable with the name received by the macro
+    set(${static_list} ${static_list_tmp})
+    # set the scope to parent in order to be visible in the parent
+    set(${static_list} PARENT_SCOPE)
+endmacro(generate_static_dependencies)
\ No newline at end of file