source: trunk/Mars/CMakeLists.txt@ 19395

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