CMake2-变量1:变量基本语法【设置变量:set(VAR1 “测试变量VAR1的值“)】

在这里插入图片描述

一、变量基本语法

# 104test_ver/CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(test_ver)
set(VAR1 "测试变量VAR1的值")
message("VAR1=" ${VAR1})
message("VAR1 in string ${VAR1}")
message("\${VAR1}=${VAR1}")


set(VAR2 "VAR1")
message("VAR2=" ${VAR2})
message("VAR2=" ${${VAR2}})

unset(VAR1)
message("\${VAR1}=${VAR1}")
(base) wyr@Beyond-PC:~/cpp_study/cmake_study/2-第2章CMake常用功能/23cmake set变量入门和示例/104test_ver$ cmake -S. -B build
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
VAR1=测试变量VAR1的值
VAR1 in string 测试变量VAR1的值
${VAR1}=测试变量VAR1的值
VAR2=VAR1
VAR2=测试变量VAR1的值
${VAR1}=
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wyr/cpp_study/cmake_study/2-第2章CMake常用功能/23cmake set变量入门和示例/104test_ver/build
(base) wyr@Beyond-PC:~/cpp_study/cmake_study/2-第2章CMake常用功能/23cmake set变量入门和示例/104test_ver$ 
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值