CMake

CMake

Created
Jul 6, 2021 04:09 AM
Tags
CMake
Published
Jul 6, 2021
Description
CMake遇到的问题

-D <var>:<type>=<value>

在弄一个软件的CMake,根据它的Makefile里面提到的cmake configure的方式添加CMake的参数,是可以用的,但是使用vscode的cmake tools添加configureSettings,是会报错
make[5]: *** No rule to make target '/home/elsa/Code/hermitux-kernel/build/local_prefix/home/elsa/Code/hermitux-kernel/build/tests-prefix/src/prefix/x86_64-hermit/lib/libhermit.a', needed by 'hermitux'.  Stop.
看起来就是把两个路径直接拼在了一起,把cmake tools生成的cmake指令拿出来,对比,对比到最后才发现是-D的时候cmake tools指定了type
cmake -DCMAKE_INSTALL_PREFIX:STRING=../prefix ..
这里的相对路径就炸了,如果换成绝对路径就是好的
根据 CMake 文档 ,应该是用 PATH 类型
因此用configureArgs
虽然文档上说的是不应该用,但是根据issue里面的,也不是不能用
There's actually no technical reason prohibiting you from passing -D with configureArgs. I believe that warning was written by vector-of-bool when he started this project and we haven't spent much time in the area yet. Based on what I see in the code I think it was to avoid conflicts between some of the "special" settings you mentioned. These conflicts are resolved if you use configureSettings, but not when you use configureArgs. I suspect it is easier to advise not to use configureArgs for -D arguments than to explain all of the potential conflicts. I think a more correct warning would be not to use configureArgs to set the following properties: CMAKE_EXPORT_COMPILE_COMMANDS CMAKE_BUILD_TYPE CMAKE_INSTALL_PREFIX CMAKE_[LANGUAGE]_COMPILER CMAKE_TOOLCHAIN_FILE BUILD_SHARED_LIBS

CMAKE_INSTALL_PREFIX

使用的是"-DCMAKE_INSTALL_PREFIX=../prefix"的时候,一直会安装到 /mnt/c/Users/Elsa/AppData/Local/Programs 里面去,在WSL里面
跑到了windows的目录里面去
notion image
CMake tools 生成的命令是
/usr/bin/cmake --no-warn-unused-cli -DCMAKE_INSTALL_PREFIX=../prefix -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H/home/elsa/Code/hermitux-kernel -B/home/elsa/Code/hermitux-kernel/build -G "Unix Makefiles"
但是文档里面的命令是,这个是正常安装
cmake -DCMAKE_INSTALL_PREFIX=../prefix ..
 
从这两糅合了一下
cmake -DCMAKE_INSTALL_PREFIX=../prefix .. -H/home/elsa/Code/hermitux-kernel -B/home/elsa/Code/hermitux-kernel/build