| 1 |
# |
| 2 |
# Copyright by The HDF Group. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# This file is part of HDF5. The full HDF5 copyright notice, including |
| 6 |
# terms governing use, modification, and redistribution, is contained in |
| 7 |
# the COPYING file, which can be found at the root of the source code |
| 8 |
# distribution tree, or in https://www.hdfgroup.org/licenses. |
| 9 |
# If you do not have access to either file, you may request a copy from |
| 10 |
# [email protected]. |
| 11 |
# |
| 12 |
# |
| 13 |
# This file provides functions for C++ support. |
| 14 |
# |
| 15 |
# ITK --start |
| 16 |
if(POLICY CMP0075) |
| 17 |
cmake_policy(SET CMP0075 NEW) # CMake 3.12.1: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. |
| 18 |
endif() |
| 19 |
# ITK --stop |
| 20 |
|
| 21 |
#------------------------------------------------------------------------------- |
| 22 |
ENABLE_LANGUAGE (CXX) |
| 23 |
set (HDF_PREFIX "H5") |
| 24 |
|
| 25 |
#------------------------------------------------------------------------------- |
| 26 |
# Fix CXX flags if we are compiling staticly on Windows using |
| 27 |
# Windows_MT.cmake from config/cmake/UserMacros |
| 28 |
#------------------------------------------------------------------------------- |
| 29 |
if (BUILD_STATIC_CRT_LIBS) |
| 30 |
TARGET_STATIC_CRT_FLAGS () |
| 31 |
endif () |
| 32 |
|
| 33 |
#----------------------------------------------------------------------------- |
| 34 |
# Configure Checks which require CXX compilation must go in here |
| 35 |
# not in the main ConfigureChecks.cmake files, because if the user has |
| 36 |
# no CXX compiler, problems arise. |
| 37 |
#----------------------------------------------------------------------------- |
| 38 |
include (CheckIncludeFileCXX) |
| 39 |
include (TestForSTDNamespace) |
| 40 |
|
| 41 |
# IF the c compiler found stdint, check the C++ as well. On some systems this |
| 42 |
# file will be found by C but not C++, only do this test IF the C++ compiler |
| 43 |
# has been initialized (e.g. the project also includes some c++) |
| 44 |
if (${HDF_PREFIX}_HAVE_STDINT_H AND CMAKE_CXX_COMPILER_LOADED) |
| 45 |
CHECK_INCLUDE_FILE_CXX ("stdint.h" ${HDF_PREFIX}_HAVE_STDINT_H_CXX) |
| 46 |
if (NOT ${HDF_PREFIX}_HAVE_STDINT_H_CXX) |
| 47 |
set (${HDF_PREFIX}_HAVE_STDINT_H "" CACHE INTERNAL "Have includes HAVE_STDINT_H") |
| 48 |
set (USE_INCLUDES ${USE_INCLUDES} "stdint.h") |
| 49 |
endif () |
| 50 |
endif () |
| 51 |
|
| 52 |
# For other CXX specific tests, use this MACRO. |
| 53 |
macro (HDF_CXX_FUNCTION_TEST OTHER_TEST) |
| 54 |
if (NOT DEFINED ${OTHER_TEST}) |
| 55 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS "-D${OTHER_TEST} ${CMAKE_REQUIRED_FLAGS}") |
| 56 |
set (OTHER_TEST_ADD_LIBRARIES) |
| 57 |
if (HDF5_REQUIRED_LIBRARIES) |
| 58 |
set (OTHER_TEST_ADD_LIBRARIES "-DLINK_LIBRARIES:STRING=${HDF5_REQUIRED_LIBRARIES}") |
| 59 |
endif () |
| 60 |
|
| 61 |
foreach (def |
| 62 |
HAVE_SYS_TIME_H |
| 63 |
HAVE_UNISTD_H |
| 64 |
HAVE_SYS_TYPES_H |
| 65 |
HAVE_SYS_SOCKET_H |
| 66 |
HAVE_SYS_FILE_H |
| 67 |
) |
| 68 |
if ("${${HDF_PREFIX}_${def}}") |
| 69 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS "${MACRO_CHECK_FUNCTION_DEFINITIONS} -D${def}") |
| 70 |
endif () |
| 71 |
endforeach () |
| 72 |
|
| 73 |
if (LARGEFILE) |
| 74 |
set (MACRO_CHECK_FUNCTION_DEFINITIONS |
| 75 |
"${MACRO_CHECK_FUNCTION_DEFINITIONS} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" |
| 76 |
) |
| 77 |
endif () |
| 78 |
|
| 79 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 80 |
message (TRACE "Performing ${OTHER_TEST}") |
| 81 |
endif () |
| 82 |
TRY_COMPILE (${OTHER_TEST} |
| 83 |
${CMAKE_BINARY_DIR} |
| 84 |
${HDF_RESOURCES_EXT_DIR}/HDFCXXTests.cpp |
| 85 |
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} |
| 86 |
"${OTHER_TEST_ADD_LIBRARIES}" |
| 87 |
OUTPUT_VARIABLE OUTPUT |
| 88 |
) |
| 89 |
if (${OTHER_TEST} EQUAL 0) |
| 90 |
set (${OTHER_TEST} 1 CACHE INTERNAL "CXX test ${FUNCTION}") |
| 91 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 92 |
message (VERBOSE "Performing CXX Test ${OTHER_TEST} - Success") |
| 93 |
endif () |
| 94 |
else () |
| 95 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 96 |
message (VERBOSE "Performing CXX Test ${OTHER_TEST} - Failed") |
| 97 |
endif () |
| 98 |
set (${OTHER_TEST} "" CACHE INTERNAL "CXX test ${FUNCTION}") |
| 99 |
file (APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log |
| 100 |
"Performing CXX Test ${OTHER_TEST} failed with the following output:\n" |
| 101 |
"${OUTPUT}\n" |
| 102 |
) |
| 103 |
endif () |
| 104 |
endif () |
| 105 |
endmacro () |
| 106 |
|
| 107 |
#----------------------------------------------------------------------------- |
| 108 |
# Check a bunch of cxx functions |
| 109 |
#----------------------------------------------------------------------------- |
| 110 |
if (CMAKE_CXX_COMPILER_LOADED) |
| 111 |
foreach (cxx_test |
| 112 |
CXX_HAVE_OFFSETOF |
| 113 |
) |
| 114 |
HDF_CXX_FUNCTION_TEST (${cxx_test}) |
| 115 |
endforeach () |
| 116 |
endif () |