Change cmake in binary directory

Let's say I have a project in which I already ran CMake in the .build directory:

project/
    .build/
    .src

Currently I have to do this in order to run the build:

cd .build
make

I would like to run make from the root of my project, perhaps with

make -f ./build/Makefile

but that will not work. I get such errors

make[1]: CMakeFiles/Makefile2: No such file or directory
make[1]: *** No rule to make target `CMakeFiles/Makefile2'.  Stop.
make: *** [all] Error 2

This is because the Makefile created in CMake assumes that its working directory is the same as where it is located (.build).

Is it possible for CMake to generate a makefile so that the makefile changes the working directory to where it is?

+3
source share
2 answers

Another approach would be to create another Makefile in the directory from which you want to run make, with the contents something like:

all:
       cd ./build;  make $(MFLAGS)

"make" .

, cmake Makefile, . , make.

cmake make , CMakeLists.txt: cmakeLists.txt:

configure_file(ProjectRootMakefile.in ${CMAKE_SOURCE_DIR}/Makefile @ONLY)

( "$ {CMAKE_SOURCE_DIR}" , )

ProjectRootMakefile.in :

all:
       cd @CMAKE_BINARY_DIR@; make $(MFLAGS)

Makefile . (, "cd" , )

, , .

0

make, , cmake.

make -C your_build_directory
+7

Source: https://habr.com/ru/post/1728385/


All Articles