简体   繁体   English

从bash脚本运行cmake

[英]Running cmake from bash script

I have a project which is build using cmake. 我有一个使用cmake构建的项目。 I am trying to write a shell script for automating the build. 我正在尝试编写一个shell脚本来自动化构建。 But the trouble is, when run from the script the cmake is giving the following error 但是问题是,从脚本运行时,cmake给出以下错误

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

I tried to run the cmake from the terminal and its working fine. 我试图从终端运行cmake,并且它运行正常。 How can i get to run cmake from the shell script?? 我如何从shell脚本运行cmake?

EDIT: cmake/comp.cmake is a file inside the project folder. 编辑:cmake / comp.cmake是项目文件夹中的文件。 which is actually an module i am loading in the cmakelists.txt 这实际上是我正在cmakelists.txt中加载的模块

EDIT: the script 编辑:脚本

#!/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

You could try to add the path of directory which contains comp.cmake to CMAKE_MODULE_PATH . 您可以尝试将包含comp.cmake的目录路径添加到CMAKE_MODULE_PATH Add this line to your CMakeLists.txt : 将此行添加到您的CMakeLists.txt

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

and then include your module: 然后包含您的模块:

include( comp )

As side note: it is usually better use out-of-source builds . 作为旁注:通常最好使用外包源构建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM