-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
301 lines (228 loc) · 8.97 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
###################################################################
#
# CMake Build Script for DeviserEdit
#
# Frank T. Bergmann
#
#
project(DeviserEdit)
cmake_minimum_required(VERSION 2.6)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.6)
cmake_policy(VERSION 2.8)
endif("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.6)
if(POLICY CMP0043)
cmake_policy(SET CMP0043 NEW)
endif(POLICY CMP0043)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif(POLICY CMP0020)
if (POLICY CMP0042)
cmake_policy(SET CMP0042 OLD)
endif (POLICY CMP0042)
set(DEVISER_VERSION_MAJOR)
set(DEVISER_VERSION_MINOR)
set(DEVISER_VERSION_PATCH)
set(DEVISER_VERSION_RELEASE)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt" VersionString NEWLINE_CONSUME )
string(STRIP "${VersionString}" VersionString )
string(REPLACE "." ";" VersionString "${VersionString}" )
string(REPLACE "-" ";" VersionString "${VersionString}" )
list(LENGTH VersionString versionLength)
list(GET VersionString 0 DEVISER_VERSION_MAJOR )
list(GET VersionString 1 DEVISER_VERSION_MINOR )
list(GET VersionString 2 DEVISER_VERSION_PATCH )
if(${versionLength} GREATER 3)
list(GET VersionString 3 DEVISER_VERSION_RELEASE )
endif()
# version number needs to be calculated correctly
MATH(EXPR DEVISER_VERSION_NUMERIC "${DEVISER_VERSION_MAJOR} * 10000 + ${DEVISER_VERSION_MINOR} * 100 + ${DEVISER_VERSION_PATCH}" )
set(PACKAGE_VERSION "${DEVISER_VERSION_MAJOR}.${DEVISER_VERSION_MINOR}.${DEVISER_VERSION_PATCH}${DEVISER_VERSION_RELEASE}")
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/deviser-version.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/deviser-version.h"
)
endif()
set(CPACK_PACKAGE_VERSION_MAJOR "${DEVISER_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${DEVISER_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${DEVISER_VERSION_PATCH}")
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/license.txt")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/readme.md")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_SOURCE_IGNORE_FILES
"aa;aa.zip;screenshots;.DS_STORE;testmodels/.DS_Store;/build/;/.bzr/;~$;${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_NSIS_CREATE_ICONS "CreateShortCut '\$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Deviser Edit.lnk' '\$INSTDIR\\\\bin\\\\DeviserEdit.exe'")
include(CPack)
###############################################################################
#
# Need some variables set up, such as the name for the libSBML
# library and the Path and file separator characters. The
# MISC_PREFIX variable will cause libsbml bindings, examples and
# documentation to be installed in PREFIX/${MISC_PREFIX}.
#
if(UNIX OR CYGWIN)
set(PATH_SEP "/")
set(FILE_SEP ":")
else()
set(PATH_SEP "\\")
set(FILE_SEP ";")
endif()
set(EXTRA_LIBS "" CACHE STRING "List of additional libraries to link against." )
set(EXTRA_FLAGS "" CACHE STRING "List of extra flags." )
set(EXTRA_INCLUDE "" CACHE STRING "List of include diretories." )
if (EXTRA_FLAGS)
foreach(${flag} ${EXTRA_FLAGS})
add_definitions(-D${flag})
endforeach()
endif()
if (APPLE)
add_definitions(-DDARWIN)
endif()
if (UNIX)
add_definitions(-DLINUX)
endif()
if(WIN32 AND NOT CYGWIN)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS")
option(WITH_STATIC_RUNTIME "Compile using the static MSVC Runtime." OFF)
if(WITH_STATIC_RUNTIME)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
add_definitions( -D_MT)
endif(WITH_STATIC_RUNTIME)
endif()
endif()
if (PREFIX_PATH)
set (CMAKE_PREFIX_PATH "${PREFIX_PATH}")
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/ChooseQtVersion.cmake)
QT_FIND_MODULES(Core Gui OpenGL Xml Network Svg Help)
set(CPP_FILES)
set(H_FILES)
set(UI_FILES)
set(RCC_FILES)
foreach(dir . model ui validation)
file(GLOB LOCAL_CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.cpp)
file(GLOB LOCAL_H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.h)
file(GLOB LOCAL_UI_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.ui )
file(GLOB LOCAL_RCC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.qrc )
if (NOT "${dir}" STREQUAL ".")
source_group(${dir} FILES
${LOCAL_CPP_FILES}
${LOCAL_H_FILES}
${LOCAL_UI_FILES}
${LOCAL_RCC_FILES})
endif()
set(CPP_FILES ${CPP_FILES} ${LOCAL_CPP_FILES})
set(H_FILES ${H_FILES} ${LOCAL_H_FILES})
set(UI_FILES ${UI_FILES} ${LOCAL_UI_FILES})
set(RCC_FILES ${RCC_FILES} ${LOCAL_RCC_FILES})
endforeach()
if (Qt5_FOUND)
qt5_add_resources(RESOURCES_RCC ${RCC_FILES})
qt5_wrap_cpp(HEADERS_MOC ${H_FILES})
qt5_wrap_ui(FORMS_HEADERS ${UI_FILES})
set(QTVERSION 5)
elseif(Qt4_FOUND OR QT4_FOUND)
qt4_add_resources(RESOURCES_RCC ${RCC_FILES})
qt4_wrap_cpp(HEADERS_MOC ${H_FILES})
qt4_wrap_ui(FORMS_HEADERS ${UI_FILES})
endif()
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/ui)
set(EXECUTABLE_FLAGS)
set(EXTRA_FILES)
if(WIN32 AND NOT CYGWIN)
option(ENABLE_UI_CONSOLE "Show the console window (to see debug messages) when running Deviser Edit" OFF)
if (NOT ENABLE_UI_CONSOLE)
set(EXECUTABLE_FLAGS WIN32)
if(MSVC)
set(CPP_FILES ${CPP_FILES} ${CMAKE_SOURCE_DIR}/deviser.rc)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:mainCRTStartup ")
endif(MSVC)
endif(NOT ENABLE_UI_CONSOLE)
endif(WIN32 AND NOT CYGWIN)
if(APPLE)
set(EXECUTABLE_FLAGS MACOSX_BUNDLE)
set(MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/QtDeviser.plist )
set(MACOSX_BUNDLE_ICON_FILE ICON_Deviser.icns )
set(EXTRA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Images/ICON_Deviser.icns )
set(MACOSX_BUNDLE_BUNDLE_VERSION "${DEVISER_VERSION_MAJOR}.${DEVISER_VERSION_MINOR}.${DEVISER_VERSION_BUILD}")
set(MACOSX_BUNDLE_INFO_STRING "Deviser Edit ${MACOSX_BUNDLE_BUNDLE_VERSION} is distributed under the LGPL." )
set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.sbml.QtDeviser" )
set(MACOSX_BUNDLE_BUNDLE_NAME "Deviser Edit")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${MACOSX_BUNDLE_BUNDLE_VERSION}")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${MACOSX_BUNDLE_BUNDLE_VERSION}")
set(MACOSX_BUNDLE_COPYRIGHT ${MACOSX_BUNDLE_INFO_STRING})
endif()
add_executable(DeviserEdit ${EXECUTABLE_FLAGS} ${CPP_FILES}
${H_FILES}
${HEADERS_MOC}
${FORMS_HEADERS}
${RESOURCES_RCC}
${EXTRA_FILES}
)
if (APPLE)
add_custom_command(TARGET DeviserEdit POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:DeviserEdit>/../Resources
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Images/ICON_Deviser.icns $<TARGET_FILE_DIR:DeviserEdit>/../Resources)
# add target to bundle up the qt libraries in the app
ADD_CUSTOM_TARGET(macdeploy
macdeployqt "${CMAKE_CURRENT_BINARY_DIR}/DeviserEdit.app" -dmg)
ADD_DEPENDENCIES(macdeploy DeviserEdit)
endif()
add_custom_command(TARGET DeviserEdit POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Deviser.qch $<TARGET_FILE_DIR:DeviserEdit>/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Deviser.qhc $<TARGET_FILE_DIR:DeviserEdit>/)
install(TARGETS DeviserEdit DESTINATION bin)
QT_BIND_TO_TARGET(DeviserEdit)
SET(DIRS)
if (EXTRA_LIBS)
foreach(${lib} ${EXTRA_LIBS})
if (EXISTS ${lib})
get_filename_component(dir ${lib} PATH)
SET(DIRS ${DIRS} ${dir})
endif()
endforeach()
endif()
if (NOT DIRS)
if (EXISTS "${EXTRA_LIBS}")
get_filename_component(DIRS ${EXTRA_LIBS} PATH)
endif()
endif()
if (QT_BINARY_DIR)
SET(DIRS ${QT_BINARY_DIR} ${DIRS})
endif()
if (NOT APPLE)
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/DeviserEdit${CMAKE_EXECUTABLE_SUFFIX}" CACHE INTERNAL "")
if (EXTRA_LIBS)
install(TARGETS EXTRA_LIBS DESTINATION bin)
endif()
# ensure that next to the binaries also dependencies are copied
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")
" COMPONENT Runtime)
endif()
message(STATUS
"
Project Deviser Edit ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
===========================
Install Prefix : ${CMAKE_INSTALL_PREFIX}
Qt Version : ${QTVERSION}
C FLAGS : ${CMAKE_C_FLAGS}
CXX FLAGS : ${CMAKE_CXX_FLAGS}
Extra Libs : ${EXTRA_LIBS}
"
)