Converting PWG/TRD to native cmake
[u/mrichter/AliRoot.git] / STARLIGHT / starlight / CMakeLists.txt.old
CommitLineData
a61a4805 1###########################################################################
2#
3# Copyright 2010
4#
5# This file is part of Starlight.
6#
7# Starlight is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# Starlight is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Starlight. If not, see <http://www.gnu.org/licenses/>.
19#
20###########################################################################
21#
22# File and Version Information:
23# $Rev:: 186 $: revision of last commit
24# $Author:: jnystrand $: author of last commit
25# $Date:: 2014-09-12 02:39:02 +0200 #$: date of last commit
26#
27# Description:
28# Starlight build file
29#
30#
31###########################################################################
32
33
34# check if cmake has the required version
35cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
36
37
38# set verbosity
39set(CMAKE_VERBOSE_MAKEFILE 0) # if set to 1 compile and link commands are displayed during build
40# the same effect can be achieved by calling 'make VERBOSE=1'
41
42
43# The version number. 9999 indicates trunk
44set (Starlight_VERSION_MAJOR 9999)
45set (Starlight_VERSION_MINOR 1)
46set (Starlight_VERSION_MINOR_MINOR 0)
47
48# define project
49project(starlight)
50find_package (Threads)
51
52# load some common cmake macros
53# set path, where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
54set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
55message(STATUS "Using cmake module path '${CMAKE_MODULE_PATH}'")
56include(CommonMacros)
57
58
59# force out-of-source builds.
60enforce_out_of_source_build()
61
62
63# warn user if system is not UNIX
64if(NOT UNIX)
65 message(FATAL_ERROR "This is an unsupported system.")
66endif()
67message(STATUS "Detected host system '${CMAKE_HOST_SYSTEM_NAME}' version '${CMAKE_HOST_SYSTEM_VERSION}' architecture '${CMAKE_HOST_SYSTEM_PROCESSOR}'")
68message(STATUS "Compiling for system '${CMAKE_SYSTEM_NAME}' version '${CMAKE_SYSTEM_VERSION}' architecture '${CMAKE_SYSTEM_PROCESSOR}'")
69
70option (CPP11 "Enable compilation with C++11 features" OFF)
71
72# define build types
73# set a default build type for single-configuration CMake generators, if no build type is set.
74set(CMAKE_BUILD_TYPE Debug)
75if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
76 message(STATUS "No build type was specified. Setting build type to 'Release'.")
77 set(CMAKE_BUILD_TYPE Release)
78endif()
79# common compiler flags
80if (CMAKE_COMPILER_IS_GNUCC)
81 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
82 message(STATUS "GCC_VERSTION")
83 message(STATUS ${GCC_VERSION})
84 if (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)
85 message(STATUS "GCC_VERSION>=4.6")
86 if(CPP11)
87 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wno-error=unused-but-set-variable -Wno-error=unused-but-set-parameter -std=c++11")
88 message(STATUS "Enabling usage of C++11 features")
89 else()
90 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wno-error=unused-but-set-variable -Wno-error=unused-but-set-parameter")
91 endif()
92 else()
93 message(STATUS "GCC_VERSION<4.6")
94 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror")
95 if(CPP11)
96 message(WARNING "C++11 feautures not supported for your compiler")
97 endif()
98 endif()
99else()
100 message(STATUS "Not GCC")
101 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror")
102 if(CPP11)
103 message(WARNING "C++11 feautures not supported for your compiler")
104 endif()
105endif()
106# flags for specific build types
107set(CMAKE_CXX_FLAGS_DEBUG "-g")
108set(CMAKE_CXX_FLAGS_RELEASE "-O3")
109set(CMAKE_CXX_LDFLAGS_DEBUG "-g")
110# report global build settings
111message(STATUS "Using CXX compiler '${CMAKE_CXX_COMPILER}'")
112message(STATUS "Using CXX general compiler flags '${CMAKE_CXX_FLAGS}'")
113foreach(_BUILD_TYPE "DEBUG" "MINSIZEREL" "RELEASE" "RELWITHDEBINFO")
114 message(STATUS "Using CXX compiler flags '${CMAKE_CXX_FLAGS_${_BUILD_TYPE}}' for build type ${_BUILD_TYPE}")
115endforeach()
116message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")
117
118
119# redirect output files
120#set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/lib")
121message(STATUS "Using library output path '${LIBRARY_OUTPUT_PATH}'")
122#set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
123message(STATUS "Using executable output path '${EXECUTABLE_OUTPUT_PATH}'")
124
125
126# make CMAKE_SOURCE_DIR accessible in source code via predefined macro CMAKE_SOURCE_DIR
127if(CMAKE_SOURCE_DIR)
128 add_definitions(-D'CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"')
129else()
130 add_definitions(-D'CMAKE_SOURCE_DIR=\"\"')
131endif()
132
133
134# make SVN version string accessible in source code via predefined macro SVN_VERSION
135find_package(Subversion)
136if(Subversion_FOUND)
137 # unfortunately CMAKE only parses 'svn info'
138 find_program(SVNVERSION_EXECUTABLE
139 svnversion
140 )
141 if(NOT SVNVERSION_EXECUTABLE)
142 message(STATUS "Could not find subversion command 'svnversion'. Repository version unknown.")
143 else()
144 execute_process(
145 COMMAND ${SVNVERSION_EXECUTABLE} "${CMAKE_SOURCE_DIR}"
146 OUTPUT_VARIABLE SVN_VERSION
147 RESULT_VARIABLE _SVNVERSION_RETURN
148 OUTPUT_STRIP_TRAILING_WHITESPACE)
149 if(NOT ${_SVNVERSION_RETURN})
150 message(STATUS "Subversion repository revision is '${SVN_VERSION}'")
151 else()
152 message(STATUS "Error running 'svnversion'. Repository version unknown.")
153 set(SVN_VERSION "")
154 endif()
155 endif()
156else()
157 message(STATUS "Could not find subversion installation. Repository version unknown.")
158endif()
159if(SVN_VERSION)
160 add_definitions(-D'SVN_VERSION=\"${SVN_VERSION}\"')
161else()
162 add_definitions(-D'SVN_VERSION=\"\"')
163endif()
164
165
166# setup doxygen
167find_package(Doxygen)
168if(NOT DOXYGEN_FOUND)
169 message(WARNING "Cannot find Doxygen. No HTML documentation will be generated.")
170else()
171 set(DOXYGEN_TARGET "doxygen")
172 set(DOXYGEN_DOC_DIR "${CMAKE_SOURCE_DIR}/doxygen")
173 set(DOXYGEN_CONF "${CMAKE_SOURCE_DIR}/starlightDoxyfile.conf")
174 message(STATUS "Run 'make ${DOXYGEN_TARGET}' to create Doxygen documentation files in '${DOXYGEN_DOC_DIR}'")
175 add_custom_target(${DOXYGEN_TARGET}
176 COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONF}
177 DEPENDS ${DOXYGEN_CONF}
178 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
179 )
180endif()
181
182
183# setup Pythia 8
184option (ENABLE_PYTHIA "Enable compilation against pythia (necessary for certain processes)" OFF)
185if(ENABLE_PYTHIA)
186 find_package(Pythia8)
187 if(PYTHIA8_FOUND)
188 set(optionalLibs ${optionalLibs} ${PYTHIA8_LIBRARY})
189 find_package(LHAPDF REQUIRED) # implemented for dummy version in Pythia8
190 set(optionalLibs ${optionalLibs} ${LHAPDF_LIBRARIES})
191 option(ENABLE_PYTHIA "Should we use the Pythia8 library" ON)
192 else()
193 option(ENABLE_PYTHIA "Should we use the Pythia8 library" OFF)
194 endif()
195endif()
196
197# setup Pythia 6
198option (ENABLE_PYTHIA6 "Enable compilation against pythia 6 (necessary for certain processes)" OFF)
199if(ENABLE_PYTHIA6)
200 find_package(Pythia6 REQUIRED)
201 if(PYTHIA6_FOUND)
202 set(optionalLibs ${optionalLibs} ${PYTHIA6_LIBRARY})
203 option (ENABLE_PYTHIA6 "Enable compilation against pythia 6 (necessary for certain processes)" ON)
204 include_directories(pythia6)
205 else(PYTHIA6_FOUND)
206 option (ENABLE_PYTHIA6 "Enable compilation against pythia 6 (necessary for certain processes)" OFF)
207 endif(PYTHIA6_FOUND)
208endif()
209
210# setup DPMJET
211option (ENABLE_DPMJET "Enable compilation against DPMJet" OFF)
212if(ENABLE_DPMJET)
213 find_package(DPMJet REQUIRED)
214 if(DPMJET_FOUND)
215 option (ENABLE_DPMJET "Enable compilation against DPMJet" ON)
216 else(DPMJET_FOUND)
217 option (ENABLE_DPMJET "Enable compilation against DPMJet" OFF)
218 endif(DPMJET_FOUND)
219 endif(ENABLE_DPMJET)
220
221
222# set include directories
223set(INCLUDE_DIRECTORIES
224 ${CMAKE_SOURCE_DIR}/include
225 ${PROJECT_BINARY_DIR}
226# ${PYTHIA8_INCLUDE_DIR}
227 )
228include_directories(${INCLUDE_DIRECTORIES})
229
230# Set our source files, include the generated dictionary
231set(SOURCES
232 src/bessel.cpp
233 src/beam.cpp
234 src/inputParameters.cpp
235 src/beambeamsystem.cpp
236 src/starlightparticle.cpp
237 src/gammaaluminosity.cpp
238 src/randomgenerator.cpp
239 src/nucleus.cpp
240 src/eventchannel.cpp
241 src/gammaavm.cpp
242 src/gammagammasingle.cpp
243 src/photonNucleusCrossSection.cpp
244 src/wideResonanceCrossSection.cpp
245 src/narrowResonanceCrossSection.cpp
246 src/readinluminosity.cpp
247 src/twophotonluminosity.cpp
248 src/gammagammaleptonpair.cpp
249 src/starlight.cpp
250 src/upcevent.cpp
251 src/vector3.cpp
252 src/lorentzvector.cpp
253 src/filewriter.cpp
254 src/eventfilewriter.cpp
255 src/starlightparticlecodes.cpp
256 src/starlightStandalone.cpp
257 src/nBodyPhaseSpaceGen.cpp
258 src/inputParser.cpp
259 src/incoherentPhotonNucleusLuminosity.cpp
260 src/incoherentVMCrossSection.cpp
261 )
262if(ENABLE_PYTHIA)
263 set (SOURCES
264 ${SOURCES}
265 #src/PythiaStarlight.cpp
266 src/pythiadecayer.cpp
267 )
268 include_directories(${PYTHIA8_INCLUDE_DIR})
269endif()
270if(ENABLE_PYTHIA6)
271 set (SOURCES
272 ${SOURCES}
273 src/starlightpythia.cpp
274 src/spectrum.cpp
275 src/spectrumprotonnucleus.cpp
276 )
277endif()
278if(ENABLE_DPMJET)
279 set (SOURCES
280 ${SOURCES}
281 src/starlightdpmjet.cpp
282 src/spectrum.cpp
283 src/spectrumprotonnucleus.cpp
284 )
285endif()
286
287# add Starlight library to the build system
288set(THIS_LIB "Starlib")
289add_library(${THIS_LIB} STATIC ${SOURCES})
290#make_shared_library("${THIS_LIB}" "${SOURCES}"
291# "${PYTHIA8_LIBRARY}"
292# "${LHAPDF_LIBRARIES}"
293#)
294
295if(ENABLE_DPMJET)
296 enable_language(Fortran)
297 set(DPMJET_LIB "DpmJetLib")
298 message(STATUS "DPMJet objects: ${DPMJET_OBJECTS}")
299 add_library(${DPMJET_LIB} STATIC dpmjet/dpmjetint.f ${DPMJET_OBJECTS})
300 set(optionalLibs ${optionalLibs} ${DPMJET_LIB})
301
302endif()
303
304if(ENABLE_PYTHIA6)
305 enable_language(Fortran)
306endif()
307
308# add starlight executable to the build system
309add_executable(starlight src/main.cpp)
310#target_link_libraries(starlight Starlib ${PYTHIA8_LIBRARY} ${LHAPDF_LIBRARIES} ${PYTHIA6_LIBRARY} ${DPMJET_LIB} )
311target_link_libraries(starlight Starlib ${optionalLibs} ${CMAKE_THREAD_LIBS_INIT})
312
313#make_executable(starlight src/main.cpp ${THIS_LIB})
314
315configure_file (
316 "${PROJECT_SOURCE_DIR}/starlightconfig.h.in"
317 "${PROJECT_BINARY_DIR}/starlightconfig.h"
318 )
319# Erase xsec values in case changes in code affects the xsec, executed during make process
320add_custom_command (TARGET Starlib POST_BUILD COMMAND touch ARGS slight.txt)
321add_custom_command (TARGET Starlib POST_BUILD COMMAND cp ARGS slight.txt slight.txt.bak)
322add_custom_command (TARGET Starlib POST_BUILD COMMAND echo ARGS '' > slight.txt )
323
324
325message(STATUS "Cmake did not find any errors. run 'make' to build the project.")
326message(STATUS "On multi-core machines 'make -j#', where # is the number of parallel jobs, can speedup compilation considerably.")