WSL/SLF GitLab Repository

CMakeLists.txt 13.6 KB
Newer Older
1
2
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/")
3
4
5
6

# Version of library
SET(VERSION_MAJOR 2 CACHE INTERNAL "")
SET(VERSION_MINOR 0 CACHE INTERNAL "")
7
SET(VERSION_PATCH 1 CACHE INTERNAL "")
8
9
10
11
12
13
14
15
16
17

PROJECT(meteoio)
ADD_SUBDIRECTORY(meteoio)
ADD_SUBDIRECTORY(meteoio/plugins)
ADD_SUBDIRECTORY(meteoio/plugins/gsn)
ADD_SUBDIRECTORY(meteoio/meteolaws)
ADD_SUBDIRECTORY(meteoio/meteofilters)

SET(POPCC popcc)

18
19
SET(LIBPREFIX "lib") #make sure ALL plugins are libXXX for ALL plateforms
SET(CMAKE_IMPORT_LIBRARY_PREFIX "lib") #for Visual C++ import libraries
20

21
###########################################################
22
#platform specific. First, compiler specific flags, then system specific flags
23
SET(DEBUG_ARITHM ON CACHE BOOL "Force crash the application when doing an arithmetic exception")
24

25
IF(CMAKE_COMPILER_IS_GNUCXX)
26
27
28
	SET(WARNINGS "-Wall")
	SET(PROFILING "-pg -fprofile-arcs")
	SET(EXTRA_WARNINGS "-Wextra -ansi -pedantic")
29
	IF(DEBUG_ARITHM)
30
		LIST(APPEND CFLAGS " -DDEBUG_ARITHM -D_USE_MATH_DEFINES") #USE_MATH_DEFINES needed for Win32
31
	ENDIF(DEBUG_ARITHM)
32
33
34
35
36
37
38
	SET(OPTIM "-g -O3 -DNDEBUG")
	EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
	IF (GCC_VERSION VERSION_GREATER 4.2 OR GCC_VERSION VERSION_EQUAL 4.2)
		SET(ARCH_OPTIM  "-march=native -mtune=native")
	ENDIF()
	SET(ARCH_SAFE  "")
	SET(DEBUG "-g3 -O0 -D__DEBUG")
39
40
41
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

IF(MSVC)
42
43
44
45
46
47
48
	#SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs"  FORCE)
	SET(WARNINGS "/W4")
	SET(EXTRA_WARNINGS "/Wp64") #/Wall
	SET(OPTIM "/O2 /Vmb /DNDEBUG /MD")
	SET(ARCH_OPTIM "/arch:SSE2")
	SET(ARCH_SAFE "")
	SET(DEBUG "/Z7 /Od /D__DEBUG /MDd")
49
	LIST(APPEND CFLAGS " /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES") #Za: strict ansi
50
51
52
	IF(DEBUG_ARITHM)
		LIST(APPEND CFLAGS " /EHa ")
	ENDIF(DEBUG_ARITHM)
53
54
ENDIF(MSVC)

55
56
IF(UNIX)
	IF(APPLE)
57
58
59
		SET(PLATFORM "-DAPPLE")
		SET(DLL_EXT "dylib")
		SET(STAT_EXT "a")
60
	ELSE(APPLE)
61
62
63
		SET(PLATFORM "-DLINUX")
		SET(DLL_EXT "so")
		SET(STAT_EXT "a")
64
65
66
	ENDIF(APPLE)
ELSE(UNIX)
	IF(WIN32)
67
68
69
		SET(PLATFORM "-D_WIN32")
		SET(DLL_EXT "dll")
		SET(STAT_EXT "a")
70
71
72
	ENDIF(WIN32)
ENDIF(UNIX)

73
74
75
76
IF(NOT CMAKE_BUILD_TYPE)
	SET(CMAKE_BUILD_TYPE "release" CACHE STRING "Choose the type of build, options are: debug release " FORCE)
	SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
ENDIF(NOT CMAKE_BUILD_TYPE)
77
78

