Merge topic 'CheckTypeSize-std-types'

7f786c6a40 Tests: Cover CheckTypeSize with uint8_t and std::uint8_t
371072e9e1 CheckTypeSize: Use C++-style headers to check for std:: types

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5008
This commit is contained in:
Brad King
2020-07-23 12:25:04 +00:00
committed by Kitware Robot
4 changed files with 77 additions and 21 deletions
+39 -21
View File
@@ -89,25 +89,7 @@ function(__check_type_size_impl type var map builtin language)
message(CHECK_START "Check size of ${type}")
endif()
# Include header files.
set(headers)
if(builtin)
if(HAVE_SYS_TYPES_H)
string(APPEND headers "#include <sys/types.h>\n")
endif()
if(HAVE_STDINT_H)
string(APPEND headers "#include <stdint.h>\n")
endif()
if(HAVE_STDDEF_H)
string(APPEND headers "#include <stddef.h>\n")
endif()
endif()
foreach(h ${CMAKE_EXTRA_INCLUDE_FILES})
string(APPEND headers "#include \"${h}\"\n")
endforeach()
# Perform the check.
# Perform language check
if(language STREQUAL "C")
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c)
elseif(language STREQUAL "CXX")
@@ -115,6 +97,37 @@ function(__check_type_size_impl type var map builtin language)
else()
message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n")
endif()
# Include header files.
set(headers)
if(builtin)
if(language STREQUAL "CXX" AND type MATCHES "^std::")
if(HAVE_SYS_TYPES_H)
string(APPEND headers "#include <sys/types.h>\n")
endif()
if(HAVE_CSTDINT)
string(APPEND headers "#include <cstdint>\n")
endif()
if(HAVE_CSTDDEF)
string(APPEND headers "#include <cstddef>\n")
endif()
else()
if(HAVE_SYS_TYPES_H)
string(APPEND headers "#include <sys/types.h>\n")
endif()
if(HAVE_STDINT_H)
string(APPEND headers "#include <stdint.h>\n")
endif()
if(HAVE_STDDEF_H)
string(APPEND headers "#include <stddef.h>\n")
endif()
endif()
endif()
foreach(h ${CMAKE_EXTRA_INCLUDE_FILES})
string(APPEND headers "#include \"${h}\"\n")
endforeach()
# Perform the check.
set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin)
configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY)
try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src}
@@ -232,8 +245,13 @@ macro(CHECK_TYPE_SIZE TYPE VARIABLE)
check_include_file(stddef.h HAVE_STDDEF_H)
elseif(_language STREQUAL "CXX")
check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
check_include_file_cxx(stdint.h HAVE_STDINT_H)
check_include_file_cxx(stddef.h HAVE_STDDEF_H)
if("${TYPE}" MATCHES "^std::")
check_include_file_cxx(cstdint HAVE_CSTDINT)
check_include_file_cxx(cstddef HAVE_CSTDDEF)
else()
check_include_file_cxx(stdint.h HAVE_STDINT_H)
check_include_file_cxx(stddef.h HAVE_STDDEF_H)
endif()
endif()
endif()
unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)