Fix for DA
[u/mrichter/AliRoot.git] / cmake / CMakeDA.cmake
index 7e8e22ac702864204af036a723883575cb02625f..4255e5243fc83eeb2c40f8f31e7643edf5bd8014 100644 (file)
@@ -1,10 +1,20 @@
-cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
+cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR)
 
 # -----------Utilities--------------------
 
 #list of detectors 
 set(ONLINEDETECTORS SPD SDD SSD TPC TRD TOF HMP PHS CPV PMD MCH MTR FMD T00 V00 ZDC ACO TRI EMC HLT TST GRP)
 
+function(expand output input)
+    string(REGEX MATCH "\\\${[^}]*}" m "${input}")
+    while(m)
+        string(REGEX REPLACE "\\\${(.*)}" "\\1" v "${m}")
+        string(REPLACE "\${${v}}" "${${v}}" input "${input}")
+        string(REGEX MATCH "\\\${[^}]*}" m "${input}")
+    endwhile()
+    set("${output}" "${input}" PARENT_SCOPE)
+endfunction()
+
 #function to get module for detector
 function (detector_module _module detector)
   #Map of online detectors to DA in pairs of ONLINEDETECTORNAME DAMODULE
@@ -45,62 +55,74 @@ endfunction()
 # ----------Common stuff-------------------
 
 file(GLOB_RECURSE _dafiles $ENV{ALICE_ROOT}/*da.cxx)
-set(DAINSTALL "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
+set(DAINSTALL "$ENV{ALICE_INSTALL}/DA")
 
 file(MAKE_DIRECTORY ${DAINSTALL})
 
-#**Set compiler flags
-
+string (REPLACE "-pedantic-errors" "" CXXFLAGS ${CXXFLAGS})
 
-find_program(AMORE amore-config)
-#temporary
-find_program(DATE date-config)
-find_program(ROOT_CONFIG root-config)
 find_program(XML2 xml2-config)
 
-if(AMORE)
-  execute_process(COMMAND ${AMORE} --cflags --includes OUTPUT_VARIABLE AMOREFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
-  #**Set compiler flags
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AMOREFLAGS}")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${AMOREFLAGS}")
-  
-  execute_process(COMMAND ${AMORE} --ldflags-da-static OUTPUT_VARIABLE _lddaflags OUTPUT_STRIP_TRAILING_WHITESPACE)
-  string(REGEX REPLACE "\n" " " _lddaflags ${_lddaflags})
-  execute_process(COMMAND ${DATE} --rcproxylibs OUTPUT_VARIABLE _rcproxylib OUTPUT_STRIP_TRAILING_WHITESPACE)
-  set(AMOREDALIBS "-static ${_lddaflags} ${_rcproxylib}")      
+if(AMORE_FOUND)
+  #Set compiler flags
+  set(CXXFLAGS "${CXXFLAGS} ${AMOREFLAGS}")
+  set(CFLAGS "${CFLAGS} ${AMOREFLAGS}")
+  set(CINTFLAGS "${CINTFLAGS} ${AMOREFLAGS}")
 else()
   set(AMORELIBS)
-endif(AMORE)
+endif(AMORE_FOUND)
 
-execute_process(COMMAND ${ROOT_CONFIG} --libdir OUTPUT_VARIABLE ROOTLIBDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
 execute_process(COMMAND ${XML2} --libs OUTPUT_VARIABLE _xml2libs OUTPUT_STRIP_TRAILING_WHITESPACE)
-execute_process(COMMAND ${DATE} --monitorlibs=noshift OUTPUT_VARIABLE MONITORLIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
+execute_process(COMMAND ${DATE_CONFIG} --monitorlibs=noshift OUTPUT_VARIABLE MONITORLIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
 
+separate_arguments(MONITORLIBS)
 
-string(REGEX REPLACE " " ";" MONITORLIBS ${MONITORLIBS})
 set(SYSLIBS -ldl -lpthread ${_xml2libs})
+
+
 set(EXTRAROOTLIB "libRootExtra.a")
+
 file(GLOB _extraroot "$ENV{ROOTSYS}/montercarlo/vmc/src/*.o" "$ENV{ROOTSYS}/tree/treeplayer/src/*.o" "$ENV{ROOTSYS}/io/xmlparser/src/*.o" "$ENV{ROOTSYS}/math/minuit2/src/*.o")
-#message("${_extraroot}")
 
+add_library(${EXTRAROOTLIB} STATIC ${_extraroot})      
+set_target_properties(${EXTRAROOTLIB} PROPERTIES LINKER_LANGUAGE CXX)
 
-#add_custom_target(TARGET ${EXTRAROOTLIB} COMMAND ${CMAKE_AR} r $ENV{ALICE_INSTALL}/lib/tgt_$ENV{ALICE_TARGET}/${EXTRAROOTLIB} ${_extraroot} COMMAND pwd)
+set(DAQDALIB_PATH $ENV{DAQDALIB_PATH}) 
+if(DAQDALIB_PATH)
+  set(DAQDADIR "${DAQDALIB_PATH}")
+else()
+  set(DAQDADIR "$ENV{ALICE}/daqDAlib")
+endif(DAQDALIB_PATH)
+set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
 
-message("RAW SRCS ${RAWDatabase_SRC}")
+include_directories(${DAQDADIR} RAW include STEER)
+include_directories(SYSTEM ${ROOTINCDIR})
 
 # ----------Create All Valid targets---------
          
 foreach(detector ${ONLINEDETECTORS} )
-  
-  #ALIROOTALIBS
-  set(ALIROOTALIBS)
-  list(APPEND ALIROOTALIBS RAWDatabase_a RAWDatarec_a RAWDatasim_a STEERBase_a STEER_a CDB_a ESD_a STAT_a AOD_a )
 
   set(ONLINEDETECTORNAME ${detector})
+
   detector_module(DAMODULE ${ONLINEDETECTORNAME})
+
   detector_subda(SUBDAMODULE ${ONLINEDETECTORNAME})
+  
+  #ALIROOTALIBS
+
+  set(ALIROOTALIBS)
+
+  list(APPEND ALIROOTALIBS RAWDatabase-static RAWDatarec-static RAWDatasim-static STEERBase-static STEER-static CDB-static ESD-static STAT-static AOD-static )
+
+  expand(ALIROOTALIBS2 "\${${DAMODULE}ALIBS}")
+  expand(DAINCDIRS "\${${DAMODULE}INC}")
+  list(APPEND ALIROOTALIBS ${ALIROOTALIBS2})
+  
+  include_directories(${DAMODULE} ${SUBDIR} ${DAINCDIRS})
 #Get detector algorithms for this detector
+
   foreach(dafile ${_dafiles})
+
        string(REGEX MATCH "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}" match ${dafile})
 #Found a valid target name
        if(match)
@@ -111,14 +133,13 @@ foreach(detector ${ONLINEDETECTORS} )
          else()
            set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}")
          endif(DANAME)
-          message("${DATARGETNAME}")
 
          set(DATARGETDIR "${DAINSTALL}/${DAMODULE}/tgt_$ENV{ALICE_TARGET}")
          file(MAKE_DIRECTORY ${DATARGETDIR})
 
          set(DASRC "${DAMODULE}/${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx")
          set(DALIB "${DAMODULE}${SUBDAMODULE}${DANAME}DA")
-         set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da")
+         set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe")
          
        # DAVERSION
          execute_process(COMMAND svn info $ENV{ALICE_ROOT}/${DASRC} OUTPUT_VARIABLE _daversion OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -136,45 +157,9 @@ foreach(detector ${ONLINEDETECTORS} )
          set(DATAR "${DATARGETDIR}/${DAARC}.src.tar.gz")
          set(DASPECFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec")
          set(DAMAKEFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.make")
-         set(DAQDALIB_PATH $ENV{DAQDALIB_PATH})        
-         if(DAQDALIB_PATH)
-           set(DAQDADIR "${DAQDALIB_PATH}")
-         else()
-           set(DAQDADIR "$ENV{ALICE}/daqDAlib")
-         endif(DAQDALIB_PATH)
-
-         set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
 
-#        message(${DAVERSION})
-#        message(${DAALIROOTRELEASE})
 
-         ##**set(EXTRADAMODULE ALIROOTALIBS
-#        file(READ "$ENV{ALICE_ROOT}/${DAMODULE}/CMake_lib${DAMODULE}.txt" _modulesrc )
-#        message("${_modulesrc}")
-#        string(REGEX MATCHALL "[^ ]+\\.cxx" DAMODULE_SRC ${_modulesrc})
-         
-#        set(MODULEALIB ${DAMODULE}_SRC)
-#        
-         
-#        message("MODULE SRCS - ${DAMODULE_SRC}")
-#        string(REGEX MATCH "[^\n]*" 
-#        list(APPEND ALIROOTALIBS ${DAMODULE_SRC})
-
-# Super Duper Hack :D
-         file(GLOB _damodule "$ENV{ALICE_ROOT}/${DAMODULE}/lib${DAMODULE}*.pkg" )
-         
-         message(${_damodule})
-         foreach(_submodule ${_damodule})
-           string(REGEX REPLACE ".*lib(${DAMODULE}.*)" "\\1" _submodule ${_submodule})
-           string(REGEX REPLACE "\\.pkg" "_a" _submodule ${_submodule})
-           list(APPEND ALIROOTALIBS "${_submodule}")     
-           message("Adding ${_submodule}")
-         endforeach(_submodule)
-         
-#      file(WRITE "$ENV{ALICE_INSTALL}/tmp" "list(APPEND ALIROOTALIBS ${DAMODULE}-all)")
-#        include("$ENV{ALICE_INSTALL}/tmp")
-
-         list(REMOVE_DUPLICATES ALIROOTALIBS)
+          
          if(EXTRADAMODULE)
            ##**set
          endif(EXTRADAMODULE)
@@ -194,49 +179,40 @@ foreach(detector ${ONLINEDETECTORS} )
           message(FATAL_ERROR "SRC FILE MISSING")
          endif(NOT _dasrc)
 
-#        message("${_dasrc}")
-#        message("DACONTACT - ${DACONTACT}")
-#        message("DALINKPAGE - ${DALINKPAGE}")
-#        message("DAREFFUN - ${DAREFFUN}")
-#        message("DARUNTYPE - ${DARUNTYPE}")
-#        message("DATYPE - ${DATYPE}")
-#        message("DANUMBEROFEVENTS - ${DANUMBEROFEVENTS}")
-#        message("DAINPUTFILES - ${DAINPUTFILES}")
-#        message("DAOUTPUTFILES - ${DAOUTPUTFILES}")
-#        message("DATRIGGERTYPE - ${DATRIGGERTYPE}")
-
 #----------- Targets ----------------------
 
-         set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
+         set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
          set(CMAKE_C_FLAGS "${CFLAGS}")
-         set(CMAKE_Fortran_FLAGS "${FFLAGS}")
+         set(CMAKE_Fortran_FLAGS ${FFLAGS})
          set(CMAKE_SHARED_LINKER_FLAGS ${SOFLAGS}) 
          set(CMAKE_MODULE_LINKER_FLAGS ${LDFLAGS})
 
-         include_directories(${MODULES} ${DAQDADIR} )
-         include_directories(SYSTEM ${ROOTINCDIR})
          set(ZIP)
          foreach(_lib ${ALIROOTALIBS})
-          string(REGEX REPLACE "-all" "_a" _lib ${_lib})
+          string(REGEX REPLACE "-static" "" _lib ${_lib})
           list(APPEND ZIP && ar x "../lib${_lib}.a")
          endforeach(_lib)
-         list (APPEND ZIP && ar r "../${DALIB}.a" "*.o")
-         add_custom_target("${DALIB}_x" rm -rf junk && mkdir -p junk 
-                               COMMAND cd junk ${ZIP}
-                               COMMAND cd ../ && rm -rf junk
+         list (APPEND ZIP && ar r "../lib${DALIB}.a" "*.o")
+
+         add_custom_target( ${DALIB} COMMAND rm -rf junk${DAEXE} && mkdir -p junk${DAEXE} 
+                               COMMAND cd junk${DAEXE} ${ZIP}
+                               COMMAND cd ../ && rm -rf junk${DAEXE}
                                DEPENDS ${ALIROOTALIBS}
                                WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
+         add_custom_command( TARGET clean
+                            COMMAND rm -rf junk${DAEXE}
+                            WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
+           
 
-         add_custom_target(${DATARGETNAME} DEPENDS ${DAEXE} )
-         add_executable(${DAEXE} ${DASRC} )
+         add_custom_target(${DATARGETNAME})
+         add_executable(${DAEXE} ${DASRC})
          set_property(TARGET ${DAEXE} PROPERTY EXCLUDE_FROM_ALL TRUE)
-         add_dependencies(${DAEXE} ${DALIB}_x)
-         target_link_libraries(${DAEXE} "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DALIB}.a" ${EXTRAROOTLIB} "${ROOTLIBDIR}/libRoot.a" "${ROOTLIBDIR}/libfreetype.a" "${ROOTLIBDIR}/libpcre.a" ${SYSLIBS} ${DAQDALIB} ${MONITORLIBS} ${AMOREDALIBS})
-         add_custom_command(TARGET ${DAEXE} 
-                       PRE_LINK
-                       COMMAND ${CMAKE_AR} r ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EXTRAROOTLIB} ${_extraroot})
-#        message("${DALIB} --> ${ALIROOTALIBS}")
+         add_dependencies(${DAEXE} ${DALIB})
+         add_dependencies(DA-all ${DATARGETNAME})
+         target_link_libraries(${DAEXE} "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${DALIB}.a" ${EXTRAROOTLIB} "${ROOTLIBDIR}/libRoot.a" "${ROOTLIBDIR}/libfreetype.a" "${ROOTLIBDIR}/libpcre.a" ${SYSLIBS} ${DAQDALIB} ${MONITORLIBS} ${AMOREDALIBS})
+         add_dependencies(${DATARGETNAME} ${DAEXE})
+         
+
        endif(match)
   endforeach(dafile)
 endforeach(detector)