]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
generate_shared_library and generate_static_library macros
authoragrigora <alina.grigoras@cern.ch>
Wed, 3 Dec 2014 15:33:28 +0000 (16:33 +0100)
committeragrigora <alina.grigoras@cern.ch>
Mon, 15 Dec 2014 12:52:05 +0000 (13:52 +0100)
RAW/RAWDatabase/CMakeLists.txt
cmake/CMakeALICE.cmake

index 378f0256f69d4fda172acb421cb22e3001b65f41..3638b567f81f2341e80e239ceeee8e6d17179879 100644 (file)
 # * provided "as is" without express or implied warranty.                  *
 # **************************************************************************
 
-# Module
+# Mandatory fields, set empty if not needed
+# MODULE - target name
+# MODULE_SRCS - list of sources that belong to the library
+# MODULE_HDRS - list of headers that belong to the library
+# MODULE_HDRS_INSTALL - list of headers that will be installed
+# MODULE_INCLUDES - list of include directories
+#                   ROOT and current folder are taken by default
+#                   To add extra include folders use either 
+#                       - include_directories(${MODULE} FOLDER)
+#                       - target_include_directories(${MODULE}-object FOLDER)
+# MODULE_ROOT_DEPENDENCIES
+# MODULE_ALIROOT_DEPENDENCIES
+# MODULE_COMPILE_FLAGS - compilation flags for the ${MODULE}-object target
+# MODULE_LINK_FLAGS - linking flags for ${MODULE} target
+#                   - other flags accesible thorough standard cmake procedures
+#
+# Target/directory properties are accesible thorough cmake standard procedures
+# Target object name = ${MODULE}-object
+# Target library name = ${MODULE}
+# Shared and static library targets are using the same object target
+
+
+# Module name
 set(MODULE RAWDatabase)
 
-# Module include folder
-include_directories(${AliRoot_SOURCE_DIR}/RAW/${MODULE})
-
-# Additional include folders in alphabetical order except ROOT
-include_directories(${ROOT_INCLUDE_DIRS}
-                    ${AliRoot_SOURCE_DIR}/STEER/ESD
-                    ${AliRoot_SOURCE_DIR}/STEER/STEERBase
-                   )
-
 # Sources in alphabetical order
