| 1 |
#----------------------------------------------------------------------------- |
| 2 |
# Include all the necessary files for macros |
| 3 |
#----------------------------------------------------------------------------- |
| 4 |
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake) |
| 5 |
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) |
| 6 |
include (${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake) |
| 7 |
include (${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake) |
| 8 |
include (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake) |
| 9 |
include (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake) |
| 10 |
include (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake) |
| 11 |
include (${CMAKE_ROOT}/Modules/CheckVariableExists.cmake) |
| 12 |
if(CMAKE_CXX_COMPILER) |
| 13 |
include (${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake) |
| 14 |
endif(CMAKE_CXX_COMPILER) |
| 15 |
|
| 16 |
#----------------------------------------------------------------------------- |
| 17 |
# APPLE/Darwin setup |
| 18 |
#----------------------------------------------------------------------------- |
| 19 |
if (APPLE) |
| 20 |
list (LENGTH CMAKE_OSX_ARCHITECTURES ARCH_LENGTH) |
| 21 |
if (ARCH_LENGTH GREATER 1) |
| 22 |
set (CMAKE_OSX_ARCHITECTURES "" CACHE STRING "" FORCE) |
| 23 |
message(FATAL_ERROR "Building Universal Binaries on OS X is NOT supported by the H5BLOSC project. This is" |
| 24 |
"due to technical reasons. The best approach would be build each architecture in separate directories" |
| 25 |
"and use the 'lipo' tool to combine them into a single executable or library. The 'CMAKE_OSX_ARCHITECTURES'" |
| 26 |
"variable has been set to a blank value which will build the default architecture for this system.") |
| 27 |
endif () |
| 28 |
set (${H5BLOSC_PREFIX}_AC_APPLE_UNIVERSAL_BUILD 0) |
| 29 |
endif (APPLE) |
| 30 |
|
| 31 |
# Check for Darwin (not just Apple - we also want to catch OpenDarwin) |
| 32 |
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 33 |
set (${H5BLOSC_PREFIX}_HAVE_DARWIN 1) |
| 34 |
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 35 |
|
| 36 |
# Check for Solaris |
| 37 |
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 38 |
set (${H5BLOSC_PREFIX}_HAVE_SOLARIS 1) |
| 39 |
endif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 40 |
|
| 41 |
#----------------------------------------------------------------------------- |
| 42 |
# This MACRO checks IF the symbol exists in the library and IF it |
| 43 |
# does, it appends library to the list. |
| 44 |
#----------------------------------------------------------------------------- |
| 45 |
set (LINK_LIBS "") |
| 46 |
MACRO (CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE) |
| 47 |
CHECK_LIBRARY_EXISTS ("${LIBRARY};${LINK_LIBS}" ${SYMBOL} "" ${VARIABLE}) |
| 48 |
if (${VARIABLE}) |
| 49 |
set (LINK_LIBS ${LINK_LIBS} ${LIBRARY}) |
| 50 |
endif (${VARIABLE}) |
| 51 |
ENDMACRO (CHECK_LIBRARY_EXISTS_CONCAT) |
| 52 |
|
| 53 |
# ---------------------------------------------------------------------- |
| 54 |
# WINDOWS Hard code Values |
| 55 |
# ---------------------------------------------------------------------- |
| 56 |
|
| 57 |
set (WINDOWS) |
| 58 |
if (WIN32) |
| 59 |
if (MINGW) |
| 60 |
set (${H5BLOSC_PREFIX}_HAVE_MINGW 1) |
| 61 |
set (WINDOWS 1) # MinGW tries to imitate Windows |
| 62 |
set (CMAKE_REQUIRED_FLAGS "-DWIN32_LEAN_AND_MEAN=1 -DNOGDI=1") |
| 63 |
endif (MINGW) |
| 64 |
set (${H5BLOSC_PREFIX}_HAVE_WIN32_API 1) |
| 65 |
set (CMAKE_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib") |
| 66 |
if (NOT UNIX AND NOT MINGW) |
| 67 |
set (WINDOWS 1) |
| 68 |
set (CMAKE_REQUIRED_FLAGS "/DWIN32_LEAN_AND_MEAN=1 /DNOGDI=1") |
| 69 |
if (MSVC) |
| 70 |
set (${H5BLOSC_PREFIX}_HAVE_VISUAL_STUDIO 1) |
| 71 |
endif (MSVC) |
| 72 |
endif (NOT UNIX AND NOT MINGW) |
| 73 |
endif (WIN32) |
| 74 |
|
| 75 |
if (WINDOWS) |
| 76 |
set (${H5BLOSC_PREFIX}_HAVE_STDDEF_H 1) |
| 77 |
set (${H5BLOSC_PREFIX}_HAVE_SYS_STAT_H 1) |
| 78 |
set (${H5BLOSC_PREFIX}_HAVE_SYS_TYPES_H 1) |
| 79 |
set (${H5BLOSC_PREFIX}_HAVE_LIBM 1) |
| 80 |
set (${H5BLOSC_PREFIX}_HAVE_STRDUP 1) |
| 81 |
set (${H5BLOSC_PREFIX}_HAVE_SYSTEM 1) |
| 82 |
set (${H5BLOSC_PREFIX}_HAVE_LONGJMP 1) |
| 83 |
if (NOT MINGW) |
| 84 |
set (${H5BLOSC_PREFIX}_HAVE_GETHOSTNAME 1) |
| 85 |
endif (NOT MINGW) |
| 86 |
set (${H5BLOSC_PREFIX}_HAVE_FUNCTION 1) |
| 87 |
set (${H5BLOSC_PREFIX}_GETTIMEOFDAY_GIVES_TZ 1) |
| 88 |
set (${H5BLOSC_PREFIX}_HAVE_TIMEZONE 1) |
| 89 |
set (${H5BLOSC_PREFIX}_HAVE_GETTIMEOFDAY 1) |
| 90 |
if (MINGW) |
| 91 |
set (${H5BLOSC_PREFIX}_HAVE_WINSOCK2_H 1) |
| 92 |
endif (MINGW) |
| 93 |
set (${H5BLOSC_PREFIX}_HAVE_LIBWS2_32 1) |
| 94 |
set (${H5BLOSC_PREFIX}_HAVE_LIBWSOCK32 1) |
| 95 |
endif (WINDOWS) |
| 96 |
|
| 97 |
# ---------------------------------------------------------------------- |
| 98 |
# END of WINDOWS Hard code Values |
| 99 |
# ---------------------------------------------------------------------- |
| 100 |
|
| 101 |
#----------------------------------------------------------------------------- |
| 102 |
# Check for the math library "m" |
| 103 |
#----------------------------------------------------------------------------- |
| 104 |
if (NOT WINDOWS) |
| 105 |
CHECK_LIBRARY_EXISTS_CONCAT ("m" ceil ${H5BLOSC_PREFIX}_HAVE_LIBM) |
| 106 |
CHECK_LIBRARY_EXISTS_CONCAT ("ws2_32" WSAStartup ${H5BLOSC_PREFIX}_HAVE_LIBWS2_32) |
| 107 |
CHECK_LIBRARY_EXISTS_CONCAT ("wsock32" gethostbyname ${H5BLOSC_PREFIX}_HAVE_LIBWSOCK32) |
| 108 |
endif (NOT WINDOWS) |
| 109 |
|
| 110 |
# UCB (BSD) compatibility library |
| 111 |
CHECK_LIBRARY_EXISTS_CONCAT ("ucb" gethostname ${HDF_PREFIX}_HAVE_LIBUCB) |
| 112 |
|
| 113 |
# For other tests to use the same libraries |
| 114 |
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LINK_LIBS}) |
| 115 |
|
| 116 |
set (USE_INCLUDES "") |
| 117 |
if (WINDOWS) |
| 118 |
set (USE_INCLUDES ${USE_INCLUDES} "windows.h") |
| 119 |
endif (WINDOWS) |
| 120 |
|
| 121 |
# For other other specific tests, use this MACRO. |
| 122 |
MACRO (H5BLOSC_FUNCTION_TEST OTHER_TEST) |
| 123 |
if ("${H5BLOSC_PREFIX}_${OTHER_TEST}" MATCHES "^${H5BLOSC_PREFIX}_${OTHER_TEST}$") |
| 124 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS "-D${OTHER_TEST} ${CMAKE_REQUIRED_FLAGS}") |
| 125 |
set (OTHER_TEST_ADD_LIBRARIES) |
| 126 |
if (CMAKE_REQUIRED_LIBRARIES) |
| 127 |
set (OTHER_TEST_ADD_LIBRARIES "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") |
| 128 |
endif (CMAKE_REQUIRED_LIBRARIES) |
| 129 |
|
| 130 |
foreach (def ${H5BLOSC_EXTRA_TEST_DEFINITIONS}) |
| 131 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS "${MACRO_CHECK_FUNCTION_DEFINITIONS} -D${def}=${${def}}") |
| 132 |
endforeach (def) |
| 133 |
|
| 134 |
foreach (def |
| 135 |
HAVE_SYS_TIME_H |
| 136 |
HAVE_UNISTD_H |
| 137 |
HAVE_SYS_TYPES_H |
| 138 |
HAVE_SYS_SOCKET_H |
| 139 |
) |
| 140 |
if ("${${H5BLOSC_PREFIX}_${def}}") |
| 141 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS "${MACRO_CHECK_FUNCTION_DEFINITIONS} -D${def}") |
| 142 |
endif ("${${H5BLOSC_PREFIX}_${def}}") |
| 143 |
endforeach (def) |
| 144 |
|
| 145 |
if (LARGEFILE) |
| 146 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS |
| 147 |
"${MACRO_CHECK_FUNCTION_DEFINITIONS} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" |
| 148 |
) |
| 149 |
endif (LARGEFILE) |
| 150 |
|
| 151 |
#message (STATUS "Performing ${OTHER_TEST}") |
| 152 |
try_compile (${OTHER_TEST} |
| 153 |
${CMAKE_BINARY_DIR} |
| 154 |
${H5BLOSC_RESOURCES_DIR}/H5BLOSCTests.c |
| 155 |
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} |
| 156 |
"${OTHER_TEST_ADD_LIBRARIES}" |
| 157 |
OUTPUT_VARIABLE OUTPUT |
| 158 |
) |
| 159 |
if (${OTHER_TEST}) |
| 160 |
set (${H5BLOSC_PREFIX}_${OTHER_TEST} 1 CACHE INTERNAL "Other test ${FUNCTION}") |
| 161 |
message (STATUS "Performing Other Test ${OTHER_TEST} - Success") |
| 162 |
else (${OTHER_TEST}) |
| 163 |
message (STATUS "Performing Other Test ${OTHER_TEST} - Failed") |
| 164 |
set (${H5BLOSC_PREFIX}_${OTHER_TEST} "" CACHE INTERNAL "Other test ${FUNCTION}") |
| 165 |
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 166 |
"Performing Other Test ${OTHER_TEST} failed with the following output:\n" |
| 167 |
"${OUTPUT}\n" |
| 168 |
) |
| 169 |
endif (${OTHER_TEST}) |
| 170 |
endif ("${H5BLOSC_PREFIX}_${OTHER_TEST}" MATCHES "^${H5BLOSC_PREFIX}_${OTHER_TEST}$") |
| 171 |
ENDMACRO (H5BLOSC_FUNCTION_TEST) |
| 172 |
|
| 173 |
H5BLOSC_FUNCTION_TEST (STDC_HEADERS) |
| 174 |
|
| 175 |
#----------------------------------------------------------------------------- |
| 176 |
|
| 177 |
#----------------------------------------------------------------------------- |
| 178 |
# Check IF header file exists and add it to the list. |
| 179 |
#----------------------------------------------------------------------------- |
| 180 |
MACRO (CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE) |
| 181 |
CHECK_INCLUDE_FILES ("${USE_INCLUDES};${FILE}" ${VARIABLE}) |
| 182 |
if (${VARIABLE}) |
| 183 |
set (USE_INCLUDES ${USE_INCLUDES} ${FILE}) |
| 184 |
endif (${VARIABLE}) |
| 185 |
ENDMACRO (CHECK_INCLUDE_FILE_CONCAT) |
| 186 |
|
| 187 |
#----------------------------------------------------------------------------- |
| 188 |
# Check for the existence of certain header files |
| 189 |
#----------------------------------------------------------------------------- |
| 190 |
CHECK_INCLUDE_FILE_CONCAT ("unistd.h" ${H5BLOSC_PREFIX}_HAVE_UNISTD_H) |
| 191 |
CHECK_INCLUDE_FILE_CONCAT ("sys/stat.h" ${H5BLOSC_PREFIX}_HAVE_SYS_STAT_H) |
| 192 |
CHECK_INCLUDE_FILE_CONCAT ("sys/types.h" ${H5BLOSC_PREFIX}_HAVE_SYS_TYPES_H) |
| 193 |
CHECK_INCLUDE_FILE_CONCAT ("stddef.h" ${H5BLOSC_PREFIX}_HAVE_STDDEF_H) |
| 194 |
CHECK_INCLUDE_FILE_CONCAT ("stdint.h" ${H5BLOSC_PREFIX}_HAVE_STDINT_H) |
| 195 |
|
| 196 |
# IF the c compiler found stdint, check the C++ as well. On some systems this |
| 197 |
# file will be found by C but not C++, only do this test IF the C++ compiler |
| 198 |
# has been initialized (e.g. the project also includes some c++) |
| 199 |
if (${H5BLOSC_PREFIX}_HAVE_STDINT_H AND CMAKE_CXX_COMPILER_LOADED) |
| 200 |
CHECK_INCLUDE_FILE_CXX ("stdint.h" ${H5BLOSC_PREFIX}_HAVE_STDINT_H_CXX) |
| 201 |
if (NOT ${H5BLOSC_PREFIX}_HAVE_STDINT_H_CXX) |
| 202 |
set (${H5BLOSC_PREFIX}_HAVE_STDINT_H "" CACHE INTERNAL "Have includes HAVE_STDINT_H") |
| 203 |
set (USE_INCLUDES ${USE_INCLUDES} "stdint.h") |
| 204 |
endif (NOT ${H5BLOSC_PREFIX}_HAVE_STDINT_H_CXX) |
| 205 |
endif (${H5BLOSC_PREFIX}_HAVE_STDINT_H AND CMAKE_CXX_COMPILER_LOADED) |
| 206 |
|
| 207 |
# Windows |
| 208 |
CHECK_INCLUDE_FILE_CONCAT ("io.h" ${H5BLOSC_PREFIX}_HAVE_IO_H) |
| 209 |
if (NOT CYGWIN) |
| 210 |
CHECK_INCLUDE_FILE_CONCAT ("winsock2.h" ${H5BLOSC_PREFIX}_HAVE_WINSOCK_H) |
| 211 |
endif (NOT CYGWIN) |
| 212 |
|
| 213 |
CHECK_INCLUDE_FILE_CONCAT ("pthread.h" ${H5BLOSC_PREFIX}_HAVE_PTHREAD_H) |
| 214 |
CHECK_INCLUDE_FILE_CONCAT ("string.h" ${H5BLOSC_PREFIX}_HAVE_STRING_H) |
| 215 |
CHECK_INCLUDE_FILE_CONCAT ("strings.h" ${H5BLOSC_PREFIX}_HAVE_STRINGS_H) |
| 216 |
CHECK_INCLUDE_FILE_CONCAT ("time.h" ${H5BLOSC_PREFIX}_HAVE_TIME_H) |
| 217 |
CHECK_INCLUDE_FILE_CONCAT ("stdlib.h" ${H5BLOSC_PREFIX}_HAVE_STDLIB_H) |
| 218 |
CHECK_INCLUDE_FILE_CONCAT ("memory.h" ${H5BLOSC_PREFIX}_HAVE_MEMORY_H) |
| 219 |
CHECK_INCLUDE_FILE_CONCAT ("dlfcn.h" ${H5BLOSC_PREFIX}_HAVE_DLFCN_H) |
| 220 |
CHECK_INCLUDE_FILE_CONCAT ("fcntl.h" ${H5BLOSC_PREFIX}_HAVE_FCNTL_H) |
| 221 |
CHECK_INCLUDE_FILE_CONCAT ("inttypes.h" ${H5BLOSC_PREFIX}_HAVE_INTTYPES_H) |
| 222 |
|
| 223 |
#----------------------------------------------------------------------------- |
| 224 |
# Check for large file support |
| 225 |
#----------------------------------------------------------------------------- |
| 226 |
|
| 227 |
# The linux-lfs option is deprecated. |
| 228 |
set (LINUX_LFS 0) |
| 229 |
|
| 230 |
set (H5BLOSC_EXTRA_C_FLAGS) |
| 231 |
set (H5BLOSC_EXTRA_FLAGS) |
| 232 |
if (NOT WINDOWS) |
| 233 |
if (NOT ${H5BLOSC_PREFIX}_HAVE_SOLARIS) |
| 234 |
# Linux Specific flags |
| 235 |
# This was originally defined as _POSIX_SOURCE which was updated to |
| 236 |
# _POSIX_C_SOURCE=199506L to expose a greater amount of POSIX |
| 237 |
# functionality so clock_gettime and CLOCK_MONOTONIC are defined |
| 238 |
# correctly. |
| 239 |
# POSIX feature information can be found in the gcc manual at: |
| 240 |
# http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html |
| 241 |
set (H5BLOSC_EXTRA_C_FLAGS -D_POSIX_C_SOURCE=199506L) |
| 242 |
# _BSD_SOURCE deprecated in GLIBC >= 2.20 |
| 243 |
try_run (HAVE_DEFAULT_SOURCE_RUN HAVE_DEFAULT_SOURCE_COMPILE |
| 244 |
${CMAKE_BINARY_DIR} |
| 245 |
${H5BLOSC_RESOURCES_DIR}/H5BLOSCTests.c |
| 246 |
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=-DHAVE_DEFAULT_SOURCE |
| 247 |
OUTPUT_VARIABLE OUTPUT |
| 248 |
) |
| 249 |
if (HAVE_DEFAULT_SOURCE_COMPILE AND HAVE_DEFAULT_SOURCE_RUN) |
| 250 |
set (H5BLOSC_EXTRA_FLAGS -D_DEFAULT_SOURCE) |
| 251 |
else (HAVE_DEFAULT_SOURCE_COMPILE AND HAVE_DEFAULT_SOURCE_RUN) |
| 252 |
set (H5BLOSC_EXTRA_FLAGS -D_BSD_SOURCE) |
| 253 |
endif (HAVE_DEFAULT_SOURCE_COMPILE AND HAVE_DEFAULT_SOURCE_RUN) |
| 254 |
|
| 255 |
option (H5BLOSC_ENABLE_LARGE_FILE "Enable support for large (64-bit) files on Linux." ON) |
| 256 |
if (H5BLOSC_ENABLE_LARGE_FILE) |
| 257 |
set (msg "Performing TEST_LFS_WORKS") |
| 258 |
try_run (TEST_LFS_WORKS_RUN TEST_LFS_WORKS_COMPILE |
| 259 |
${CMAKE_BINARY_DIR} |
| 260 |
${H5BLOSC_RESOURCES_DIR}/H5BLOSCTests.c |
| 261 |
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=-DTEST_LFS_WORKS |
| 262 |
OUTPUT_VARIABLE OUTPUT |
| 263 |
) |
| 264 |
if (TEST_LFS_WORKS_COMPILE) |
| 265 |
if (TEST_LFS_WORKS_RUN MATCHES 0) |
| 266 |
set (TEST_LFS_WORKS 1 CACHE INTERNAL ${msg}) |
| 267 |
set (LARGEFILE 1) |
| 268 |
set (H5BLOSC_EXTRA_FLAGS ${H5BLOSC_EXTRA_FLAGS} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE) |
| 269 |
message (STATUS "${msg}... yes") |
| 270 |
else (TEST_LFS_WORKS_RUN MATCHES 0) |
| 271 |
set (TEST_LFS_WORKS "" CACHE INTERNAL ${msg}) |
| 272 |
message (STATUS "${msg}... no") |
| 273 |
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 274 |
"Test TEST_LFS_WORKS Run failed with the following output and exit code:\n ${OUTPUT}\n" |
| 275 |
) |
| 276 |
endif (TEST_LFS_WORKS_RUN MATCHES 0) |
| 277 |
else (TEST_LFS_WORKS_COMPILE ) |
| 278 |
set (TEST_LFS_WORKS "" CACHE INTERNAL ${msg}) |
| 279 |
message (STATUS "${msg}... no") |
| 280 |
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 281 |
"Test TEST_LFS_WORKS Compile failed with the following output:\n ${OUTPUT}\n" |
| 282 |
) |
| 283 |
endif (TEST_LFS_WORKS_COMPILE) |
| 284 |
endif (H5BLOSC_ENABLE_LARGE_FILE) |
| 285 |
set (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${HDF_EXTRA_FLAGS}) |
| 286 |
endif (NOT ${H5BLOSC_PREFIX}_HAVE_SOLARIS) |
| 287 |
endif (NOT WINDOWS) |
| 288 |
|
| 289 |
add_definitions (${H5BLOSC_EXTRA_FLAGS}) |
| 290 |
#----------------------------------------------------------------------------- |
| 291 |
# Check for some functions that are used |
| 292 |
# |
| 293 |
if (NOT WINDOWS) |
| 294 |
foreach (test |
| 295 |
HAVE_ATTRIBUTE |
| 296 |
HAVE_C99_FUNC |
| 297 |
HAVE_FUNCTION |
| 298 |
HAVE_C99_DESIGNATED_INITIALIZER |
| 299 |
SYSTEM_SCOPE_THREADS |
| 300 |
CXX_HAVE_OFFSETOF |
| 301 |
) |
| 302 |
H5BLOSC_FUNCTION_TEST (${test}) |
| 303 |
endforeach (test) |
| 304 |
endif (NOT WINDOWS) |
| 305 |
|