WSL/SLF GitLab Repository

CMakeLists.txt 13.5 KB
Newer Older
Mathias Bavay's avatar
Mathias Bavay committed
1
#SPDX-License-Identifier: GPL-3.0-or-later
2
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
3
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/tools/cmake/")
4

buergiss's avatar
buergiss committed
5
6
7
8
9
10
11
12
13
14
15
# Version of library
IF(DEFINED ENV{VERSION_MAJOR} AND DEFINED ENV{VERSION_MINOR} AND DEFINED ENV{VERSION_PATCH})
	SET(VERSION_MAJOR $ENV{VERSION_MAJOR} CACHE INTERNAL "Major version")
	SET(VERSION_MINOR $ENV{VERSION_MINOR} CACHE INTERNAL "Minor version")
	SET(VERSION_PATCH $ENV{VERSION_PATCH} CACHE INTERNAL "Patch version")
ELSE()
	SET(VERSION_MAJOR 2 CACHE INTERNAL "")
	SET(VERSION_MINOR 0 CACHE INTERNAL "")
	SET(VERSION_PATCH 7 CACHE INTERNAL "")
ENDIF()

16
PROJECT(inishell VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
17
18
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/main/config.h.in ${PROJECT_SOURCE_DIR}/src/main/config.h)

Mathias Bavay's avatar
Mathias Bavay committed
19
20
###########################################################
# Set language compatibility and qt tools
21
22
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
23
24
INCLUDE("${CMAKE_SOURCE_DIR}/tools/cmake/SetCompilerOptions.cmake")
SET_COMPILER_OPTIONS()
25

26
# Specific QT settings
27
28
29
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_AUTOUIC ON)
30
31
32
33
IF(CMAKE_VERSION VERSION_LESS "3.7.0")
    SET(CMAKE_INCLUDE_CURRENT_DIR ON)
ENDIF()

34
#in order to support both Qt5 and QT6
35
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
36
37
38
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Xml Network REQUIRED)
SET(QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Xml Qt${QT_VERSION_MAJOR}::Network)
MARK_AS_ADVANCED(FORCE Qt${QT_VERSION_MAJOR}Core_DIR Qt${QT_VERSION_MAJOR}Gui_DIR Qt${QT_VERSION_MAJOR}Network_DIR Qt${QT_VERSION_MAJOR}Widgets_DIR Qt${QT_VERSION_MAJOR}Xml_DIR Qt${QT_VERSION_MAJOR}_DIR)
39

40
41
42
43
44
45
46
47
48
49
50
51
#finally, SET compile flags
SET(CMAKE_CXX_FLAGS "${ARCH} ${EXTRA}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_RELEASE "${OPTIM}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_DEBUG "${DEBUG} ${WARNINGS} ${EXTRA_WARNINGS}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_CXXFLAGS "$ENV{CXXFLAGS}" CACHE STRING "" FORCE)
MARK_AS_ADVANCED(FORCE CMAKE_CXX_FLAGS_CXXFLAGS)

IF(NOT CMAKE_BUILD_TYPE)
	SET(CMAKE_BUILD_TYPE "release" CACHE STRING "Choose the type of build, options are: debug release coverage cxxflags" FORCE)
	SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
ENDIF(NOT CMAKE_BUILD_TYPE)

Mathias Bavay's avatar
Mathias Bavay committed
52
53
54
SET(EXTRA_LIBS_SRC ./lib/tinyexpr.c)
SET(RESOURCES resources/inishell.qrc)
INCLUDE("${PROJECT_SOURCE_DIR}/src/CMakeLists.txt")
55

Mathias Bavay's avatar
Mathias Bavay committed
56
SET(TARGET ${CMAKE_PROJECT_NAME})
57
SET(TARGET_TYPE "")
58
59
SET(INSTALL_OSX "")
SET(DLL_EXT "so")
60
61
62

IF(WIN32)
	SET(TARGET_TYPE "WIN32")
63
	SET(DLL_EXT "dll")
64
65
ENDIF(WIN32)
IF(APPLE)
66
	SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.13) # High Sierra
