]> git.uio.no Git - u/mrichter/AliRoot.git/blame - cmake/CMakeLists.example
CMAKE: CMakeLists.example skeleton
[u/mrichter/AliRoot.git] / cmake / CMakeLists.example
CommitLineData
6cb9cec0 1# **************************************************************************
2# * Copyright(c) 1998-2015, 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############################################################################
17# GENERAL SETTINGS #
18############################################################################
19
20# CMake configuration is controlled through CMakeLists files.
21# - Normally a single CMakeLists files should contain a single target/library.
22# - The file below tries to offer a standard format for generating libraries
23# but full access to cmake functions and utilities is possible.
24# - For any customization please use instructions provided by the minum cmake
25# version 2.8.11
26# http://www.cmake.org/cmake/help/v2.8.11/cmake.html
27
28# Module name
29# Module name translates into library name
30# Ex: set(MODULE ANALYSIS)
31set(MODULE ModuleNameExample)
32
33# Module include folder
34# - Add here all include folders containing headers that belong
35# to this module.
36# - Do not add dependencies here
37# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
38# For more information about include_directories please read
39# documentation for minimum required version:
40# http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:include_directories
41# Ex: include_directories(${AliRoot_SOURCE_DIR}/ANALYS/${MODULE})
42include_directories()
43
44# Additional include folders in alphabetical order except ROOT
45# - ROOT include folders are added by the FindROOT macro
46# - To remove compilation warnings related to dependencies headers
47# please add them as SYSTEM headers.
48# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
49# For more information about include_directories please read
50# documentation for minimum required version:
51# http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:include_directories
52# Ex: include_directories(${AliRoot_SOURCE_DIR}/STEER/STEERBase
53# )
54include_directories(
55 )
56
57# Library sources in alphabetical order
58# - Only these sources will be added to the library
59# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
60# Ex:
61#set(SRCS
62# AliAnalysisDataContainer.cxx
63# AliAnalysisDataSlot.cxx
64# )
65set(SRCS
66 )
67
68# Headers generated from sources list
69# - This list is used mainly during dictionary generating and installation step,
70# all source headers will be installed into $CMAKE_INSTALL_PREFIX/include
71# - Note that it is possible to create your own custom list of headers, to add
72# to the existing one or to delete from it. Change this variable as it suits
73# the purpose of the library, but be sure you do not affect the dictionary
74# generation
75# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
76string(REPLACE ".cxx" ".h" HDRS "${SRCS}")
77
78# Generating the dictionary
79# - The name of the LinkDef has to be "${MODULE}LinkDef.h"
80# - Using custom LinkDef names is for advanced users! If you are not sure
81# how to generate the dictionary please contact aliroot-git-admins@cern.ch
82# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
83get_directory_property(incdirs INCLUDE_DIRECTORIES)
84generate_dictionary("${MODULE}" "${MODULE}LinkDef.h" "${HDRS}" "${incdirs}")
85# End Generation the dictionary
86
87# Seting ROOT and AliRoot dependecies
88# - Any ROOT symbols used in the current sources has to be added to the list of
89# dependecies.
90# - The mapping between ROOT symbols and libraries can be found inside the ROOT
91# map files. If you are not sure which library contains a certain symbol grep
92# the rootmap files for the symbol:
93# Ex:
94# $ cd $ROOTSYS/lib
95# $ grep TSelectorCint *.rootmap
96# libTree.rootmap:Library.TSelectorCint: libTree.so libNet.so libRIO.so libThread.so
97# TSelectorCint symbol belongs to Tree library and we add it to ROOT_DEPENDENCIES
98# Ex: set(ROOT_DEPENDENCIES Core Gpad Hist Net RIO Tree XMLParser)
99# Ex: set(ALIROOT_DEPENDENCIES STEERBase ANALYSIS)
100# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
101set(ROOT_DEPENDENCIES)
102set(ALIROOT_DEPENDENCIES)
103
104# Generating the ROOT map
105# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
106set(LIBDEPS ${ROOT_DEPENDENCIES} ${ALIROOT_DEPENDENCIES})
107generate_rootmap("${MODULE}" "${LIBDEPS}" "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}LinkDef.h")
108# End Generating the ROOT map
109
110############################################################################
111# END GENERAL SETTINGS #
112############################################################################
113
114
115############################################################################
116# COMPILATION AND LINKING CUSTOM FLAGS #
117############################################################################
118
119# Setting custom compilation and linking flags
120# Ex system dependent: Modify the way the library is build
121# if(${CMAKE_SYSTEM} MATCHES Darwin)
122# set(MODULE_LINK_FLAGS "-undefined dynamic_lookup")
123# endif(${CMAKE_SYSTEM} MATCHES Darwin)
124# - MODULE_COMPILE_FLAGS and MODULE_LINK_FLAGS will be used later for library
125# generation
126# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
127set(MODULE_COMPILE_FLAGS )
128set(MODULE_LINK_FLAGS )
129
130############################################################################
131# END COMPILATION AND LINKING CUSTOM FLAGS #
132############################################################################
133
134
135############################################################################
136# LIBRARY CREATION #
137############################################################################
138
139# Two options are availabe when creating the libraries:
140# - dynamic only libraries
141# - dinamic and static libraries
142# Static libraries are by used the DAs. If you are sure the library will
143# be used by the DAs it is mandatory to create the static version.
144# - Use only one of the options at a time, DO NOT FORGET to delete the content
145# that is not used
146
147############################################################################
148## 1. DYNAMIC LIBRARY CREATION - NO STATIC LIBRARY NEEDED #
149############################################################################
150
151# Create the dynamic library
152# - DELETE if static libraries are neded and follow Dynamic/Static libraries
153# instructions
154# - DELETE the dynamic/static block if only dynamic libraries are needed
155# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
156add_library(${MODULE} SHARED ${SRCS} G__${MODULE}.cxx)
157
158# Additional compilation flags
159set_target_properties(${MODULE} PROPERTIES COMPILE_FLAGS ${MODULE_COMPILE_FLAGS})
160
161# Additional linking flags
162set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${MODULE_LINK_FLAGS})
163
164# Link library to dependecies
165target_link_libraries(${MODULE} ${LIBDEPS})
166
167############################################################################
168## END DYNAMIC LIBRARY CREATION - NO STATIC LIBRARY NEEDED #
169############################################################################
170
171
172############################################################################
173## 2. DYNAMIC/STATIC LIBRARY CREATION #
174############################################################################
175
176# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
177# - DELETE if no static libraries are needed
178# - Create an object to be reused in case of static libraries
179# otherwise the sources will be compiled twice
180add_library(${MODULE}-object OBJECT ${SRCS} G__${MODULE}.cxx)
181
182# - Add a library to the project using the object
183add_library(${MODULE} SHARED $<TARGET_OBJECTS:${MODULE}-object>)
184
185# Setting the correct headers for the object as gathered from the dependencies
186target_include_directories(${MODULE}-object PUBLIC $<TARGET_PROPERTY:${MODULE},INCLUDE_DIRECTORIES>)
187set_target_properties(${MODULE}-object PROPERTIES COMPILE_DEFINITIONS $<TARGET_PROPERTY:${MODULE},COMPILE_DEFINITIONS>)
188
189# Additional compilation flags
190set_target_properties(${MODULE}-object PROPERTIES COMPILE_FLAGS "")
191
192# Additional linking flags
193set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${MODULE_LINK_FLAGS})
194
195# Link library to dependecies
196target_link_libraries(${MODULE} ${LIBDEPS})
197
198# Create the static library only if ALIROOT_STATIC variable is set
199# ALIROOT_STATIC is automatically set by the DA flag
200if(ALIROOT_STATIC)
201 add_library(${MODULE}-static STATIC $<TARGET_OBJECTS:${MODULE}-object>)
202 set_target_properties(${MODULE}-static PROPERTIES OUTPUT_NAME ${MODULE})
203
204 # list of shared dependencies / the name of the variable containing the list of static ones
205 generate_static_dependencies("${ALIROOT_DEPENDENCIES}" "STATIC_ALIROOT_DEPENDENCIES")
206 target_link_libraries(${MODULE}-static ${STATIC_ALIROOT_DEPENDENCIES} Root RootExtra)
207
208 # Public include folders that will be propagated to the dependecies
209 target_include_directories(${MODULE}-static PUBLIC ${incdirs})
210
211 set_target_properties(${MODULE}-static PROPERTIES LINK_FLAGS "-Wl,--whole-archive")
212
213 # Installation
214 install(TARGETS ${MODULE}-static
215 ARCHIVE DESTINATION lib
216 LIBRARY DESTINATION lib)
217endif(ALIROOT_STATIC)
218
219############################################################################
220## END DYNAMIC/STATIC LIBRARY CREATION #
221############################################################################
222
223############################################################################
224# END LIBRARY CREATION #
225############################################################################
226
227############################################################################
228# INSTALLATION #
229############################################################################
230
231# The installation step is copying files needed at runtime into CMAKE_INSTALL_PREFIX
232# DO NOT forget to install all macros needed to run Grid jobs or any files that are
233# needed as input.
234# - If you are not sure how to proceed please contact aliroot-git-admins@cern.ch
235
236# Library installation into $CMAKE_INSTALL_PREFIX/lib
237install(TARGETS ${MODULE}
238 ARCHIVE DESTINATION lib
239 LIBRARY DESTINATION lib)
240
241# Header installation into $CMAKE_INSTALL_PREFIX/include
242install(FILES ${HDRS} DESTINATION include)
243
244# Macros installation
245install(DIRECTORY macros DESTINATION ${MODULE})