简体   繁体   English

cmake源和源外导航

[英]cmake source and out-of-source navigation

cmake advises to use out-of-source builds. cmake建议使用out-of-source构建。 While in general I like the idea I find it not comfortable to navigate from out-of-source sub directory to the corresponding source directory. 虽然总的来说我喜欢这个想法,但我觉得从源外子目录导航到相应的源目录是不舒服的。 I frequently need the code to perform some actions with code (eg grep, svn command etc.). 我经常需要代码来执行一些代码操作(例如grep,svn命令等)。

Is there an easy way in shell to navigate from out-of-source sub directory to the corresponding source directory? shell中有一种简单的方法可以从源外子目录导航到相应的源目录吗?

Thanks Dima 谢谢迪马

I prefer to keep it simple and have the source checkouts in a src/ directory, and the corresponding builds in a build/ directory. 我更喜欢保持简单,并在src/目录中有源检出,以及build/目录中的相应构建。 Then I can use 然后我就可以用了

function cs() {
    cd "${PWD/build/src}"
}
function cb() {
    cd "${PWD/src/build}"
}

Cf. 参看 also KDE's TechBase for another approach. 还有KDE的TechBase用于另一种方法。

I think that the most straightforward and convenient way to do this is simply open more than one Shell session, ie tabs. 我认为最简单方便的方法是打开多个Shell会话,即选项卡。 For example, KDE4 Konsole supports tabs and you can navigate through them with Shift + ArrowLeft or ArrowRight. 例如,KDE4 Konsole支持选项卡,您可以使用Shift + ArrowLeft或ArrowRight浏览它们。 IMHO very comfortable plus it preserves history better. 恕我直言非常舒适加上它保存历史更好。

Have you tried the pushd and popd builtins ? 你有没有试过pushdpopd内置的

When in the /source/directory /source/directory

pushd /to/build/directory

Work there 在那里工作

popd ## Back to source directory popd ##返回源目录

You can even stack that deeper... 你甚至可以把它stack更深......

Ok this is what what I found. 好的,这就是我发现的。 The idea is to use CMakeCache.txt which is found in out-of-source tree. 我们的想法是使用在源外树中找到的CMakeCache.txt。 We go up while looking for cache file. 我们在寻找缓存文件时上去。 Once found we extract source directory, which is stored in CMAKE_HOME_DIRECTORY varible. 一旦找到,我们提取源目录,该目录存储在CMAKE_HOME_DIRECTORY varible中。

function cdoos2src () {
    path=$(pwd)

    while [[ $path != "/" ]]; do
        if [[ -f $path/CMakeCache.txt ]]; then
            break;
        fi

        # go up one directory
        path=$(dirname $path)
    done

    if [[ $path == "/" ]]; then
        echo "This is not svn out-of-source directory - CmakeCache.txt not found"
        return
    fi

    oos_dir=$(pwd) 

    code_dir=$(sed -n '/CMAKE_HOME_DIRECTORY/s/.*=//p' $path/CMakeCache.txt)
    echo "Code dir     [$code_dir]"

    code_sub_dir=$(echo $(pwd) | sed  -n 's#^'$path'##p')
    echo "Code sub dir [$code_sub_dir]"

    cd $code_dir/$code_sub_dir
}

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

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