缓存(全局)变量

set(my_global_string "a string value"
    CACHE STRING "a description about the string variable")
set(my_global_bool TRUE
    CACHE BOOL "a description on the boolean cache entry")

如果在 CMake 处理相应的行时已经在高速缓存中定义了高速缓存的变量(例如,当重新运行 CMake 时),则不会改变它。要覆盖默认值,请将 FORCE 附加为最后一个参数:

set(my_global_overwritten_string "foo"
    CACHE STRING "this is overwritten each time CMake is run" FORCE)