###########################################################
79
80
81
82
#targets providing SETs of compiler options
IF(NOT DEST)
	SET(DEST "safe" CACHE STRING "Choose safe, optimized, hera, par or hera_par (with popc)" FORCE)
ENDIF(NOT DEST)
83

84
IF (DEST STREQUAL "hera_par") #only g++ is supported on hera
85
	#required for AMD64: amdfam10 or fPIC, even for static libs
86
87
	SET(ARCH "-march=amdfam10 -fPIC")
ENDIF(DEST STREQUAL "hera_par")
88

89
90
91
IF (DEST STREQUAL "hera")
	SET(ARCH  "-march=amdfam10")
ENDIF(DEST STREQUAL "hera")
92

93
94
95
IF (DEST STREQUAL "par")
	SET(ARCH  "${ARCH_OPTIM}")
ENDIF(DEST STREQUAL "par")
96

97
98
99
IF (DEST STREQUAL "safe")
	SET(ARCH  "${ARCH_SAFE}")
ENDIF(DEST STREQUAL "safe")
100
101

IF(DEST STREQUAL "optimized")
102
	SET(ARCH  "${ARCH_OPTIM}")
103
104
ENDIF(DEST STREQUAL "optimized")

105
###########################################################
106
107
108
#finally, SET compile flags
SET(CMAKE_CXX_FLAGS_RELEASE "${ARCH} ${OPTIM} ${CFLAGS} ${PLATFORM}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_DEBUG "${DEBUG} ${ARCH} ${CFLAGS} ${PLATFORM} ${WARNINGS} ${EXTRA_WARNINGS}" CACHE STRING "" FORCE)
109

110
111
MESSAGE(STATUS "DEBUG CXXFLAGS  : ${CMAKE_CXX_FLAGS_DEBUG}")
MESSAGE(STATUS "RELEASE CXXFLAGS: ${CMAKE_CXX_FLAGS_RELEASE}")
112
113
114

###########################################################
#plugins
115
116
117
118
119
120
121
122
123
124
125
126
127
SET(PLUGIN_ARCIO ON CACHE BOOL "Compilation ARCIO ON or OFF")
SET(PLUGIN_ARPSIO ON CACHE BOOL "Compilation ARPSIO ON or OFF")
SET(PLUGIN_PGMIO ON CACHE BOOL "Compilation PGMIO ON or OFF")
SET(PLUGIN_BORMAIO OFF CACHE BOOL "Compilation BORMAIO ON or OFF")
SET(PLUGIN_GEOTOPIO ON CACHE BOOL "Compilation GEOTOPIO ON or OFF")
SET(PLUGIN_SNIO ON CACHE BOOL "Compilation SNIO ON or OFF")
SET(PLUGIN_SMETIO ON CACHE BOOL "Compilation SMETIO ON or OFF")
SET(PLUGIN_GRASSIO ON CACHE BOOL "Compilation GRASSIO ON or OFF")
SET(PLUGIN_GSNIO OFF CACHE BOOL "Compilation GSNIO ON or OFF")
SET(PLUGIN_IMISIO OFF CACHE BOOL "Compilation IMISIO ON or OFF")
SET(PLUGIN_COSMOXMLIO OFF CACHE BOOL "Compilation COSMOXMLIO ON or OFF")
SET(PROJ4 OFF CACHE BOOL "Use PROJ4 for the class MapProj ON or OFF")

Mathias Bavay's avatar
Mathias Bavay committed
128
129
#SET(LIBRARY_OUTPUT_DIRECTORY lib)
#SET(ARCHIVE_OUTPUT_DIRECTORY lib)
130
131
132
133
134

#some cmake specific things //HACK: should it not be in the plugin Cmake?
IF (GSOAPPP AND NOT EXISTS ${GSOAPPP})
	SET(GSOAPPP NOTFOUND CACHE FORCE)
ENDIF(GSOAPPP AND NOT EXISTS ${GSOAPPP})
135
136
137

###########################################################
#for the install target
138
139
140
FILE(GLOB hfiles "meteoio/*.h")
FILE(GLOB hlawsfiles "meteoio/meteolaws/*.h")
FILE(GLOB hfilterfiles "meteoio/meteofilters/*.h")
141
142
143

IF(DEST MATCHES "par")
	FILE(GLOB phfiles "${CMAKE_CURRENT_SOURCE_DIR}/meteoio/*.ph")
144
145
	FILE(GLOB modules "${CMAKE_BINARY_DIR}/lib/*.module")
	INSTALL(FILES ${modules} DESTINATION lib/meteoio COMPONENT libraries)
146
147
148
149
150
ENDIF(DEST MATCHES "par")
INSTALL(FILES ${hfiles} ${phfiles} DESTINATION include/meteoio COMPONENT headers)
INSTALL(FILES ${hlawsfiles} DESTINATION include/meteoio/meteolaws COMPONENT headers)
INSTALL(FILES ${hfilterfiles} DESTINATION include/meteoio/meteofilters COMPONENT headers)

151
IF(WIN32) #handle the special case of WIN32 needing import libraries
152
	FILE(GLOB importlibs "lib/libmeteoio*.lib*")
Mathias Bavay's avatar
Mathias Bavay committed
153
ENDIF(WIN32)
154
155
156
FILE(GLOB solibs "lib/libmeteoio*.${DLL_EXT}*")
FILE(GLOB plugins "lib/plugins/lib*.${DLL_EXT}*")
FILE(GLOB alibs "lib/*.${STAT_EXT}*")
157
158

INSTALL(FILES ${solibs} ${importlibs} ${alibs} DESTINATION lib COMPONENT libraries)
159
160
161
INSTALL(FILES ${plugins} DESTINATION lib/meteoio/plugins COMPONENT plugins)


162
ADD_CUSTOM_TARGET(distclean make clean
163
164
165
166
167
168
169
170
171
	COMMAND cmake -E remove CMakeCache.txt cmake_install.cmake meteoio/cmake_install.cmake meteoio/plugins/cmake_install.cmake meteoio/plugins/gsn/cmake_install.cmake
	COMMAND cmake -E remove_directory CMakeFiles
	COMMAND cmake -E remove_directory meteoio/CMakeFiles
	COMMAND cmake -E remove_directory meteoio/plugins/gsn/CMakeFiles
	COMMAND cmake -E remove_directory meteoio/plugins/CMakeFiles)

###########################################################
#for the uninstall target
CONFIGURE_FILE(
172
173
174
	"${PROJECT_SOURCE_DIR}/tools/cmake/cmake_uninstall.cmake.in"
	"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
	IMMEDIATE @ONLY)
175

176
ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
177
178

#Build the documentation if doxygen is found
179
INCLUDE(FindDoxygen)
180
181
182
FIND_PACKAGE(Doxygen)
if (DOXYGEN_FOUND)
	ADD_CUSTOM_TARGET(documentation "doxygen" ${PROJECT_SOURCE_DIR}/meteoio/config.dox)
183
184
185
186
187
188
	GET_TARGET_PROPERTY(DOC_TARGET doc TYPE)
	IF(NOT DOC_TARGET)
		ADD_CUSTOM_TARGET(doc)
	ENDIF(NOT DOC_TARGET)
	ADD_DEPENDENCIES(doc documentation)
ENDIF (DOXYGEN_FOUND)
189
#Install the documentation if the user desires it
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
SET(INSTALL_DOC OFF CACHE BOOL "Install documentation ON or OFF")
IF(INSTALL_DOC)
	IF(WIN32)
		SET(DOC_PATH "doc")
	ELSE(WIN32)
		SET(DOC_PATH "share/doc/${CMAKE_PROJECT_NAME}")
	ENDIF(WIN32)
	IF (DOXYGEN_FOUND)
		INSTALL(DIRECTORY doc/html DESTINATION ${DOC_PATH} COMPONENT documentation)
	ELSE (DOXYGEN_FOUND)
		MESSAGE("Doxygen has not been found and is needed to build online documentation. Please either install doxygen or download a documentation-only package!")
	ENDIF (DOXYGEN_FOUND)
	SET(DOC_FILES License.txt doc/SMET_specifications.pdf meteoio/icons/icon.ico)
	INSTALL(FILES ${DOC_FILES} DESTINATION ${DOC_PATH} COMPONENT documentation)
	install(DIRECTORY doc/examples DESTINATION ${DOC_PATH} COMPONENT examples PATTERN ".svn" EXCLUDE)
ENDIF(INSTALL_DOC)
206

207
208
###########################################################
## CPACK section
209
###########################################################
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
SET(CPACK_PACKAGE_DESCRIPTION "Meteorological preprocessing library")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Meteorological Input/Output preprocessing library: it covers data retrieval, data filtering, data transformations and spatial interpolations. Please refer to the included documentation and the included code examples!")
SET(CPACK_PACKAGE_NAME "MeteoIO")
SET(CPACK_PACKAGE_CONTACT "Mathias Bavay ")
SET(CPACK_PACKAGE_VENDOR "WSL Institute for Snow and Avalanche Research")
SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/meteoio/icons\\\\icon.ico")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/License.txt")

