从bash脚本运行cmake [英] Running cmake from bash script
问题描述
我有一个使用cmake构建的项目。我正在尝试编写一个shell脚本来自动化构建。但问题是,从脚本运行时,cmake给出以下错误
I have a project which is build using cmake. I am trying to write a shell script for automating the build. But the trouble is, when run from the script the cmake is giving the following error
"include could not find load file:
cmake/comp.cmake "
我试图从终端运行cmake及其工作精细。我怎么能从shell脚本运行cmake?
I tried to run the cmake from the terminal and its working fine. How can i get to run cmake from the shell script??
编辑:cmake / comp.cmake是项目文件夹中的文件。这实际上是我正在cmakelists.txt中加载的模块。
cmake/comp.cmake is a file inside the project folder. which is actually an module i am loading in the cmakelists.txt
编辑:脚本
#!/bin/bash
num=$(grep -c "PATH=$PATH:/opt/robocomp/bin" ~/.bashrc)
if [ $num -eq 0 ]; then
echo "export PATH=$PATH:/opt/robocomp/bin" >> ~/.bashrc;
echo "added /opt/robocomp/bin to PATH ";
fi
source ~/.bashrc
cd ~/robocomp
cmake .
make
sudo make install
if [ $? -eq 0 ]; then
echo "/opt/robocomp/lib/" >> /etc/ld.so.conf
sudo ldconfig
fi
推荐答案
您可以尝试将包含 comp.cmake
的目录路径添加到 CMAKE_MODULE_PATH
。将此行添加到您的 CMakeLists.txt
:
You could try to add the path of directory which contains comp.cmake
to CMAKE_MODULE_PATH
. Add this line to your CMakeLists.txt
:
list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
,然后包含您的模块:
include( comp )
请注意:通常最好使用源代码以外的版本。
As side note: it is usually better use out-of-source builds.
这篇关于从bash脚本运行cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!