Cleanup of the linking to avoid problems on Mac
[u/mrichter/AliRoot.git] / RAW / alimdc / CMakeLists.txt
1 # **************************************************************************
2 # * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3 # *                                                                        *
4 # * Author: The ALICE Off-line Project.                                    *
5 # * Contributors are mentioned in the code where appropriate.              *
6 # *                                                                        *
7 # * Permission to use, copy, modify and distribute this software and its   *
8 # * documentation strictly for non-commercial purposes is hereby granted   *
9 # * without fee, provided that the above copyright notice appears in all   *
10 # * copies and that both the copyright notice and this permission notice   *
11 # * appear in the supporting documentation. The authors make no claims     *
12 # * about the suitability of this software for any purpose. It is          *
13 # * provided "as is" without express or implied warranty.                  *
14 # **************************************************************************
15
16 # Module
17 set (MODULE alimdc)
18 include_directories(${AliRoot_SOURCE_DIR}/${MODULE})
19
20 # Aditional include folders in alphabetical order except ROOT
21 include_directories(${ROOT_INCLUDE_DIRS} 
22                     ${AliRoot_SOURCE_DIR}/RAW/MDC
23                     ${AliRoot_SOURCE_DIR}/RAW/RAWDatabase
24                     ${AliRoot_SOURCE_DIR}/RAW/RAWDatarec
25                     ${AliRoot_SOURCE_DIR}/STEER/ESD
26                     ${AliRoot_SOURCE_DIR}/STEER/STEERBase
27                    )
28
29 # Create an object to be reused in case of static libraries 
30 # Otherwise the sources will be compiled twice
31 add_library(${MODULE}-object OBJECT alimdc_main.cxx)
32 # Add a library to the project using the object
33 add_executable(${MODULE} $<TARGET_OBJECTS:${MODULE}-object>)
34 target_link_libraries(${MODULE} STEERBase ESD MDC RAWDatabase RAWDatarec)
35
36 # Compile and link flags
37 set(MODULE_COMPILE_FLAGS)
38 set(MODULE_LINK_FLAGS)
39
40 if(DATE_FOUND)
41     set(MODULE_COMPILE_FLAGS "${DATE_CFLAGS}")
42     set(MODULE_LINK_FLAGS "${DATE_LDFLAGS} ${DATE_LIBS}")
43 endif(DATE_FOUND)
44
45 # Setting target compile and linking flags
46 set_target_properties(${MODULE} PROPERTIES COMPILE_FLAGS "${MODULE_COMPILE_FLAGS}")
47 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "${MODULE_LINK_FLAGS}")
48
49 # Installation
50 install(TARGETS ${MODULE} RUNTIME DESTINATION bin)
51
52 # Creating the AliMDC static library and the rpm
53 if(MDCRPM)
54     add_library(AliMDC STATIC $<TARGET_OBJECTS:${MODULE}-object>)
55
56     # list of shared dependencies / the name of the variable containing the list of static ones
57     generate_static_dependencies("${ALIROOT_DEPENDENCIES}" "STATIC_ALIROOT_DEPENDENCIES")
58     target_link_libraries(AliMDC ${STATIC_ALIROOT_DEPENDENCIES} Root RootExtra)
59
60     set_target_properties(AliMDC PROPERTIES LINK_FLAGS "-Wl,--whole-archive")
61
62     # Installation
63     install(TARGETS AliMDC
64             ARCHIVE DESTINATION lib
65             LIBRARY DESTINATION lib)
66
67     configure_file("alimdc.spec.in" "alimdc.spec" @ONLY)
68
69     add_custom_command(TARGET alimdc POST_BUILD
70                        COMMAND mkdir ARGS -p alimdc-rpm/root/opt/alimdc/lib
71                        COMMAND mkdir ARGS -p alimdc-rpm/root/opt/alimdc/include
72                        COMMAND cp ARGS libAliMDC.a alimdc-rpm/root/opt/alimdc/lib
73                        COMMAND cp ARGS ${ROOT_LIBDIR}/libRoot.a alimdc-rpm/root/opt/alimdc/lib/
74                        COMMAND cp ARGS ${CMAKE_BINARY_DIR}/libRootExtra.a alimdc-rpm/root/opt/alimdc/lib/
75                        COMMAND cp ARGS ${ROOT_LIBDIR}/libpcre.a alimdc-rpm/root/opt/alimdc/lib/
76                        COMMAND cp ARGS ${ROOT_LIBDIR}/liblzma.a alimdc-rpm/root/opt/alimdc/lib/
77                        COMMAND cp ARGS ${ROOT_LIBDIR}/libfreetype.a alimdc-rpm/root/opt/alimdc/lib/
78                        COMMAND cp ARGS ${CMAKE_BINARY_DIR}/libRootExtra.a alimdc-rpm/root/opt/alimdc/lib/
79                        COMMAND cp ARGS ${AliRoot_SOURCE_DIR}/RAW/MDC/mdc.h alimdc-rpm/root/opt/alimdc/include
80                        COMMAND rpmbuild ARGS --verbose --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}/alimdc-rpm" --define "%buildroot ${CMAKE_CURRENT_BINARY_DIR}/alimdc-rpm/root" -bb alimdc.spec
81                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
82                        COMMENT "RPM creation for AliMDC"
83     )
84     
85     # make clean will remove also the rpm folder
86     # Retrive the current list of file to be deleted - set_directory_property is overwriting, not adding to the list
87     get_directory_property(_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
88     set(_clean_files alimdc-rpm ${_clean_files})
89     set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${_clean_files}")
90     
91     # install RPM into $CMAKE_INSTALL_PREFIX/darpms
92     install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/alimdc-rpm/RPMS/ DESTINATION mdcrpm PATTERN "\\.rpm")
93
94 endif(MDCRPM)