我正在尝试编写一个基本的cmake来检查某些类型是否存在。 我遇到多次调用check_type_size的问题。如果我多次使用相同的变量(保持大小的变量),只有第一次调用check_type_size时才会填充它。
cmake_minimum_required(VERSION 3.8)
project(TEST LANGUAGES C;CXX)
INCLUDE (CheckTypeSize)
check_type_size("int" VAR_SIZE1)
message(${VAR_SIZE1})
check_type_size("void *" VAR_SIZE1)
message(${VAR_SIZE1})
message("VAR_SIZE1 was not updated after the second call.\n")
check_type_size("int" VAR_SIZE2)
message(${VAR_SIZE2})
check_type_size("void *" VAR_SIZE3)
message(${VAR_SIZE3})
message("We get the correct size if use different variable every time.")
add_executable(TEST "${TEST_SOURCE_DIR}/main.cpp")
这就是我得到的: 检查int的大小 检查int的大小 - 完成 4 4 第二次调用后,VAR_SIZE1未更新。
Check size of int
Check size of int - done
4
Check size of void *
Check size of void * - done
8
We get the correct size if use different variable every time.
有没有人知道发生了什么事?
答案 0 :(得分:1)
使用check_type_size()
调用创建的变量实际上是 CACHE 变量(这在宏的documentation中有所描述。一旦设置了变量,它就不会更新。[这用于在您下次运行cmake
时省略成功检查。]
不同的检查应使用不同的变量。