我的源代码目录结构如下:
.
├── build
├── CMakeLists.txt
├── libs
│ ├── CMakeLists.txt
│ ├── ext
│ │ └── include
│ │ └── json.hpp
│ └── int
│ ├── CMakeLists.txt
│ └── net
│ ├── CMakeFiles
│ │ ├── CMakeDirectoryInformation.cmake
│ │ └── progress.marks
│ ├── cmake_install.cmake
│ ├── CMakeLists.txt
│ ├── include
│ │ ├── connection.hpp
│ │ └── conn_manager.hpp
│ ├── Makefile
│ └── src
│ ├── CMakeFiles
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── libs.dir
│ │ │ ├── build.make
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── cmake_clean_target.cmake
│ │ │ ├── DependInfo.cmake
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── link.txt
│ │ │ └── progress.make
│ │ └── progress.marks
│ ├── cmake_install.cmake
│ ├── CMakeLists.txt
│ ├── connection.cpp
│ ├── conn_manager.cpp
│ └── Makefile
└── main
├── CMakeLists.txt
├── config
│ └── config.json
└── srcs
├── CMakeLists.txt
├── main.cpp
├── samvaadak.cpp
└── samvaadak.hpp
"建立"是我运行cmake的文件夹。它运行并在build / dist / bin中创建最终输出可执行文件。但它也会在源代码树(libs和main)中创建大量中间内容并使其变得杂乱无章。
顶级CMakeLists.txt文件如下所示。
project (samvaadak)
subdirs(main libs)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/bin)
中级CMakeLists.txt文件包含以下内容:
subdirs(src)
并且,源文件所在的内部文件夹的CMakeLists.txt文件是这样的:
include_directories(${samvaadak_SOURCE_DIR}/libs/int/net/include)
include_directories(${samvaadak_SOURCE_DIR}/libs/ext/include)
add_library(nettu conn_manager.cpp connection.cpp)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/bin)
如何告诉cmake在 libs 和主要文件夹之外构建并在构建内部构建所有内容?
答案 0 :(得分:0)
您可以在源代码构建中禁用:
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
还建议:
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
需要在第一个project()
命令之前使用它们。