问题
I am pretty new to cmake and wonder how I can do this is cmake. I want to place all the intermediate files (like the .o files) to be placed in a certain directory (say "build") and then once the build is done I want copy certain files I need (e.g., the .exe, .dll like the end product) from build directory to "stage" directory. how can I specify the path to these two directories (build and stage)? Cmake will also check if the build/stage directory exists or not. If does not exist, it will create the directories for me.
Any help will be appreciated.
回答1:
What are you asking is the most often CMake use case.
To make whole build process to occur in arbitary dir, you should run cmake /path/to/your/project
from that dir (or use cmake-gui).
Your source dir would be untouched until you explicitly tell CMake to output some files there.
As for point 2:
You should place install()
invocations into your CMakeLists.txt (see documentation on install()
) and set CMAKE_INSTALL_PREFIX to the dir where you wish files to be copied. After that you can run make install
or cmake -P cmake_install.cmake
from your build dir to install these files.
回答2:
I would suggest another approach.
- make out-of-source builds see here, so that all your build stuff is in an own folder
- copy your executables from your build directory in an own folder with explicit copying see here
Or instead of choosing step 2 you also can provide an install routine where the needed executables are installed in a give path. see here
来源:https://stackoverflow.com/questions/9218638/cmake-to-place-the-intermediate-files-to-a-certain-directory