cmakegnu-makeramdisk

cmake build dir stored in ramdisk and symlinked to project causes make to fail


I'm trying to speed up build process using ramdisk for build directory.

I've created ramdisk:

sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk

On ramdisk I've created build dir:

mkdir -p /mnt/ramdisk/rust/hello3/build/

Then I've symlinked ramdisk build dir to project in which I want to use this directory:

cd /home/wakatana/rust/hello3
ln -s /mnt/ramdisk/rust/hello3/build/ build

After this I did classic combo for building project:

cd /home/wakatana/rust/hello3/build
cmake ..
make

But above command does not worked because relative path (cmake ..) is translated to /mnt/ramdisk/rust/hello3 and not to /home/wakatana/rust/hello3/ (I suspect that this is whole problem)

So instead of classic combo I did a little bit modified combo (when build dir is not symlinked this works):

cd /home/wakatana/rust/hello3/build
cmake /home/wakatana/rust/hello3
make

But this ends up with errors during make phase:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/wakatana/rust/hello3/build
make[2]: *** No rule to make target '../src/lib.rs', needed by 'src/x86_64-unknown-linux-gnu/debug/libtest_lib.a'.  Stop.
CMakeFiles/Makefile2:122: recipe for target 'src/CMakeFiles/test-lib_target.dir/all' failed
make[1]: *** [src/CMakeFiles/test-lib_target.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Is it possible to somehow tell to cmake/make to deal symlinks correctly?


Solution

  • Just save yourself the trouble of creating symlinks and work on the ram disc:

    cmake -S /home/wakatana/rust/hello3 -B /mnt/ramdisk/rust/hello3/build/
    cmake --build /mnt/ramdisk/rust/hello3/build/
    

    You could create the symlink, and then work from parent dir:

    ln -s /mnt/ramdisk/rust/hello3/build/
    cd /home/wakatana/rust/hello3 
    cmake -S .  -B build
    cmake --build build
    # or expand the symlink before cmake has to:
    cmake -S .  -B "$(readlink -f "./build")"
    cmake --build "$(readlink -f "./build")"