从bash脚本运行cmake

时间:2015-03-24 14:13:02

标签: bash cmake

我有一个使用cmake构建的项目。我正在尝试编写一个shell脚本来自动构建。但问题是,当从脚本运行时,cmake会发出以下错误

"include could not find load file:
            cmake/comp.cmake "

我试图从终端运行cmake并且工作正常。如何从shell脚本运行cmake?

编辑:cmake / comp.cmake是项目文件夹中的一个文件。这实际上是我在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

1 个答案:

答案 0 :(得分:0)

您可以尝试将包含comp.cmake的目录路径添加到CMAKE_MODULE_PATH。将此行添加到CMakeLists.txt

list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )

然后包含您的模块:

include( comp )

作为旁注:通常最好使用out-of-source builds