IF (DEST MATCHES "par")
	SET(PACKAGE_EXTRA "-par")
ENDIF(DEST MATCHES "par")
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_ARCH "i386")
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}${PACKAGE_EXTRA}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_ARCH}")
228
229

#installation by components for formats that support it
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
#SET(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE 1)
SET(CPACK_COMPONENTS_ALL libraries headers plugins documentation examples)
SET(CPACK_COMPONENT_libraries_DISPLAY_NAME "MeteoIO library")
SET(CPACK_COMPONENT_libraries_DESCRIPTION "The MeteoIO library itself")
SET(CPACK_COMPONENT_libraries_GROUP Runtime)
SET(CPACK_COMPONENT_headers_DISPLAY_NAME "Header files")
SET(CPACK_COMPONENT_headers_DESCRIPTION "Necessary C++ header files for developing applications using MeteoIO")
SET(CPACK_COMPONENT_headers_GROUP Development)
SET(CPACK_COMPONENT_headers_DEPENDS libraries)
SET(CPACK_COMPONENT_plugins_DISPLAY_NAME "Input/Output Plugins")
SET(CPACK_COMPONENT_plugins_DESCRIPTION "Various plugins for supporting various data formats/protocols")
SET(CPACK_COMPONENT_plugins_GROUP Runtime)
SET(CPACK_COMPONENT_plugins_DEPENDS libraries)
SET(CPACK_COMPONENT_documentation_DISPLAY_NAME "Documentation")
SET(CPACK_COMPONENT_documentation_DESCRIPTION "Documentation of the MeteoIO usage and API both for the end user and the developer using MeteoIO in his/her application")
SET(CPACK_COMPONENT_examples_DISPLAY_NAME "Examples")
SET(CPACK_COMPONENT_examples_DESCRIPTION "C++ Source code of various simple examples of applications with their example data")
SET(CPACK_COMPONENT_examples_GROUP Development)
SET(CPACK_COMPONENT_examples_DEPENDS libraries headers)

