diff options
author | Aiden Woodruff <aiden.woodruff@gmail.com> | 2020-07-13 01:36:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-07-20 19:47:18 (GMT) |
commit | 371072e9e1677e883d3feed167b53e075fb129b3 (patch) | |
tree | 0ec74296c44bea6120145bf613f0494e5f3cda6d | |
parent | 32c000823ebe0cab99f20f4a053f2c377af99de7 (diff) | |
download | CMake-371072e9e1677e883d3feed167b53e075fb129b3.zip CMake-371072e9e1677e883d3feed167b53e075fb129b3.tar.gz CMake-371072e9e1677e883d3feed167b53e075fb129b3.tar.bz2 |
CheckTypeSize: Use C++-style headers to check for std:: types
In order to check for types like `std::uint8_t` in C++, we need to
include `<cstdint>` instead of `<stdint.h>`.
-rw-r--r-- | Modules/CheckTypeSize.cmake | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake index 2b07b7c..17beadc 100644 --- a/Modules/CheckTypeSize.cmake +++ b/Modules/CheckTypeSize.cmake @@ -89,17 +89,38 @@ function(__check_type_size_impl type var map builtin language) message(CHECK_START "Check size of ${type}") endif() + # Perform language check + if(language STREQUAL "C") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) + elseif(language STREQUAL "CXX") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp) + else() + message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n") + 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") + 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}) @@ -107,14 +128,6 @@ function(__check_type_size_impl type var map builtin language) endforeach() # Perform the check. - - if(language STREQUAL "C") - set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) - elseif(language STREQUAL "CXX") - set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp) - else() - message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n") - endif() 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) |