forked from openmeeg/matio-openmeeg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
197 lines (154 loc) · 5.25 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
set(PACKAGE_VERSION_MAJOR "1")
set(PACKAGE_VERSION_MINOR "5")
set(PACKAGE_VERSION_PATCH "2")
set(VERSION ${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
# Options
option(ENABLE_FORTRAN "Enable fortran interface to mat library")
set(EXTRA_LANGAGE)
if (ENABLE_FORTRAN)
set(EXTRA_LANGAGE Fortran)
set(MATIO_FORTRAN TRUE)
endif()
# CXX is added just for GenerateExportHeader that uses the
# CXX compiler to check or visibilityy. It can disappear
# as soon as this cmake bug is corrected.
project(MATIO C CXX ${EXTRA_LANGAGE})
cmake_minimum_required(VERSION 2.8)
include(FindLibrary)
include(DefaultFileVersion)
include(GenerateConfigFile)
option(USE_SYSTEM_ZLIB "Use installed zlib if possible" ON)
mark_as_advanced(USE_SYSTEM_ZLIB)
option(MAT73 "Matlab 7.3 support" ON)
unset(OPT)
if (NOT MAT73)
set(OPT OPTIONAL)
endif()
#set(FIND_PACKAGE_DEBUG 1)
Dependencies(matio ZLIB ${OPT} HDF5)
#message("[[Found: ZLIB: ${ZLIB_INCLUDE_DIRS} HDF5: ${HDF5_INCLUDE_DIRS}]]")
include_directories(${ZLIB_INCLUDE_DIR})
set(HAVE_ZLIB 1)
set(Z_PREFIX)
# Tell Hdf5 to disable its own zlib detection (and to use this version).
set(H5_ZLIB_HEADER zlib.h)
if (MAT73)
include(HDF5Version)
if (HDF5_VERSION_STRING VERSION_LESS "1.8.9")
MESSAGE(SEND_ERROR "hdf5 library must be 1.8.9 or higher. Using internal copy.")
endif()
include_directories(${HDF5_INCLUDE_DIRS})
if (NOT BUILD_SHARED_LIBS)
set(TARGET_SUFFIX -static)
endif()
set(HAVE_HDF5 1)
set(HDF5_LIB ${HDF5_LIBRARIES})
endif()
# It may seem that ${CMAKE_ARCH_TRIPLET} might appear in a future cmake release.
# For now, do for the best.
set(MATIO_PLATFORM ${CMAKE_SYSTEM_PROCESSOR}-unknown-${CMAKE_SYSTEM_NAME})
# Options
option(ENABLE_PROFILE "Turn on profile")
if (ENABLE_PROFILE)
endif()
option(EXTENDED_SP "Enable extended sparse matrix data types not supported in Matlab" ON)
if (EXTENDED_SP)
set(EXTENDED_SPARSE 1)
endif()
include (Documentation optionAL)
if (BUILD_DOCUMENTATION)
add_subdirectory(documentation)
endif()
# Check headers
# Public header
# Provide stdint.h for windows, if it is not already there.
# MSVC starts to include stddint.h only from MSVC10 !!!
# Append after in order to use the system includes if they are provided.
if (WIN32 AND NOT CYGWIN_INSTALL_PATH)
set(CMAKE_REQUIRED_INCLUDES ${INTTYPES_INCLUDES})
include_directories(AFTER SYSTEM ${INTTYPES_INCLUDES})
endif()
include(CheckIncludeFile)
include(CheckHeaderSTDC)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(strings.h HAVE_STRINGS_H)
check_include_file(ctype.h HAVE_CTYPE_H)
check_include_file(stdlib.h HAVE_STDLIB_H)
check_include_file(string.h HAVE_STRING_H)
#CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
check_header_stdc()
# type size
include(CheckTypeSize)
set(TYPES double float long int short char size_t)
foreach(TYPE ${TYPES})
string(TOUPPER ${TYPE} TYPE_UPPER)
check_type_size(${TYPE} SIZEOF_${TYPE_UPPER})
endforeach()
check_type_size("long long" LONG_LONG)
set(HAVE_LONG_LONG ${HAVE_${LONG_LONG}})
set(SIZEOF_LONG_LONG ${LONG_LONG})
check_type_size("long double" LONG_DOUBLE)
set(HAVE_LONG_DOUBLE ${HAVE_${LONG_DOUBLE}})
check_type_size(void* SIZEOF_VOID_P)
set(TYPES uint8_t uint16_t uint32_t uint64_t int8_t int16_t int32_t int64_t)
foreach(TYPE ${TYPES})
string(TOUPPER ${TYPE} TYPE_UPPER)
check_type_size(${TYPE} ${TYPE_UPPER})
set(HAVE_MAT_${TYPE_UPPER} ${HAVE_${TYPE_UPPER}})
set(SIZEOF_${TYPE_UPPER} ${${TYPE_UPPER}})
if (NOT ${${TYPE_UPPER}})
message(FATAL_ERROR "Unknown type ${TYPE}")
endif()
endforeach()
# Check functions
include(CheckFunctionExists)
check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(vasprintf HAVE_VASPRINTF)
check_function_exists(asprintf HAVE_ASPRINTF)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(getopt HAVE_GETOPT)
include(VA_COPY)
VA_COPY()
if (WIN32)
if (NOT LIBRARY_OUTPUT_PATH)
set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if (NOT EXECUTABLE_OUTPUT_PATH)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
endif()
endif()
if (NOT HAVE_GETOPT)
add_subdirectory(getopt)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/getopt)
set(GETOPT_LIB gnu)
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(src)
add_subdirectory(tools)
# pkg-config
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/lib")
set(includedir "\${prefix}/include")
set(ZLIB_LIBS ${ZLIB_LIBRARIES})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/matio.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/matio.pc"
IMMEDIATE @ONLY)
GenerateConfigFile(matio LIBRARIES matio)
#INSTALL(EXPORT matio DESTINATION )
# Testing
option(MATIO_BUILD_TESTING "Build matio tests" ON)
if (MATIO_BUILD_TESTING)
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/datasets)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
endif()
include(Uninstall)
include(Packaging)