source: trunk/Mars/CMakeLists.txt @ 19321

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