SET(CPACK_COMPONENT_Runtime_GROUP "Runtime")
SET(CPACK_COMPONENT_GROUP_Runtime_DESCRIPTION "What you need to run an application based on MeteoIO")
SET(CPACK_COMPONENT_Development_GROUP "Development")
SET(CPACK_COMPONENT_GROUP_Development_DESCRIPTION "What you need to develop an application based on MeteoIO")

#CPACK_ADD_COMPONENT(libraries DISPLAY_NAME "MeteoIO library" DESCRIPTION "The MeteoIO library itself" GROUP Runtime)
# CPACK_ADD_COMPONENT(headers DISPLAY_NAME "Header files" DESCRIPTION "Necessary C++ header files for developing applications using MeteoIO" DEPENDS libraries GROUP Development)
# CPACK_ADD_COMPONENT(plugins DISPLAY_NAME "Input/Output Plugins" DESCRIPTION "Various plugins for supporting various data formats/protocols" DEPENDS libraries GROUP Runtime)
# CPACK_ADD_COMPONENT(documentation DISPLAY_NAME "Documentation" DESCRIPTION "Documentation of the MeteoIO usage and API both for the end user and the developer using MeteoIO in his/her application")
# CPACK_ADD_COMPONENT(examples DISPLAY_NAME "Examples" DESCRIPTION "C++ Source code of various simple examples of applications with their example data" DEPENDS "libraries;headers" GROUP Development)

