CMakeLists.txt 7.09 KB
Newer Older
Pawel Sznajder's avatar
Pawel Sznajder committed
1
2
3
# BASIC DEFINITIONS ========================================================================

# define minimum version of cmake
4
cmake_minimum_required(VERSION 3.2)
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
5

Pawel Sznajder's avatar
Pawel Sznajder committed
6
# define project name and its language
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
7
project(PARTONS CXX)
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
8

Pawel Sznajder's avatar
Pawel Sznajder committed
9
# define c++ standard and issue all the warning demanded by this standard
10
11
12
13
14
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   add_definitions(-std=c++11 -pedantic -Wno-vla-extension)
else()
   add_definitions(-std=c++11 -pedantic -Wno-vla-extension -fext-numeric-literals)
endif()
15
16
17
18
19
set(CMAKE_CXX_STANDARD 11)

if (NOT DEFINED CMAKE_MACOSX_RPATH)
   set(CMAKE_MACOSX_RPATH 0)
endif()
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
20

21
22
23
24
25
# VERSION ==================================================================================

# read file
file(READ ${CMAKE_SOURCE_DIR}/data/version.txt VERSION_STR)

Pawel Sznajder's avatar
Pawel Sznajder committed
26
# strip spaces
27
28
string(STRIP ${VERSION_STR} VERSION_STR)

29
30
31
32
33
34
35
36
37
38
39
# get major, minor and patch versions
string(REGEX MATCH "^[0-9]*\\." TMP_STR ${VERSION_STR})
string(REGEX REPLACE "\\." "" PARTONS_VERSION_MAJOR ${TMP_STR})

string(REGEX MATCH "\\.[0-9]*\\." TMP_STR ${VERSION_STR})
string(REGEX REPLACE "\\." "" PARTONS_VERSION_MINOR ${TMP_STR})

string(REGEX MATCH "\\.[0-9]*$" TMP_STR ${VERSION_STR})
string(REGEX REPLACE "\\." "" PARTONS_VERSION_PATCH ${TMP_STR})

message("-- PARTONS version is: " ${PARTONS_VERSION_MAJOR} "." ${PARTONS_VERSION_MINOR} "." ${PARTONS_VERSION_PATCH})
40

Pawel Sznajder's avatar
Pawel Sznajder committed
41
42
43
44
45
46
47
execute_process(COMMAND bash -c "cd ${CMAKE_SOURCE_DIR}; git branch | grep '\*' | cut -d ' ' -f2 2> /dev/null" OUTPUT_VARIABLE PARTONS_GIT_BRANCH)
execute_process(COMMAND bash -c "cd ${CMAKE_SOURCE_DIR}; git rev-parse HEAD 2> /dev/null" OUTPUT_VARIABLE PARTONS_GIT_REVISION)
string(REGEX REPLACE "\n$" "" PARTONS_GIT_BRANCH "${PARTONS_GIT_BRANCH}")
string(REGEX REPLACE "\n$" "" PARTONS_GIT_REVISION "${PARTONS_GIT_REVISION}")

message("-- Git branch (revision): " ${PARTONS_GIT_BRANCH} " (" ${PARTONS_GIT_REVISION} ")")

48
# configure
Pawel Sznajder's avatar
Pawel Sznajder committed
49
configure_file(${CMAKE_SOURCE_DIR}/cmake/Version/PartonsVersion.h_in ${CMAKE_SOURCE_DIR}/include/partons/PartonsVersion.h)
50

Pawel Sznajder's avatar
Pawel Sznajder committed
51
52
53
# AUTOMOC ==================================================================================

# tell cmake to run Qt moc when necessary
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
54
55
set(CMAKE_AUTOMOC ON)
  
Pawel Sznajder's avatar
Pawel Sznajder committed
56
# as moc files are generated in the binary dir, tell cmake to always look for includes there
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
57
set(CMAKE_INCLUDE_CURRENT_DIR ON)
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
58

Pawel Sznajder's avatar
Pawel Sznajder committed
59
60
# FIND LIBRARIES ===========================================================================

61
62
63
# find libraries: additional modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

64
# find libraries: Qt
65
find_package(Qt5 COMPONENTS Core Sql XmlPatterns QUIET)
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
66

67
if(${Qt5_FOUND})
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
68

Pawel Sznajder's avatar
Pawel Sznajder committed
69
70
71
72
73
74
75
   find_package(Qt5Widgets QUIET)
   
   if (Qt5Widgets_FOUND)
   	  set(QT_VERSION ${Qt5Widgets_VERSION})
   else()
      set(QT_VERSION "5.??.??")
   endif()
