Sword Destiny
Sword Destiny

Reputation: 31

BUILD.gn: how to add all .c files in one directory into sources

how to add all .c files in one directory into sources.

this is not correct:

sources = [ "./fuzz_ioctl.c", "./Secodefuzz/mutators/*.c", "./Secodefuzz/common/*.c" ]

There is so many files in Secodefuzz/mutators and Secodefuzz/common. I don't want to write all the file-name.

Upvotes: 1

Views: 335

Answers (1)

Charles Nicholson
Charles Nicholson

Reputation: 1154

GN does not natively support globs, and requires all source lists to be explicit.

It's not considered good GN style, but (for completeness) there is always exec_script. You can use exec_script to run a script at configuration time, investigate the filesystem, and return a list back to GN:

path/to/libfoo/BUILD.gn:

static_library("libfoo") {
  sources = exec_script("get_c_files.py", [], "list lines", [])
}

path/to/libfoo/get_c_files.py:

import pathlib
print("\n".join(str(f) for f in pathlib.Path().glob("*.c")))

Note that exec_script will run every time you invoke GN (including sub-tools like desc and ls), and can be a source of performance issues. Also, you can use the --time command-line option to profile your project.

Upvotes: 0

Related Questions