source: trunk/Mars/CMakeLists.txt@ 19339

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