cmake调用shell的笔记

想用cmake调用shell引入一些环境变量,或者编译链。

查到了几种方法:

execute_process

https://cmake.org/cmake/help/v3.0/command/execute_process.html

exec_program

https://cmake.org/cmake/help/v3.0/command/exec_program.html#command:exec_program

add_custom_target

https://cmake.org/cmake/help/v3.0/command/add_custom_target.html

add_custom_command

https://cmake.org/cmake/help/v3.0/command/add_custom_command.html

但是无论如何,都在child process里面执行shell,No intermediate shell is used,没办法放弃了。

除非把所有shell用cmake写一遍,但是一旦shell更新,cmake也要更新,这就是给自己找麻烦了。

解决办法是外部留一个build.sh 在里面选平台也好,加选项也好,再用这个shell脚本调用cmake。

当然,python和bat也ok。

=================更新==============

还有种苟且的方法,使用file命令读编译链的文本。

file(STRINGS env.sh my_env_file)

然后用正则表达式手转一遍

if( $ENV{啥啥FLAGS} MATCHES ”啥啥“ )

set( 整一下 )

endif()

还有环境变量

set( CMAKE_CXX_FLAGS $ENV{CXXFLAGS} CACHE STRING "" FORCE )

其他参考:

https://blog.csdn.net/ztszph/article/details/80997953

https://blog.csdn.net/lv_xinmy/article/details/19567319

https://www.cnblogs.com/coderfenghc/default.html?page=3

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值