76
77
78
79
80

   set(QT_LIBRARY_CORE "Qt5::Core")
   set(QT_LIBRARY_SQL "Qt5::Sql")
   set(QT_LIBRARY_XML "Qt5::XmlPatterns")
   
Pawel Sznajder's avatar
Pawel Sznajder committed
81
   message("-- Found Qt5: " ${QT_VERSION})
82
83
84
   
else()

Pawel Sznajder's avatar
Pawel Sznajder committed
85
   find_package(Qt4 COMPONENTS QtCore QtSql QtXmlPatterns QUIET)
86
87

   if(${Qt4_FOUND})
Pawel Sznajder's avatar
Pawel Sznajder committed
88
89
   
   	  set(QT_VERSION ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
90
91
92
93
94

      set(QT_LIBRARY_CORE "Qt4::QtCore")
      set(QT_LIBRARY_SQL "Qt4::QtSql")
      set(QT_LIBRARY_XML "Qt4::QtXmlPatterns")
      
Pawel Sznajder's avatar
Pawel Sznajder committed
95
      message("-- Found Qt4: " ${QT_VERSION})
96
97
98
99
100

   else()
      message(FATAL_ERROR "Neither Qt5 nor Qt4 found in this system")
   endif()
endif()
Nabil Chouika's avatar
ref#16    
Nabil Chouika committed
101

Pawel Sznajder's avatar
Pawel Sznajder committed
102
103
# find libraries: ElementaryUtils
find_package(ElementaryUtils REQUIRED)
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
104

Pawel Sznajder's avatar
Pawel Sznajder committed
105
106
# find libraries: NumA++
find_package(NumA++ REQUIRED)
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
107

108
109
110
111
112
113
# find libraries: SFML
find_package(SFML COMPONENTS system REQUIRED)

# find libraries: CLN
find_package(CLN REQUIRED)

114
115
116
# find libraries: GSL
find_package(GSL REQUIRED)

117
118
119
# find libraries: Apfel++
find_package(Apfel++ REQUIRED)

120
121
122
# find libraries: LHAPDF
find_package(LHAPDF REQUIRED)

Pawel Sznajder's avatar
Pawel Sznajder committed
123
# directories containing headers 
Pawel Sznajder's avatar
Pawel Sznajder committed
124
include_directories(${QT_INCLUDE_DIRS} ${ElementaryUtils_INCLUDE_DIR} ${NumA++_INCLUDE_DIR} ${SFML_INCLUDE_DIR} ${CLN_INCLUDE_DIR} ${GSL_INCLUDE_DIRS} ${Apfel++_INCLUDE_DIR} ${LHAPDF_INCLUDE_DIR})
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
125
126
include_directories(include)

127
128
# ENVIRONMENT VARIABLES ========================================================================

Pawel Sznajder's avatar
Pawel Sznajder committed
129
130
file(READ ${ElementaryUtils_INCLUDE_DIR}/ElementaryUtils/ElementaryUtilsVersion.h VERSION_STR)

Pawel Sznajder's avatar
Pawel Sznajder committed
131
132
133
string(REGEX MATCH "ELEMENTARY_UTILS_GIT_BRANCH[ \t]*[^\t\n]*\n" ELEMUTILS_BRANCH "${VERSION_STR}")
string(REGEX REPLACE "ELEMENTARY_UTILS_GIT_BRANCH[ \t]*" "" ELEMUTILS_BRANCH "${ELEMUTILS_BRANCH}")
string(REGEX REPLACE "\"" "" ELEMUTILS_BRANCH "${ELEMUTILS_BRANCH}")
Pawel Sznajder's avatar
Pawel Sznajder committed
134
135
string(STRIP ${ELEMUTILS_BRANCH} ELEMUTILS_BRANCH)
string(REGEX MATCH "ELEMENTARY_UTILS_GIT_REVISION[ \t]*[^\t\n]*\n" ELEMUTILS_REVISION ${VERSION_STR})
Pawel Sznajder's avatar
Pawel Sznajder committed
136
137
138
string(REGEX REPLACE "ELEMENTARY_UTILS_GIT_REVISION[ \t]*" "" ELEMUTILS_REVISION "${ELEMUTILS_REVISION}")
string(REGEX REPLACE "\"" "" ELEMUTILS_REVISION "${ELEMUTILS_REVISION}")
string(STRIP "${ELEMUTILS_REVISION}" ELEMUTILS_REVISION)
Pawel Sznajder's avatar
Pawel Sznajder committed
139
140
141
142

file(READ ${NumA++_INCLUDE_DIR}/NumA/NumAVersion.h VERSION_STR)

string(REGEX MATCH "NUMA_GIT_BRANCH[ \t]*[^\t\n]*\n" NUMA_BRANCH ${VERSION_STR})
Pawel Sznajder's avatar
Pawel Sznajder committed
143
144
145
string(REGEX REPLACE "NUMA_GIT_BRANCH[ \t]*" "" NUMA_BRANCH "${NUMA_BRANCH}")
string(REGEX REPLACE "\"" "" NUMA_BRANCH "${NUMA_BRANCH}")
string(STRIP "${NUMA_BRANCH}" NUMA_BRANCH)
Pawel Sznajder's avatar
Pawel Sznajder committed
146
string(REGEX MATCH "NUMA_GIT_REVISION[ \t]*[^\t\n]*\n" NUMA_REVISION ${VERSION_STR})
Pawel Sznajder's avatar
Pawel Sznajder committed
147
148
149
string(REGEX REPLACE "NUMA_GIT_REVISION[ \t]*" "" NUMA_REVISION "${NUMA_REVISION}")
string(REGEX REPLACE "\"" "" NUMA_REVISION "${NUMA_REVISION}")
string(STRIP "${NUMA_REVISION}" NUMA_REVISION)
Pawel Sznajder's avatar
Pawel Sznajder committed
150
151
152
153

file(READ ${CMAKE_SOURCE_DIR}/include/partons/PartonsVersion.h VERSION_STR)

string(REGEX MATCH "PARTONS_GIT_BRANCH[ \t]*[^\t\n]*\n" PARTONS_BRANCH ${VERSION_STR})
Pawel Sznajder's avatar
Pawel Sznajder committed
154
155
156
string(REGEX REPLACE "PARTONS_GIT_BRANCH[ \t]*" "" PARTONS_BRANCH "${PARTONS_BRANCH}")
string(REGEX REPLACE "\"" "" PARTONS_BRANCH "${PARTONS_BRANCH}")
string(STRIP "${PARTONS_BRANCH}" PARTONS_BRANCH)
Pawel Sznajder's avatar
Pawel Sznajder committed
157
string(REGEX MATCH "PARTONS_GIT_REVISION[ \t]*[^\t\n]*\n" PARTONS_REVISION ${VERSION_STR})
Pawel Sznajder's avatar
Pawel Sznajder committed
158
159
160
161
string(REGEX REPLACE "PARTONS_GIT_REVISION[ \t]*" "" PARTONS_REVISION "${PARTONS_REVISION}")
string(REGEX REPLACE "\"" "" PARTONS_REVISION "${PARTONS_REVISION}")
string(STRIP "${PARTONS_REVISION}" PARTONS_REVISION)

162
163
164

configure_file("${CMAKE_SOURCE_DIR}/data/config/environment_configuration.dat.in" "${CMAKE_SOURCE_DIR}/data/config/environment_configuration.dat")

Pawel Sznajder's avatar
Pawel Sznajder committed
165
166
167
# FINALIZE ==================================================================================

# generate list of source files
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
168
169
170
171
172
173
174
175
176
file(

        GLOB_RECURSE

        source_files

        src/*
)

Pawel Sznajder's avatar
Pawel Sznajder committed
177
# define target library
Pawel Sznajder's avatar
Pawel Sznajder committed
178
179
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
180
181
182
183
184
185
186
187
188
add_library(

        PARTONS

        SHARED

        ${source_files}
)

Pawel Sznajder's avatar
Pawel Sznajder committed
189
# define libraries to be linked
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
190
191
target_link_libraries(

Pawel Sznajder's avatar
Pawel Sznajder committed
192
193
		PARTONS
          
194
		${SFML_LIBRARIES}
Pawel Sznajder's avatar
Pawel Sznajder committed
195
          
196
		${CLN_LIBRARIES}
Pawel Sznajder's avatar
Pawel Sznajder committed
197
          
198
		${ElementaryUtils_LIBRARIES}
Pawel Sznajder's avatar
Pawel Sznajder committed
199
          
200
201
202
203
		${NumA++_LIBRARIES}

		${GSL_LIBRARIES}

204
205
		${Apfel++_LIBRARIES}

206
207
		${LHAPDF_LIBRARIES}

208
209
210
211
212
		${QT_LIBRARY_CORE}
		
		${QT_LIBRARY_SQL}
		
		${QT_LIBRARY_XML}
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
213
)
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
214

Pawel Sznajder's avatar
Pawel Sznajder committed
215
216
# install
install(TARGETS PARTONS 
217
218
219
220
221
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
	ARCHIVE DESTINATION lib/static)
install(DIRECTORY include/ DESTINATION include)
install(DIRECTORY data DESTINATION share)