CMake source and external navigation system

cmake advises using assemblies outside the source. Although I generally like the idea, I am not comfortable navigating from a subdirectory from the source source to the corresponding source directory. I often need code to perform some actions with the code (for example, grep, svn, etc.).

Is there an easy way in the shell to move from a subdirectory outside the source to the corresponding source directory?

Thanks Dima

+4
source share
4 answers

I prefer to keep it simple and have the original checks in the src/ directory and the corresponding assemblies in the build/ directory. Then i can use

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

Cf. also KDE TechBase for a different approach.

+3
source

I think the easiest and most convenient way to do this is to simply open more than one Shell session, i.e. tabs. For example, KDE4 Konsole supports tabs, and you can navigate through them using Shift + ArrowLeft or ArrowRight. IMHO is very convenient, plus it better saves history.

+1
source

Have you tried pushd and popd built-in functions ?

When in /source/directory

pushd /to/build/directory

Work there

popd ## Return to source directory

You can even stack deeper ...

0
source

Ok, that’s what I found. The idea is to use CMakeCache.txt, which is in the source tree. We go up, looking for a cache file. After detection, we retrieve the source directory, which is stored in 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 } 
0
source

All Articles