source: trunk/Mars/CMakeLists.txt @ 19263

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