我想从目录中找到所有c文档,并将所有文件添加到SRC档案中,以便汇编成 cm。 我如何能够在CMakeList.txt这样做。
普通造册
SPECIFIED_SRC_FILE = $(foreach d,$(SPECIFIED_SRC_DIRS),$(wildcard $(addprefix $(d)/*,*.c)))
但是,我无法在CMakeList.txt中找到这样的东西。
我想从目录中找到所有c文档,并将所有文件添加到SRC档案中,以便汇编成 cm。 我如何能够在CMakeList.txt这样做。
普通造册
SPECIFIED_SRC_FILE = $(foreach d,$(SPECIFIED_SRC_DIRS),$(wildcard $(addprefix $(d)/*,*.c)))
但是,我无法在CMakeList.txt中找到这样的东西。
为此:
将所有来源档案列入目录。
AUX_SOURCE_DIRECTORY(dir VARIABLE)
Collects the names of all the source files in the specified directory and stores the list in the variable provided. This command is intended to be used by projects that use explicit template instantiation. Template instantiation files can be stored in a "Templates" subdirectory and collected automatically using this command to avoid manually listing all instantiations.
It is tempting to use this command to avoid writing the list of source files for a library or executable target. While this seems to work, there is no way for CMake to generate a build system that knows when a new source file has been added. Normally the generated build system knows when it needs to rerun CMake because the CMakeLists.txt file is modified to add a new source. When the source is just added to the directory without modifying this file, one would have to manually rerun CMake to generate a build system incorporating the new file.
如何对待好老的游说?
FILE(GLOB MyCSources *.c)
ADD_EXECUTABLE(MyExecutable ${MyCSources})
<><> 代码>GLOB_RECURSE recursive example
基本上,<代码>*也属于次方向:
cmake_minimum_required(VERSION 3.0)
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.c")
add_executable(main ${SOURCES})
And then our sources could be located for example as:
src/main.c
src/d/a.c
src/d/a.h
使用<代码>GLOB_RECURSE在CMake顶级(即*.c>
而不是src/*.c”
,可能是一种坏的想法,因为它可以检索.c
,由CMake本身生成的载于build/
的文档。
可操作的例子on Git。
<><>只有>> 正确的答案是,而不是>。 详情见 多边。 页: 1 我将在此总结一下,以减少重要性。
aux_source_directory
function is outright incorrect since it cannot detect changes in the filesystem. For the same reason, using file(GLOB
or file(GLOB_RECURSE
without CONFIGURE_DEPENDS
is outright incorrect.CONFIGURE_DEPENDS
is not guaranteed to work. (See point 1)
只是简单地列出你自己的来源。
<>1> 这里,CMake的开发商必须说:
<>说明: 我们不建议利用GLOB收集来源树的原始档案清单。 如果没有CMakeList。 当一个来源被添加或移除时,所产生的建筑系统无法知道何时要求CMake进行再生。 <>CONFIGURE_DEPENDS 旗帜不能对所有发电机进行可靠的工作,或者如果将来添加无法支持的新发电机,则使用这种装置的项目将受到阻碍。 即便是<> CONFIGURE_DEPENDS 可靠地开展工作,每次重建都会有费用进行检查。
是的,你有两个选择。 让我假定,这种双重结构类似。
├── autopilot
│ ├── _AutoPilot.cpp
│ ├── _AutoPilot.h
│ └── action
│ ├── ActionBase.cpp
│ ├── ActionBase.h
│ ├── APcopter
│ │ ├── APcopter_avoid.cpp
│ │ ├── APcopter_avoid.h
如果要使用<代码>AUX_SOURCE_DIRECTORY,你必须增加CMakeLists。 每一分局。 然后,你们必须把所有这些分局包括在内并连接起来。 这是一项艰巨的任务。 因此,你可以轻松地做工作。 这就是如何做到这一点。
file(GLOB autopilot_sources ./**.cpp ./**.c)
SET( autopilot ${autopilot_sources})
如果你想使用上述来源代码建立一个图书馆,则指挥是:
ADD_LIBRARY ( autopilot ${autopilot_sources})
TARGET_LINK_LIBRARIES ( autopilot)
如果你想使用上述来源法建立一个可起诉的档案,则指挥是:
ADD_EXECUTABLE(autopilot ${autopilot_sources})
你可以使用
Is there a way to have make display the line number where it declares an error? The -d switch doesn t seem to cut it. Updated: Example output: Reaping winning child 0x08aa8648 PID 9381 /bin/sh: ...
I m revisiting Python after Michael Sparks s excellent walk through of Peter Norvig s Python spell checker at the SO DevDay in London. One of the points he highlighted was how clean Python is to look ...
Is there a command line way in make to find out which of the prerequisites of a target is not updated?
I m working on a cross-platform 2D engine for mobile devices (Windows Mobile 6 and Android). My Windows version is pretty much ready, but I still need to make sure the same functionality is available ...
I want to just type make all and have the following Makefile do everything it s supposed to do: LEX = lex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl ...
在我执政时,我发现以下错误:
How can you tell, from the command line, how many cores are on the machine when you re running Mac OS X? On Linux, I use: x=$(awk /^processor/ {++n} END {print n+1} /proc/cpuinfo) It s not ...
I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive(); extern int timer_x; #endif /*TUNABLES_H */ and ...