mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-06 14:19:59 -05:00
Merge topic 'CheckTypeSize-std-types'
7f786c6a40Tests: Cover CheckTypeSize with uint8_t and std::uint8_t371072e9e1CheckTypeSize: Use C++-style headers to check for std:: types Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5008
This commit is contained in:
+39
-21
@@ -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)
|
||||
|
||||
@@ -21,6 +21,8 @@ check_type_size("((struct somestruct*)0)->somechar" SIZEOF_STRUCTMEMBER_CHAR)
|
||||
|
||||
# Check CXX types
|
||||
check_type_size(bool SIZEOF_BOOL LANGUAGE CXX)
|
||||
check_type_size(uint8_t SIZEOF_UINT8_T LANGUAGE CXX)
|
||||
check_type_size(std::uint8_t SIZEOF_STD_UINT8_T LANGUAGE CXX)
|
||||
|
||||
set(CMAKE_EXTRA_INCLUDE_FILES someclass.hxx)
|
||||
check_type_size("((ns::someclass*)0)->someint" SIZEOF_NS_CLASSMEMBER_INT LANGUAGE CXX)
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
#ifdef HAVE_STDDEF_H
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
#ifdef HAVE_CSTDINT
|
||||
# include <cstdint>
|
||||
#endif
|
||||
#ifdef HAVE_CSTDDEF
|
||||
# include <cstddef>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -122,6 +128,26 @@ int main()
|
||||
NODEF(SIZEOF_SSIZE_T);
|
||||
#endif
|
||||
|
||||
/* uint8_t */
|
||||
#if defined(SIZEOF_UINT8_T)
|
||||
CHECK(uint8_t, SIZEOF_UINT8_T);
|
||||
# if !defined(HAVE_SIZEOF_UINT8_T)
|
||||
NODEF(HAVE_SIZEOF_UINT8_T);
|
||||
# endif
|
||||
#elif defined(HAVE_SIZEOF_UINT8_T)
|
||||
NODEF(SIZEOF_UINT8_T);
|
||||
#endif
|
||||
|
||||
/* std::uint8_t */
|
||||
#if defined(SIZEOF_STD_UINT8_T)
|
||||
CHECK(std::uint8_t, SIZEOF_STD_UINT8_T);
|
||||
# if !defined(HAVE_SIZEOF_STD_UINT8_T)
|
||||
NODEF(HAVE_SIZEOF_STD_UINT8_T);
|
||||
# endif
|
||||
#elif defined(HAVE_SIZEOF_STD_UINT8_T)
|
||||
NODEF(SIZEOF_STD_UINT8_T);
|
||||
#endif
|
||||
|
||||
/* ns::someclass::someint */
|
||||
#if defined(SIZEOF_NS_CLASSMEMBER_INT)
|
||||
CHECK(y.someint, SIZEOF_NS_CLASSMEMBER_INT);
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
#cmakedefine HAVE_SYS_TYPES_H
|
||||
#cmakedefine HAVE_STDINT_H
|
||||
#cmakedefine HAVE_STDDEF_H
|
||||
#cmakedefine HAVE_CSTDINT
|
||||
#cmakedefine HAVE_CSTDDEF
|
||||
|
||||
/* bool */
|
||||
#cmakedefine HAVE_SIZEOF_BOOL
|
||||
@SIZEOF_BOOL_CODE@
|
||||
|
||||
/* uint8_t */
|
||||
#cmakedefine HAVE_SIZEOF_UINT8_T
|
||||
@SIZEOF_UINT8_T_CODE@
|
||||
|
||||
/* std::uint8_t */
|
||||
#cmakedefine HAVE_SIZEOF_STD_UINT8_T
|
||||
@SIZEOF_STD_UINT8_T_CODE@
|
||||
|
||||
/* struct ns::somestruct::someint */
|
||||
#cmakedefine HAVE_SIZEOF_NS_STRUCTMEMBER_INT
|
||||
@SIZEOF_NS_STRUCTMEMBER_INT_CODE@
|
||||
|
||||
Reference in New Issue
Block a user