C++ CMake在配置步骤检查数据类型大小的目的是什么?

C++ CMake在配置步骤检查数据类型大小的目的是什么?,c++,c,cmake,build,configure,C++,C,Cmake,Build,Configure,我正在尝试使用创建项目 对于配置和生成构建文件,我使用这个命令 cmake -G "Visual Studio 16 2019" -A x64 -S . -B build64 -DDepsPath=C:\Users\alokm\Downloads\dependencies2019\win64 -DQTDIR=C:\Qt\5.15.2\msvc2019_64 -DVIRTUALCAM_GUID=e61ba6f1-ac3a-47b6-aaee-b537088061e4 -DCMA

我正在尝试使用创建项目

对于配置和生成构建文件,我使用这个命令

cmake -G "Visual Studio 16 2019" -A x64 -S . -B build64 -DDepsPath=C:\Users\alokm\Downloads\dependencies2019\win64 -DQTDIR=C:\Qt\5.15.2\msvc2019_64 -DVIRTUALCAM_GUID=e61ba6f1-ac3a-47b6-aaee-b537088061e4 -DCMAKE_CONFIGURATION_TYPES=Release
我正在检查的那些相关日志行是

C compiler: MSVC

-- Check size of __int64
-- Check size of __int64 - done
-- Check size of int64_t
-- Check size of int64_t - done
-- Check size of long long
-- Check size of long long - done
-- Check size of int32_t
-- Check size of int32_t - done
-- Check size of __int32
-- Check size of __int32 - done
-- Check size of long
-- Check size of long - done
-- Check size of int
-- Check size of int - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Check size of unsigned int
-- Check size of unsigned int - done
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Check size of uint32_t
-- Check size of uint32_t - done
-- Check size of __uint32
-- Check size of __uint32 - failed
-- Check size of uint16_t
-- Check size of uint16_t - done
-- Check size of __uint16
-- Check size of __uint16 - failed
-- Check size of uint8_t
-- Check size of uint8_t - done
-- Check size of __uint8
-- Check size of __uint8 - failed
-- Check size of ssize_t
-- Check size of ssize_t - failed
-- Check size of SSIZE_T
-- Check size of SSIZE_T - failed

在这个配置步骤中,这些日志行是关于检查数据类型大小的?这几行是什么意思?检查数据类型大小的目的是什么?

原因是代码的可移植性。并非所有编译器都需要支持像
int32\t
这样的标准类型,而且只支持C99(和C++11)

我们可以看到捆绑的
jansson
库需要特定的宽度整数类型来进行JSON解析。因此,例如,对于32位整数,它会检查一些可能性-
int32\u t
\uu int32
long
int

# Check our 32 bit integer sizes
check_type_size (int32_t INT32_T)
check_type_size (__int32 __INT32)
check_type_size ("long" LONG_INT)
check_type_size ("int" INT)
if (HAVE_INT32_T)
   set (JSON_INT32 int32_t)
elseif (HAVE___INT32)
   set (JSON_INT32 __int32)
elseif (HAVE_LONG_INT AND (${LONG_INT} EQUAL 4))
   set (JSON_INT32 long)
elseif (HAVE_INT AND (${INT} EQUAL 4))
   set (JSON_INT32 int)
else ()
   message (FATAL_ERROR "Could not detect a valid 32-bit integer type")
endif ()

可以说,如果一次执行一次检查,直到找到所需的类型,配置过程会更快(在大多数情况下,第一选择就足够了)。

原因是代码可移植性。并非所有编译器都需要支持像
int32\t
这样的标准类型,而且只支持C99(和C++11)

我们可以看到捆绑的
jansson
库需要特定的宽度整数类型来进行JSON解析。因此,例如,对于32位整数,它会检查一些可能性-
int32\u t
\uu int32
long
int

# Check our 32 bit integer sizes
check_type_size (int32_t INT32_T)
check_type_size (__int32 __INT32)
check_type_size ("long" LONG_INT)
check_type_size ("int" INT)
if (HAVE_INT32_T)
   set (JSON_INT32 int32_t)
elseif (HAVE___INT32)
   set (JSON_INT32 __int32)
elseif (HAVE_LONG_INT AND (${LONG_INT} EQUAL 4))
   set (JSON_INT32 long)
elseif (HAVE_INT AND (${INT} EQUAL 4))
   set (JSON_INT32 int)
else ()
   message (FATAL_ERROR "Could not detect a valid 32-bit integer type")
endif ()
可以说,如果一次执行一次检查,直到找到所需的类型,配置过程会更快(在大多数情况下,第一选择就足够了)。

另请参见