CMake GLOB不返回任何源文件吗?

问题描述 投票:0回答:1

我正在尝试使用带有GLOB的cmake为我的c ++项目自动编写我的makefile。但是,代码和标头位于两个单独的文件夹中。

/Users/username/Coding/Major Projects/ProjectName/Backend

/Users/username/Coding/Major Projects/ProjectName/Terminal

后端具有平台无关的代码。只是一堆c和c ++源文件。并且Terminal文件夹中有一些代码,这些代码使用Backend中指定的对象对它们运行一些测试。这些文件位于单独的文件夹中的原因是后端代码是Multiplatform。因此,一个Xcode项目将其导入等等。Terminal文件夹具有测试代码,因为这是唯一尝试将其编译为linux二进制文件的代码。

任何人,我都尝试构建以下CMakeList.txt文件以生成makefile。

cmake_minimum_required(VERSION 2.8.9)
project(terminalTest)

set(MainSource "/Users/username/Coding/Major Projects/ProjectName/Backend")
set(TerminalSource "/Users/username/Coding/Major Projects/ProjectName/Terminal")

#Bring the headers, such as Student.h into the project
include_directories(${MainSource} ${TerminalSource})

#Can manually add the sources using the set command as follows:
#set(SOURCES src/mainapp.cpp src/Student.cpp)

#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "./{${MainSource},${TerminalSource}}/*.cpp")

add_executable(terminalTest ${SOURCES})

并且当我从Cmake GUI运行此程序时,其结果是成功的配置,但错误No SOURCES given to target: terminalTest表示我的file()命令无法正常工作。

我认为这可能与我的路径中有空格,但似乎也没有关系。顺便说一下,我将此文件放在Terminal文件夹中,并尝试从Terminal / Build进行构建

有什么方法可以调试,并查看GLOB命令带来了哪些资源?我真的可以像这样执行多目录GLOB吗?

c++ cmake glob
1个回答
0
投票

您的file(GLOB ...)路径格式不正确。您可以在此命令中单独列出源的路径,以获取both目录中的所有源文件。

file(GLOB SOURCES 
    ${MainSource}/*.cpp
    ${TerminalSource}/*.cpp
)
© www.soinside.com 2019 - 2024. All rights reserved.