SCons在多个目录中查找文件

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

所以我是scons的新手,我在弄清楚如何查看多个目录时遇到了一些麻烦?

这是我目前的方法,适用于单个文件夹:

files = File([
    'testfile.c',
    'testfile_const.c',
    'folder/testfile2.c',
    'folder/testfile2_const.c'

])


dir = Dir('.')
env.Append(CPPPATH = dir)
env.Prepend(CPPPATH = dir.srcnode())
Return('files')

问题是,现在我把testfile2放在自己的文件夹中,我的scons脚本抱怨道。我怎样才能在另一个目录中查找文件?

scons
1个回答
0
投票

如果您希望所有目录都是CPPPATH的一部分,则需要显式添加它们。通过使用for循环可以非常简单地使用当前方法完成此操作:

import os

# Use all C/C++ files in this folder
files = File([
    'testfile.c',
    'testfile_const.c',
    'folder/testfile2.c',
    'folder/testfile2_const.c'

])

# Add folder to search path
for file in files:
    dirpath = os.path.dirname(file.path)
    if not dirpath in env['CPPPATH']:
        env.Append(CPPPATH = [dirpath])

Return('files')
© www.soinside.com 2019 - 2024. All rights reserved.