source: trunk/Mars/CMakeLists.txt@ 19651

Last change on this file since 19651 was 19619, checked in by tbretz, 5 years ago
Get rid of some compiler warnings which come from the root dictionary:
File size: 13.9 KB
Line 
1# *********************************
2# ************ cmake **************
3# *********************************
4CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
5CMAKE_POLICY(SET CMP0043 NEW)
6CMAKE_POLICY(SET CMP0048 NEW)
7
8# Enable debug symbols by default
9# must be done before project() statement
10SET(CMAKE_BUILD_TYPE_INIT Release)
11# (you can also set it on the command line: -D CMAKE_BUILD_TYPE=Release)
12
13# Enable CLANG as default compilers, to change this use
14# cmake -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++
15# Note that if compilers are switched on the fly,
16# the cache is deleted
17IF(NOT DEFINED CMAKE_C_COMPILER)
18 FIND_PROGRAM(CMAKE_C_COMPILER NAMES $ENV{CC} clang gcc cc PATHS ENV PATH NO_DEFAULT_PATH DOC "C Compiler")
19ENDIF()
20IF(NOT DEFINED CMAKE_CXX_COMPILER)
21 FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES $ENV{CXX} clang++ g++ c++ PATHS ENV PATH NO_DEFAULT_PATH DOC "C++ Compiler")
22ENDIF()
23
24#SET(CMAKE_VERBOSE_MAKEFILE ON)
25
26# To check for an include file you do this:
27#CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
28# To check the size of a primitive type:
29#CHECK_TYPE_SIZE("int" SIZEOF_INT)
30
31
32
33# *********************************
34# ************ Project ************
35# *********************************
36
37STRING(TIMESTAMP VERSION %y.%U.%w.%H UTC)
38
39MESSAGE(STATUS "Mars V${VERSION}")
40
41PROJECT(mars VERSION ${VERSION})
42
43INCLUDE(GNUInstallDirs)
44
45# ======== For config.h.in =========
46SET(PACKAGE_MAINTAINER "Thomas Bretz")
47SET(PACKAGE_BUGREPORT "tbretz@physik.rwth-aachen.de")
48SET(PACKAGE_URL "https://www.fact-project.org")
49
50FIND_PROGRAM(LSB_RELEASE_EXE NAMES lsb_release)
51IF (DEFINED LSB_RELEASE_EXE)
52 EXECUTE_PROCESS(COMMAND ${LSB_RELEASE_EXE} -d OUTPUT_VARIABLE LSB_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE)
53 MESSAGE(STATUS ${LSB_RELEASE})
54ENDIF()
55
56# *********************************
57# ********* Requirements **********
58# *********************************
59
60# Inlclude the main source AND build dir itself
61#SET(CMAKE_INCLUDE_CURRENT_DIR ON)
62SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
63
64# =========== help2man ============
65FIND_PROGRAM(HELP2MAN_EXECUTABLE help2man)
66
67# =========== pkg-config ============
68FIND_PACKAGE(PkgConfig)
69FIND_PACKAGE(PackageHandleStandardArgs)
70
71
72# ============= libnova ==============
73
74PKG_CHECK_MODULES(Nova QUIET Nova)
75
76# Try to locate the package in the default path
77# and in the path provided by pkg-config
78FIND_PATH(NOVA_INCLUDE_DIR NAMES libnova/libnova.h PATHS ${NOVA_INCLUDE_DIRS})
79FIND_LIBRARY(NOVA_LIBRARY NAMES nova PATHS ${NOVA_LIBRARY_DIRS})
80
81# Check if NOVA_LIBARARY and NOVA_INCLUDE_DIR is set
82# Print a message otherwise
83FIND_PACKAGE_HANDLE_STANDARD_ARGS(Nova DEFAULT_MSG NOVA_LIBRARY NOVA_INCLUDE_DIR)
84
85# Mark those variables to be displayed as 'advanced' in the GUI
86MARK_AS_ADVANCED(NOVA_LIBRARY NOVA_INCLUDE_DIR)
87
88# handle success
89FIND_PACKAGE_MESSAGE(NovaInc "Found Nova headers in ${NOVA_INCLUDE_DIR}" "[${NOVA_LIBRARY}][${NOVA_INCLUDE_DIR}]")
90
91
92# ============== libz ================
93
94FIND_PACKAGE(ZLIB REQUIRED)
95
96# ============== ROOT ================
97
98FIND_PROGRAM(ROOTCONFIG_EXECUTABLE NAMES root-config)
99FIND_PACKAGE_HANDLE_STANDARD_ARGS(root-config DEFAULT_MSG ROOTCONFIG_EXECUTABLE)
100IF(NOT ROOTCONFIG_EXECUTABLE)
101 MESSAGE(FATAL_ERROR "Please make sure `root-config` is accessible in your path. In case of an installation from source, you might need to source\n . [path-to-root]/bin/thisroot.sh")
102ENDIF()
103
104# You need to tell CMake where to find the ROOT installation. This can be done in a number of ways:
105# - ROOT built with classic configure/make use the provided $ROOTSYS/etc/cmake/FindROOT.cmake
106# - ROOT built with CMake. Add in CMAKE_PREFIX_PATH the installation prefix for ROOT
107IF(EXISTS $ENV{ROOTSYS}/ROOTConfig.cmake)
108 IF(NOT DEFINED ENV{CMAKE_PREFIX_PATH})
109 LIST(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
110 ENDIF()
111ELSE()
112 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "$ENV{ROOTSYS}/etc/cmake")
113ENDIF()
114
115#---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
116FIND_PACKAGE(ROOT REQUIRED COMPONENTS Gui Minuit ASImage HistPainter)
117
118IF(NOT DEFINED ROOT_CONFIG_EXECUTABLE)
119 FIND_PACKAGE_MESSAGE(RootFound "Found ROOT: ${ROOT_INCLUDE_DIRS} [${ROOT_VERSION}]" "[${ROOT_INCLUDE_DIRS}][${ROOT_LIBRARY_DIR}][${ROOT_VERSION}]")
120ENDIF()
121
122#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
123IF(DEFINED ROOT_USE_FILE)
124 FIND_PACKAGE_MESSAGE(RootInclude "Setup ROOT: ${ROOT_USE_FILE}" "[${ROOT_USE_FILE}]")
125 INCLUDE(${ROOT_USE_FILE})
126ELSE()
127 FIND_PACKAGE_MESSAGE(RootInclude "Setup ROOT: ${ROOT_VERSION}" "[${ROOT_VERSION}]")
128 # From RootUseFile.cmake (root 6)
129 INCLUDE_DIRECTORIES(${ROOT_INCLUDE_DIRS})
130 LINK_DIRECTORIES(${ROOT_LIBRARY_DIR})
131 ADD_DEFINITIONS(${ROOT_DEFINITIONS})
132 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CXX_FLAGS}")
133 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ROOT_C_FLAGS}")
134 SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${ROOT_fortran_FLAGS}")
135ENDIF()
136
137# -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree
138# -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread
139# -lASImage -lMinuit -lHistPainter -lThread
140
141#MESSAGE("INCL_DIRS: ${ROOT_INCLUDE_DIRS}")
142#MESSAGE("LIBS: ${ROOT_LIBRARIES}")
143#MESSAGE("DEFS: ${ROOT_DEFINITIONS}")
144#MESSAGE("CXXFLAGS: ${ROOT_CXX_FLAGS}")
145#MESSAGE("CXFLAGS: ${ROOT_CC_FLAGS}")
146#MESSAGE("FOUND: ${ROOT_FOUND}")
147#MESSAGE("FILE: ${ROOT_USE_FILE}")
148#MESSAGE("DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
149#ROOT_<library>_LIBRARY PATH Full path for each of the ROOT libraries listed in COMPONENTS
150#ROOT_<command>_CMD PATH Full path for each ROOT executable (rootcling, root, hadd, etc.)
151#ROOT_<option>_FOUND BOOL True for each enabled build option (e.g. cocoa, python, xrootd, etc.)
152
153# function ROOT_GENERATE_DICTIONARY( dictionary
154# header1 header2 ...
155# LINKDEF linkdef1 ...
156# OPTIONS opt1...)
157
158# *********************************
159# ********** Observatory **********
160# *********************************
161
162SET(OBSERVATORY "ORM" CACHE STRING "Select the observatory location (ORM, HAWC, SPM, RWTH: see nova.h)")
163
164IF(NOT OBSERVATORY STREQUAL "ORM" AND
165 NOT OBSERVATORY STREQUAL "HAWC" AND
166 NOT OBSERVATORY STREQUAL "SPM" AND
167 NOT OBSERVATORY STREQUAL "RWTH")
168 MESSAGE(FATAL_ERROR "OBSERVATORY=${OBSERVATORY} invalid. Only ORM, HAWC, SPM and RWTH allowd!")
169ENDIF()
170
171FIND_PACKAGE_MESSAGE(PresetObservatory "Preset Observatory: ${OBSERVATORY}" "[${OBSERVATORY}]")
172
173
174# *********************************
175# *********** Compiler ************
176# *********************************
177
178SET(CMAKE_CXX_STANDARD 11)
179SET(CMAKE_CXX_FLAGS
180 "${CMAKE_CXX_FLAGS} -Wall -Winit-self -Wpointer-arith \
181 -Wcast-align -Wformat -Woverloaded-virtual \
182 -Wnon-virtual-dtor -Wshadow -fPIC") # -Wextra
183
184SET(CMAKE_CXX_FLAGS
185 "${CMAKE_CXX_FLAGS} \
186 -DMARSVER=\\\"1.0\\\" -D_REENTRANT -D__MARS__ -D__LINUX__ \
187 -DPACKAGE_VERSION=\\\"1.0\\\" -DREVISION=\\\"1.0\\\" \
188 -DPACKAGE_NAME=\\\"MARS\\\" -DHAVE_ZLIB")
189
190CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/cmake/root.rc.in" "${PROJECT_BINARY_DIR}/.rootrc")
191CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/cmake/rootlogon.C.in" "${PROJECT_BINARY_DIR}/rootlogon.C")
192CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/cmake/dohtml.C.in" "${PROJECT_BINARY_DIR}/dohtml.C")
193
194# -------------------------------------------------------
195
196FILE(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/dictionary)
197
198MACRO(SRCFILES subdir)
199
200 MESSAGE(STATUS "Reading source list from ${DIR}/Makefile")
201
202 EXECUTE_PROCESS(COMMAND
203 ${PROJECT_SOURCE_DIR}/Makefile.extract.sh ${subdir}
204 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${subdir}
205 OUTPUT_VARIABLE _HEADERS)
206
207 SEPARATE_ARGUMENTS(_HEADERS)
208
209 LIST(GET _HEADERS 0 _CINT)
210 LIST(REMOVE_AT _HEADERS 0)
211
212 SET(_SRCLIST ${_HEADERS})
213
214 STRING(REPLACE "${subdir}/" " " _HEADERS ${_HEADERS}) # Remove directory
215 STRING(REPLACE ".cc" ".h" _HEADERS ${_HEADERS}) # change extension
216 STRING(REPLACE ".cxx" ".hxx" _HEADERS ${_HEADERS}) # special for files in mmc
217
218 SEPARATE_ARGUMENTS(_HEADERS)
219
220 # - This adds the rule how the dictionary is created
221 ROOT_GENERATE_DICTIONARY(dictionary/${_CINT} ${_HEADERS} ${_CINT}Incl.h LINKDEF ${subdir}/${_CINT}LinkDef.h OPTIONS -p -D__MARS__ -DHAVE_ZLIB)
222 # - This makes sure that it is compiled
223 TARGET_SOURCES(mars PRIVATE dictionary/${_CINT}.cxx ${_SRCLIST})
224 SET_SOURCE_FILES_PROPERTIES(dictionary/${_CINT}.cxx PROPERTIES COMPILE_FLAGS "-Wno-deprecated-register")
225
226 INSTALL(DIRECTORY ${subdir}/ DESTINATION "include" FILES_MATCHING PATTERN "*.h")
227
228ENDMACRO()
229
230# -------------------------------------------------------
231
232#SET(DIRECTORIES mmc)
233
234SET(DIRECTORIES
235 manalysis
236 mastro
237 mbadpixels
238 mbase
239 mcalib
240 mcamera
241 mcorsika
242 mdata
243 mdrs
244 melectronics
245 mextralgo
246 mfbase
247 mfileio
248 mfilter
249 mgeom
250 mgui
251 mhbase
252 mhcalib
253 mhflux
254 mhft
255 mhist
256 mhvstime
257 mimage
258 mjobs
259 mjoptim
260 mjtrain
261 mmain
262 mmc
263 mmovie
264 mmuon
265 mpedestal
266 mpointing
267 mranforest
268 mraw
269 mreport
270 msignal
271 msim
272 msimcamera
273 msimreflector
274 msql
275 mtools
276 mtrigger
277)
278
279INCLUDE_DIRECTORIES(${DIRECTORIES} mcore .)
280
281ROOT_GENERATE_DICTIONARY(dictionary/Core
282 mcore/factofits.h
283 mcore/factfits.h
284 mcore/DrsCalib.h
285 mcore/PixelMap.h
286 mcore/Interpolator2D.h
287 mcore/nova.h
288 mcore/Prediction.h
289 MIncl.h
290 LINKDEF MLinkDef.h
291 OPTIONS -p -D__MARS__ -DHAVE_ZLIB)
292
293ADD_LIBRARY(mars SHARED dictionary/Core.cxx) # CMAKE_POSITION_INDEPENDENT_CODE
294 SET_SOURCE_FILES_PROPERTIES(dictionary/Core.cxx PROPERTIES COMPILE_FLAGS "-Wno-deprecated-register")
295TARGET_LINK_LIBRARIES(mars
296 ZLIB::ZLIB
297 ${NOVA_LIBRARY}
298 ${ROOT_LIBRARIES})
299
300ADD_EXECUTABLE(showplot showplot.cc)
301ADD_EXECUTABLE(showlog showplot.cc)
302ADD_EXECUTABLE(ceres ceres.cc)
303TARGET_LINK_LIBRARIES(showplot mars ${ROOT_LIBRARIES})
304TARGET_LINK_LIBRARIES(showlog mars ${ROOT_LIBRARIES})
305TARGET_LINK_LIBRARIES(ceres mars ${ROOT_LIBRARIES})
306
307
308FOREACH(DIR ${DIRECTORIES})
309 SRCFILES(${DIR})
310ENDFOREACH()
311
312# rootlogon.C finds the shared object only if the libmars.so is in the same directory than the dictionary files
313# there is a way to create a map file with rootcling - but I haven#t yet fugured out how. Note that a link is not enough
314#ADD_CUSTOM_COMMAND(TARGET mars POST_BUILD
315# COMMAND cp -f ${PROJECT_BINARY_DIR}/libmars.so ${PROJECT_BINARY_DIR}/dictionary/libmars.so
316# COMMENT "Copying libmars.so to ${PROJECT_BINARY_DIR}/dictionary")
317
318#---Create a shared library with geneated dictionary
319#ADD_LIBRARY(Event SHARED Event.cxx G__Event.cxx)
320#TARGET_LINK_LIBRARIES(Event ${ROOT_LIBRARIES})
321
322#---Create a main program using the library
323#ADD_EXECUTABLE(Main MainEvent.cxx)
324#TARGET_LINK_LIBRARIES(Main Event)
325
326
327# *********************************
328# ************ Packaging **********
329# *********************************
330
331#SET(PKG_SHARE "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
332#SET(PKG_APPS "${CMAKE_INSTALL_DATAROOTDIR}/applications")
333#SET(PKG_PIXMAPS "${CMAKE_INSTALL_DATAROOTDIR}/pixmaps")
334
335# ====== Installation targets =====
336
337#INSTALL(TARGETS mars DESTINATION "${CMAKE_INSTALL_BINDIR}")
338INSTALL(TARGETS mars DESTINATION ".")
339INSTALL(TARGETS showplot DESTINATION ".")
340INSTALL(TARGETS showlog DESTINATION ".")
341INSTALL(TARGETS ceres DESTINATION ".")
342INSTALL(FILES .rootrc DESTINATION ".")
343INSTALL(DIRECTORY lib DESTINATION ".")
344INSTALL(DIRECTORY macros DESTINATION "." FILES_MATCHING PATTERN "*.C")
345INSTALL(DIRECTORY fact DESTINATION "." FILES_MATCHING PATTERN "*.C")
346INSTALL(DIRECTORY datacenter DESTINATION ".")
347INSTALL(DIRECTORY scripts DESTINATION ".")
348INSTALL(DIRECTORY resources DESTINATION "." FILES_MATCHING PATTERN "*.rc" PATTERN "*.txt")
349INSTALL(DIRECTORY resmc DESTINATION "." FILES_MATCHING PATTERN "*" )
350INSTALL(DIRECTORY mcore/ DESTINATION "include" FILES_MATCHING PATTERN "*.h")
351
352
353# ======== General packaging ======
354# https://cmake.org/cmake/help/latest/module/CPack.html
355
356INCLUDE(InstallRequiredSystemLibraries)
357
358# SET(CPACK_STRIP_FILES ON) # Strip debug sysmbold from files
359
360SET(CPACK_PACKAGE_VERSION "${mars_VERSION}")
361SET(CPACK_PACKAGE_CONTACT "${PACKAGE_BUGREPORT}")
362SET(CPACK_PACKAGE_MAINTAINER "${PACKAGE_MAINTAINER}")
363#SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
364#SET(CPACK_PACKAGE_VENDOR "Me, myself, and I")
365
366
367SET(CPACK_SOURCE_IGNORE_FILES "/old/;/build/;/[.].*/;/autom4te[.]cache/;.*~;.log$")
368
369# Maybe the text displayed in synaptic?
370#SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
371SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MARS - Environment")
372#CPACK_RESOURCE_FILE_README ReadMe file to be embedded in the installer.
373
374SET(CPACK_GENERATOR TBZ2) # TGZ DEB
375#SET(CPACK_SOURCE_GENERATOR TBZ2) # TGZ
376#SET(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/cmake/Package.txt)
377#SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
378
379
380# ======== Debian packaging =======
381# https://cmake.org/cmake/help/latest/module/CPackDeb.html
382# https://www.debian.org/doc/debian-policy
383
384#SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libao4 (>=1.0), libsfm-system2.3v5 (>=2.3), libsfml-graphicsv2.3v5 (>=2.3), libsfml-audio2.3v5 (>=2.3), libsfm-window2.3v5 (>2.3)")
385SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS 1) # generate better (atomatic?) dependecies
386SET(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")
387SET(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
388SET(CPACK_DEBIAN_PACKAGE_SECTION utils)
389SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${PACKAGE_URL}")
390SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION
391"${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
392 This package contains the MARS Analysis Environment.")
393#indent the long description with spaces
394
395#CPACK_INSTALL_CMAKE_PROJECTS
396#List of four values that specify what project to install. Build directory, Project Name, Project Component, Directory.
397
398INCLUDE(CPack)
Note: See TracBrowser for help on using the repository browser.