Specifying build directory within CMakeLists file

后端 未结 2 774
旧巷少年郎
旧巷少年郎 2020-12-30 14:39

Is it possible to specify build directory within CMakeLists file? If yes, how.

My aim is to be able to call \"cmake\" within top level source directory and have cmak

相关标签:
2条回答
  • 2020-12-30 15:06

    By design, there is not a way to specify that in CMakeLists.txt. It is designed for the user to be able to build the project in whatever directory they want. The typical workflow is:

    1. Check out the project source code.
    2. Go to desired build directory, or the source dir if you plan to do an in-source build.
    3. Run cmake or ccmake to configure the project in that build directory.
    4. Build your project.

    All of the directories specified within your CMakeLists.txt should be relative to the ${PROJECT_BINARY_DIR} and ${PROJECT_SOURCE_DIR} variables. In this way, your code becomes buildable across different platforms, which is the goal of CMake.

    0 讨论(0)
  • 2020-12-30 15:17

    Afaik, with CMake the build directory is always the directory from where you invoke the cmake or ccmake command. So if you want to change the build directory, you have to change directories before running CMake.

    To control the location where executables, static and shared libraries are placed once finished, you can modifiy CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_ARCHIVE_OUTPUT_DIRECTORY, and CMAKE_LIBRARY_OUTPUT_DIRECTORY respectively.

    0 讨论(0)
提交回复
热议问题