我有一个大致具有以下结构的CMake项目:
bootstrap | bootout domain-target [service-path service-path2 ...] | service-target
Bootstraps or removes domains and services. When service arguments are present, bootstraps and correspondingly removes their definitions into the domain. Services may be specified as a series of
paths or a service identifier. Paths may point to XPC service bundles, launchd.plist(5) s, or a directories containing a collection of either. If there were one or more errors while bootstrapping or
removing a collection of services, the problematic paths will be printed with the errors that occurred.
If no paths or service target are specified, these commands can either bootstrap or remove a domain specified as a domain target. Some domains will implicitly bootstrap pre-defined paths as part of
their creation.
在.
|-- library1
| |-- CMakeLists.txt
|-- library2
| |-- CMakeLists.txt
|-- executables
| |-- CMakeLists.txt
中的我生成了2个可执行文件。我想知道是否有可能仅生成一个可执行文件及其依赖项而不是全部。我听说过有关cmake executables
选项的信息,但无法使其与--target
一起使用。
答案 0 :(得分:3)
这里有两个潜在的问题。首先,典型的CMake工作流程将build
文件夹放置为顶级CMake文件的同级文件。因此,您的文件层次结构应如下所示:
.
|-- CMakeLists.txt
|-- library1
| |-- CMakeLists.txt
|-- library2
| |-- CMakeLists.txt
|-- executables
| |-- CMakeLists.txt
|-- build <------------ Run CMake commands from here.
这会将所有CMake生成的文件隔离到build
文件夹中。其次,您必须小心在适当的位置运行CMake构建阶段。我们可以从build
文件夹中运行所有内容,例如:
要生成构建系统,请从cmake ..
目录运行build
。第一步应指向顶级CMake文件。
要构建(或编译)一个特定的目标,例如称为MyExecutable1
,请运行以下命令:
cmake --build . --target MyExecutable1
来自build
目录。您必须确保将--build
标志指向build
文件夹,这次不是不是顶级CMake文件。另外,此命令中要指定的目标名称应与add_executable()
中使用的目标名称匹配,不项目名称或其他任何名称。
与往常一样,当尝试运行CMake时遇到错误/问题时,它有助于清除缓存(删除build/CMakeCache.txt
),或仅删除build
文件夹并重新启动。