cmake to place the intermediate files to a certain directory

流过昼夜 提交于 2019-12-10 21:19:27

问题


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.

  1. make out-of-source builds see here, so that all your build stuff is in an own folder
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!