# CPACK_ADD_COMPONENT_GROUP(Runtime EXPANDED DESCRIPTION "What you need to run an application based on MeteoIO")
# CPACK_ADD_COMPONENT_GROUP(Development EXPANDED DESCRIPTION "What you need to develop an application based on MeteoIO")
263
264
265

IF(UNIX)
	IF(APPLE)
266
267
		SET(CPACK_GENERATOR "PackageMaker")
		#SET(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/Welcome.txt")
268
	ELSE(APPLE)
269
270
271
272
273
274
275
276
277
278
		SET(CPACK_GENERATOR "DEB;RPM;TGZ")
		SET(CPACK_DEBIAN_PACKAGE_NAME "meteoio")
		SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
		SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6, libproj0") #objdump -p lib/libmeteoio.so | grep NEEDED | tr -s ' ' | cut -d' ' -f3 | tr '\n' ','
		SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386") #dpkg --print-architecture
		SET(CPACK_RPM_PACKAGE_NAME "meteoio")
		SET(CPACK_RPM_PACKAGE_LICENSE "LPGLv3")
		SET(CPACK_RPM_PACKAGE_REQUIRES "libstdc++6, libproj4")
		SET(CPACK_RPM_PACKAGE_ARCHITECTURE "i386")
		SET(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
279
280
281
	ENDIF(APPLE)
ELSE(UNIX)
	IF(WIN32)
282
283
284
285
286
		SET(CPACK_GENERATOR "NSIS")
		SET(CPACK_NSIS_MUI_ICON "${CPACK_PACKAGE_ICON}")
		SET(CPACK_PACKAGE_ICON "${CPACK_PACKAGE_ICON}")
		SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}-${VERSION}")
		SET(CPACK_NSIS_MENU_LINKS
287
288
289
290
			"${DOC_PATH}/html/index.html" "MeteoIO documentation"
			"${DOC_PATH}/examples" "MeteoIO examples"
			"https://slfsmm.indefero.net/p/meteoio/" "Home page")
		#info for the add/uninstall software administration
291
292
293
294
		SET(CPACK_NSIS_INSTALLED_ICON_NAME "${DOC_PATH}\\\\icon.ico")
		SET(CPACK_NSIS_URL_INFO_ABOUT "http://www.slf.ch")
		SET(CPACK_NSIS_HELP_LINK "https://slfsmm.indefero.net/p/meteoio")
		SET(CPACK_NSIS_CONTACT "Mathias.Bavay@wsl.ch")
295
296
297
298
	ENDIF(WIN32)
ENDIF(UNIX)


299
300
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${VERSION}" CACHE INTERNAL "tarball basename")
SET(CPACK_SOURCE_GENERATOR TGZ)
301
302
303
# 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.
304
SET(CPACK_SOURCE_IGNORE_FILES
305
306
307
308
309
310
311
312
313
314
315
316
317
	"~$"
	"\\\\.svn/"
	"/CMakeFiles/"
	"/CMakeCache*"
	"/cmake_install\\\\.cmake$"
	"/cmake_uninstall\\\\.cmake$"
	"^_CPack_.*/"
	"/CPack*"
	"\\\\.o$"
	"/m4/"
)

INCLUDE(CPack)