使用CMake自动将文件夹中的所有文件添加到目标吗? [英] Automatically add all files in a folder to a target using CMake?

查看:103
本文介绍了使用CMake自动将文件夹中的所有文件添加到目标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将跨平台项目从Visual C ++,XCode和makefile中的单独构建管理系统切换到CMake。

I am considering switching a cross platform project from separate build management systems in Visual C++, XCode and makefiles to CMake.

我需要的一个基本功能是自动添加目录中所有文件的目标。尽管使用make可以轻松做到这一点,但是使用Visual C ++和XCode却不容易做到(如果我做错了,请纠正我)。是否可以直接在CMake中进行?

One essential feature I need is to add automatically all files in a directory to a target. While this is easy to do with make, it is not easily doable with Visual C++ and XCode (correct me if I am wrong). Is it possible to do it in directly in CMake? How?

推荐答案

有可能。例如。与 file(GLOB

cmake_minimum_required(VERSION 2.8)

file(GLOB helloworld_SRC
    "*.h"
    "*.cpp"
)

add_executable(helloworld ${helloworld_SRC})

请注意,这需要重新运行 cmake的 manual 如果添加或删除了源文件,因为生成的构建系统不知道何时要求CMake重新生成,而在每次构建时都这样做会增加构建时间。

Note that this requires manual re-running of cmake if a source file is added or removed, since the generated build system does not know when to ask CMake to regenerate, and doing it at every build would increase the build time.

这篇关于使用CMake自动将文件夹中的所有文件添加到目标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