67
	SET(TARGET_TYPE "MACOSX_BUNDLE")
68
	SET(INSTALL_OSX BUNDLE DESTINATION bin)
69
	SET(DLL_EXT "dylib")
70
71
ENDIF(APPLE)

72
73
74
# Generate the .qm translation files and potentially the .ts files
SET(SUPPORT_TRANSLATIONS OFF CACHE BOOL "Support translating the user interface? (this may require the qttools5-dev package)")
IF(SUPPORT_TRANSLATIONS)
75
76
 	FIND_PACKAGE(Qt${QT_VERSION_MAJOR}LinguistTools REQUIRED)
 	MARK_AS_ADVANCED(FORCE Qt${QT_VERSION_MAJOR}LinguistTools_DIR)
77
78
79
	FILE(GLOB TS_FILES ${PROJECT_SOURCE_DIR}/resources/langs/*.ts)
	SET_SOURCE_FILES_PROPERTIES(${TS_FILES} PROPERTIES OUTPUT_LOCATION "resources/l10n")
	qt5_add_translation(QM_FILES ${TS_FILES})
80
81
82
83
84
85
86
87
88

	#dynamically create a resources file that contains all translations
	SET(TRANSLATION_RESOURCES ${PROJECT_SOURCE_DIR}/resources/translations.qrc)
	FILE(WRITE ${TRANSLATION_RESOURCES} "<!DOCTYPE RCC><RCC version=\"1.0\">\n\n<qresource>\n")
	FOREACH(_qm_file ${QM_FILES})
 		GET_FILENAME_COMPONENT(_filename ${_qm_file} NAME)
		FILE(APPEND ${TRANSLATION_RESOURCES} "\t<file>l10n/${_filename}</file>\n")
	ENDFOREACH()
	FILE(APPEND ${TRANSLATION_RESOURCES} "</qresource>\n\n</RCC>\n")
89
90
ENDIF(SUPPORT_TRANSLATIONS)

91
ADD_EXECUTABLE(${TARGET} ${TARGET_TYPE} ${EXTRA_LIBS_SRC} ${SOURCES} ${RESOURCES} ${QM_FILES} ${TRANSLATION_RESOURCES})
92

93
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/")
94
TARGET_LINK_LIBRARIES(${TARGET} ${QT_LIBRARIES})
Mathias Bavay's avatar
Mathias Bavay committed
95
96
97
98
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES
	RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
	CLEAN_DIRECT_OUTPUT 1
	OUTPUT_NAME ${TARGET})
99
INSTALL(TARGETS ${TARGET} RUNTIME DESTINATION bin ${INSTALL_OSX} COMPONENT exe)
100

101
102
# Retrieve the absolute path to qmake and then use that path to find
# the binaries
103
GET_TARGET_PROPERTY(_qmake_executable Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
104
GET_FILENAME_COMPONENT(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
105
106
107
108
109
110
111
112

IF(WIN32)
	FIND_PROGRAM(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
	ADD_CUSTOM_COMMAND(TARGET ${TARGET} POST_BUILD
	COMMAND "${CMAKE_COMMAND}" -E
		env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
			"$<TARGET_FILE:${TARGET}>"
	COMMENT "Running windeployqt...")
113
ENDIF(WIN32)
114
115
116
IF(APPLE)
	FIND_PROGRAM(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}")
	ADD_CUSTOM_COMMAND(TARGET ${TARGET} POST_BUILD
117
118
119
120
		COMMAND "${MACDEPLOYQT_EXECUTABLE}" "bin/inishell.app" -always-overwrite
		COMMENT "Running macdeployqt..."
	)
ENDIF(APPLE)
121

Mathias Bavay's avatar
Mathias Bavay committed
122
123
###########################################################
# Custom targets
Mathias Bavay's avatar
Mathias Bavay committed
124
125
ADD_CUSTOM_TARGET(distclean make clean
	COMMAND cmake -E remove CMakeCache.txt CPackSourceConfig.cmake CPackConfig.cmake CTestTestfile.cmake DartConfiguration.tcl cmake_install.cmake cmake_uninstall.cmake install_manifest.txt Makefile
126
	COMMAND cmake -E remove bin/inishell bin/inishell.* ${QM_FILES}
Mathias Bavay's avatar
Mathias Bavay committed
127
128
129
130
131
	COMMAND cmake -E remove */CMakeCache.txt */CTestTestfile.cmake */cmake_install.cmake
	COMMAND cmake -E remove */*/CMakeCache.txt */*/CTestTestfile.cmake */*/cmake_install.cmake
	COMMAND cmake -E remove_directory CMakeFiles
	COMMAND cmake -E remove_directory build/tmp/obj tmp/obj inishell_autogen
)
Mathias Bavay's avatar
Mathias Bavay committed
132
133
134
135
136
137
138
139
140

#for the uninstall target
CONFIGURE_FILE(
	"${PROJECT_SOURCE_DIR}/tools/cmake/cmake_uninstall.cmake.in"
	"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
	IMMEDIATE @ONLY
)
ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

141
#for the install target
142
143
144
145
146
SET(XML_DEST inishell-apps)
IF((UNIX) AND (NOT APPLE))
	SET(XML_DEST share/inishell-apps)
ENDIF()

147
FILE(GLOB xmlfiles "inishell-apps/*.xml")
148
INSTALL(FILES ${xmlfiles} DESTINATION ${XML_DEST} COMPONENT resources)
Mathias Bavay's avatar
Mathias Bavay committed
149
FILE(GLOB pngfiles "inishell-apps/*.png")
150
INSTALL(FILES ${pngfiles} DESTINATION ${XML_DEST} COMPONENT resources)
151
152
153
154
155
156
157
158
159
160
161
162
163
164
IF(WIN32)
	FILE(GLOB dlls "bin/*.dll")
	INSTALL(FILES ${dlls} DESTINATION bin COMPONENT exe)
	INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/bearer DESTINATION bin COMPONENT exe)
	INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/iconengines DESTINATION bin COMPONENT exe)
	INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/imageformats DESTINATION bin COMPONENT exe)
	INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/platforms DESTINATION bin COMPONENT exe)
	INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/styles DESTINATION bin COMPONENT exe)
	INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/translations DESTINATION bin COMPONENT exe)
ENDIF(WIN32)

###########################################################
## CPACK section
###########################################################
165
166
167
168
169
170
171
172
173
174
175
176
177
178
SET(CPACK_BUNDLE_METEOIO ON CACHE BOOL "Pack a MeteoIO converter application")
IF(CPACK_BUNDLE_METEOIO)
	#bundle MeteoIO
	FIND_PACKAGE(MeteoIO REQUIRED)
	SET(ALL_RX_PERM OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
	FILE(GLOB meteoio_libs "${METEOIO_ROOT}/lib/libmeteo*.${DLL_EXT}")
	IF(WIN32)
		INSTALL(FILES ${meteoio_libs} DESTINATION bin COMPONENT meteoio)
	ELSE(WIN32)
		INSTALL(FILES ${meteoio_libs} DESTINATION lib COMPONENT meteoio)
	ENDIF(WIN32)
	FILE(GLOB meteoio_bins "${METEOIO_ROOT}/bin/meteoio_timeserie*")
	INSTALL(FILES ${meteoio_bins} DESTINATION bin PERMISSIONS ${ALL_RX_PERM} COMPONENT meteoio)
ENDIF(CPACK_BUNDLE_METEOIO)
179

Mathias Bavay's avatar
Mathias Bavay committed
180
181
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Inishell Graphical User Interface dynamic generator for numerical models")
SET(CPACK_PACKAGE_DESCRIPTION "An XML description of the input fields necessary to configure a given numerical model is used to generate on the fly a Graphical User Interface that lets the user configure the numerical model and even run it if so configured")
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/Welcome.txt")
SET(CPACK_PACKAGE_NAME "Inishell")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
SET(CPACK_PACKAGE_CONTACT "Mathias Bavay <Mathias.Bavay@wsl.ch>")
SET(CPACK_PACKAGE_VENDOR "WSL Institute for Snow and Avalanche Research")
SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/resources/icons\\\\inishell_192.ico")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
SET(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/Welcome.txt")
SET(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/Readme.txt")

SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
SET(VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${VERSION}-${CPACK_ARCH}")

#installation by components for formats that support it
#SET(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE 1)
SET(CPACK_COMPONENTS_ALL exe resources meteoio)
202
203
SET(CPACK_COMPONENT_EXE_DISPLAY_NAME "Inishell application")
SET(CPACK_COMPONENT_EXE_DESCRIPTION "The Inishell applications itself with what it needs to run")
204
205
206
207
208
209
210
SET(CPACK_COMPONENT_EXE_REQUIRED ON)
SET(CPACK_COMPONENT_RESOURCES_DISPLAY_NAME "Inishell resources")
SET(CPACK_COMPONENT_RESOURCES_DESCRIPTION "Additional files to use Inishell")
IF(CPACK_BUNDLE_METEOIO)
	SET(CPACK_COMPONENT_METEOIO_DISPLAY_NAME "MeteoIO converter application")
	SET(CPACK_COMPONENT_METEOIO_DESCRIPTION "A MeteoIO based application to read/convert/output timeseries")
ENDIF(CPACK_BUNDLE_METEOIO)
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

IF(UNIX)
	IF(APPLE)	#OsX packages: IMG
		SET(CPACK_GENERATOR "DragNDrop")
		SET(CPACK_PACKAGING_INSTALL_PREFIX "/${CPACK_PACKAGE_NAME}")
		SET(CPACK_DMG_FORMAT "UDBZ")
		#SET(CPACK_GENERATOR "Bundle")
		SET(CPACK_BUNDLE_PLIST "${CMAKE_SOURCE_DIR}/tools/inishell.plist")
		SET(MACOSX_BUNDLE_INFO_STRING "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
		SET(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/resources/icons/inishell_192.icns")
		SET(MACOSX_BUNDLE_ICON_FILE "${CPACK_BUNDLE_ICON}")
		SET(MACOSX_BUNDLE_GUI_IDENTIFIER "${CPACK_PACKAGE_DESCRIPTION}")
		SET(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION}")
		SET(CPACK_BUNDLE_NAME "${CPACK_PACKAGE_NAME}")
		SET(MACOSX_BUNDLE_BUNDLE_NAME "${CPACK_PACKAGE_NAME}")
		SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION}")
		SET(MACOSX_BUNDLE_BUNDLE_VERSION "0")
		SET(MACOSX_BUNDLE_COPYRIGHT "${CPACK_PACKAGE_VENDOR}")
		#SET(CPACK_PACKAGING_INSTALL_PREFIX "/Applications/${CPACK_PACKAGE_NAME}")
		SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/resources/icons/inishell_192.icns")
		SET_SOURCE_FILES_PROPERTIES(${CPACK_BUNDLE_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
	ELSE(APPLE)	#Linux packages: rmp, deb and tgz
buergiss's avatar
buergiss committed
233
234
		SET(CPACK_GENERATOR "DEB;RPM;TGZ" CACHE STRING "Which packages to build")
		MARK_AS_ADVANCED(FORCE CPACK_GENERATOR)
235
236
		SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
		SET(CPACK_DEBIAN_PACKAGE_NAME "inishell")
Mathias Bavay's avatar
Mathias Bavay committed
237
238
239
		SET(CPACK_DEBIAN_PACKAGE_SECTION "Education/Science")
		SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libQt5Widgets5,libQt5Xml5,libQt5XmlPatterns5,libQt5Gui5,libQt5Network5,libQt5Core5a") #objdump -p lib/libmeteoio.so | grep NEEDED | tr -s ' ' | cut -d' ' -f3 | tr '\n' ','
		SET(CPACK_DEBIAN_PACKAGE_VERSION "${VERSION}")
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
		#SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386") #dpkg --print-architecture
		IF("${CPACK_ARCH}" STREQUAL "x86_64")
			SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
		ELSE("${CPACK_ARCH}" STREQUAL "x86_64")
			SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_ARCH}")
		ENDIF("${CPACK_ARCH}" STREQUAL "x86_64")
		SET(CPACK_RPM_PACKAGE_NAME "inishell")
		SET(CPACK_RPM_PACKAGE_LICENSE "GPLv3")
		SET(CPACK_RPM_PACKAGE_REQUIRES "libstdc++") #simply libproj for OpenSuse
		SET(CPACK_RPM_PACKAGE_ARCHITECTURE "${CPACK_ARCH}")
		SET(CPACK_RPM_PACKAGE_GROUP "Education/Science")
	ENDIF(APPLE)
ELSE(UNIX)
	IF(WIN32)	#Windows packages
		SET(CPACK_GENERATOR "NSIS")
		SET(CPACK_NSIS_MUI_ICON "${CPACK_PACKAGE_ICON}")
		SET(CPACK_PACKAGE_ICON "${CPACK_PACKAGE_ICON}")
		SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CPACK_PACKAGE_NAME}")
		
		#Main links (they can get overwritten later)
Mathias Bavay's avatar
Mathias Bavay committed
260
		SET(MENU_LINKS_INISHELL "bin/inishell.exe" "Inishell")
261
		SET(MENU_LINKS_INISHELL_APPS ${XML_DEST} "Inishell XML files")
262
		SET(MENU_LINKS_INISHELL_HOME "https://models.slf.ch/p/inishell-ng" "Inishell's home page" )
263
264
		SET(MENU_LINKS_INISHELL_SRC "https://code.wsl.ch/snow-models/inishell" "Inishell's repository")
		
Mathias Bavay's avatar
Mathias Bavay committed
265
		SET(CPACK_NSIS_MENU_LINKS ${MENU_LINKS_INISHELL} ${MENU_LINKS_INISHELL_APPS} ${MENU_LINKS_INISHELL_HOME} ${MENU_LINKS_INISHELL_SRC})
266
267
268
269
		
		#info for the add/uninstall software administration
		SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_NAME}-${VERSION}")
		SET(CPACK_NSIS_INSTALLED_ICON_NAME "${CMAKE_SOURCE_DIR}/resources/icons\\\\inishell_192.ico")
270
		SET(CPACK_NSIS_URL_INFO_ABOUT "https://www.slf.ch")
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
		SET(CPACK_NSIS_HELP_LINK "https://models.slf.ch/p/inishell-ng")
		SET(CPACK_NSIS_CONTACT "${CPACK_PACKAGE_CONTACT}")
		SET(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
	ENDIF(WIN32)
ENDIF(UNIX)

#Source packages
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${VERSION}" CACHE INTERNAL "tarball basename")
SET(CPACK_SOURCE_GENERATOR TGZ)
# The following components are regex's to match anywhere (unless anchored)
# in absolute path + filename to find files or directories to be excluded
# from source tarball.
SET(CPACK_SOURCE_IGNORE_FILES
	"~$"
	"\\\\.svn/"
	"/CMakeFiles/"
	"/CMakeCache*"
	"/cmake_install\\\\.cmake$"
	"/cmake_uninstall\\\\.cmake$"
	"^_CPack_.*/"
	"/CPack*"
	"\\\\.o$"
	"/m4/"
)

INCLUDE(CPack)