-set(SRCS
+set(MODULE_SRCS
     AliAltroMapping.cxx
     AliCaloAltroMapping.cxx
     AliRawDataArray.cxx
@@ -45,44 +58,30 @@ set(SRCS
    )
 
 # Headers from sources
-string(REPLACE ".cxx" ".h" HDRS "${SRCS}")
+string(REPLACE ".cxx" ".h" MODULE_HDRS "${MODULE_SRCS}")
 
 # Extra headers in alphabetical order
-set(HDRS ${HDRS}
+set(MODULE_HDRS ${MODULE_HDRS}
     AliRawDataHeader.h
     AliRawDataHeaderV3.h
     AliRawEventHeaderVersions.h
    )
 
-# Generate the dictionary
-# It will create G_ARG1.cxx and G_ARG1.h / ARG1 = function first argument
-get_directory_property(incdirs INCLUDE_DIRECTORIES)
-generate_dictionary("${MODULE}" "${MODULE}LinkDef.h" "${HDRS}" "${incdirs}")
-
-set(ROOT_DEPENDENCIES Core Hist RIO)
-set(ALIROOT_DEPENDENCIES ESD STEERBase)
-
-# Generate the ROOT map
-# Dependecies
-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(${MODULE}-object OBJECT ${SRCS} G__${MODULE}.cxx)
-# Follow headers dependencies
-add_dependencies(${MODULE}-object ${ALIROOT_DEPENDENCIES})
-# Add a library to the project using the object
-add_library(${MODULE} SHARED $<TARGET_OBJECTS:RAWDatabase-object>)
-target_link_libraries(${MODULE} ${ALIROOT_DEPENDENCIES} ${ROOT_DEPENDENCIES})
+# List of headers to be installed
+set(MODULE_HDRS_INSTALL ${MODULE_HDRS})
 
-# Setting the correct headers for the object as gathered from the dependencies
-target_include_directories(${MODULE}-object PUBLIC $<TARGET_PROPERTY:${MODULE},INCLUDE_DIRECTORIES>)
-set_target_properties(${MODULE}-object PROPERTIES COMPILE_DEFINITIONS $<TARGET_PROPERTY:${MODULE},COMPILE_DEFINITIONS>)
+# List of include folders
+set(MODULE_INCLUDES
+        STEER/ESD
+        STEER/STEERBase
+   )
 
-# Public include folders that will be propagated to the dependecies
-target_include_directories(${MODULE} PUBLIC ${incdirs})
+# Root dependecies - please solve all symbols by searching them inside the *.rootmap files
+set(MODULE_ROOT_DEPENDENCIES Core Hist RIO)
+# AliRoot dependencies
+set(MODULE_ALIROOT_DEPENDENCIES ESD STEERBase)
 
+# Compilation and linking flags
 set(MODULE_COMPILE_FLAGS)
 set(MODULE_LINK_FLAGS)
 
@@ -99,34 +98,10 @@ if(${CMAKE_SYSTEM} MATCHES Darwin)
     set(MODULE_LINK_FLAGS "-undefined dynamic_lookup ${MODULE_LINK_FLAGS}")
 endif(${CMAKE_SYSTEM} MATCHES Darwin)
 
-# Setting compilation flags for the object
-set_target_properties(${MODULE}-object PROPERTIES COMPILE_FLAGS "${MODULE_COMPILE_FLAGS}")
-# Setting the linking flags for the library
-set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "${MODULE_LINK_FLAGS}")
-
-# Installation
-install(TARGETS ${MODULE}
-        ARCHIVE DESTINATION lib
-        LIBRARY DESTINATION lib)
-
-install(FILES ${HDRS} DESTINATION include)
+# Generating the static library
+generate_shared_library()
 
 # Static version if DA enabled
 if(ALIROOT_STATIC)
-    add_library(${MODULE}-static STATIC $<TARGET_OBJECTS:RAWDatabase-object>)
-    
-    # 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)
-    
-    # Public include folders that will be propagated to the dependecies
-    target_include_directories(${MODULE}-static PUBLIC ${incdirs})
-
-    set_target_properties(${MODULE}-static PROPERTIES OUTPUT_NAME ${MODULE})
-    set_target_properties(${MODULE}-static PROPERTIES LINK_FLAGS "-Wl,--whole-archive")
-
-    # Installation
-    install(TARGETS ${MODULE}-static
-            ARCHIVE DESTINATION lib
-            LIBRARY DESTINATION lib)
+    generate_static_library()
 endif(ALIROOT_STATIC)
index a99f2d7c8042d3f3b7f1b4632264b4b62640b4a0..89ddfd4466fc3eab7a1869b9275c25204e3421b1 100644 (file)
@@ -15,9 +15,9 @@
 
 # General purpose functions
 
-#########################
+###########################################################################
 # ROOT utilities
-#########################
+###########################################################################
 
 # Generation of the dictionaries
 # @DNAME  Dictionary name
@@ -85,9 +85,51 @@ macro(generate_rootmap LIBNAME LIBDEPS LINKDEF)
     
 endmacro(generate_rootmap)
 
-#########################
-# Static utilities
-#########################
+###########################################################################
+# Shared librarires utilities
+###########################################################################
+macro(generate_shared_library)
+    # Generate the dictionary
+    # It will create G_ARG1.cxx and G_ARG1.h / ARG1 = function first argument
+    get_directory_property(incdirs INCLUDE_DIRECTORIES)
+    set(incdirs ${MODULE_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} ${incdirs})
+    generate_dictionary("${MODULE}" "${MODULE}LinkDef.h" "${MODULE_HDRS}" "${incdirs}")
+
+    # Generate the ROOT map
+    # Dependecies
+    set(MODULE_LIBDEPS ${MODULE_ALIROOT_DEPENDENCIES} ${MODULE_ROOT_DEPENDENCIES})
+    generate_rootmap("${MODULE}" "${MODULE_LIBDEPS}" "${MODULE}LinkDef.h")
+
+    # Create an object to be reused in case of static libraries 
+    # Otherwise the sources will be compiled twice
+    add_library(${MODULE}-object OBJECT ${SRCS} G__${MODULE}.cxx)
+    # Add a library to the project using the object
+    add_library(${MODULE} SHARED $<TARGET_OBJECTS:${MODULE}-object>)
+    target_link_libraries(${MODULE} ${MODULE_LIBDEPS})
+
+    # Setting the correct headers for the object as gathered from the dependencies
+    target_include_directories(${MODULE}-object PUBLIC $<TARGET_PROPERTY:${MODULE},INCLUDE_DIRECTORIES>)
+    set_target_properties(${MODULE}-object PROPERTIES COMPILE_DEFINITIONS $<TARGET_PROPERTY:${MODULE},COMPILE_DEFINITIONS>)
+
+    # Public include folders that will be propagated to the dependecies
+    target_include_directories(${MODULE} PUBLIC ${incdirs})
+
+    # Setting compilation flags for the object
+    set_target_properties(${MODULE}-object PROPERTIES COMPILE_FLAGS "${MODULE_COMPILE_FLAGS}")
+    # Setting the linking flags for the library
+    set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "${MODULE_LINK_FLAGS}")
+
+    # Installation
+    install(TARGETS ${MODULE}
+            ARCHIVE DESTINATION lib
+            LIBRARY DESTINATION lib)
+
+    install(FILES ${MODULE_HDRS_INSTALL} DESTINATION include)
+endmacro()
+
+###########################################################################
+# Static libraries utilities
+###########################################################################
 
 # Generate the static dependecies from dynamic list
 # @ shared_list - list of shared libraries
@@ -104,9 +146,28 @@ macro(generate_static_dependencies shared_list static_list)
     set(${static_list} PARENT_SCOPE)
 endmacro(generate_static_dependencies)
 
-#########################
+macro(generate_static_library)
+    add_library(${MODULE}-static STATIC $<TARGET_OBJECTS:${MODULE}-object>)
+    
+    # list of shared dependencies / the name of the variable containing the list of static ones
+    generate_static_dependencies("${MODULE_ALIROOT_DEPENDENCIES}" "STATIC_ALIROOT_DEPENDENCIES")
+    target_link_libraries(${MODULE}-static ${STATIC_ALIROOT_DEPENDENCIES} Root RootExtra)
+    
+    # Public include folders that will be propagated to the dependecies
+    target_include_directories(${MODULE}-static PUBLIC ${incdirs})
+
+    set_target_properties(${MODULE}-static PROPERTIES OUTPUT_NAME ${MODULE})
+    set_target_properties(${MODULE}-static PROPERTIES LINK_FLAGS "-Wl,--whole-archive")
+
+    # Installation
+    install(TARGETS ${MODULE}-static
+            ARCHIVE DESTINATION lib
+            LIBRARY DESTINATION lib)
+endmacro()
+
+###########################################################################
 # DA utilities
-#########################
+###########################################################################
 
 # Extract the first comment from a DA file
 # Find the position for first /* and */ and extract the substring