Use of add_files in xmake

2015/12/06 22:03
Reading number 727

If you read Introduction to project description Do you think it is convenient to add source files through add_files?

At present, it can support. c/. cpp/. s/ The source code and library files with suffix S/. m/. mm/. o/. obj/. a/. lib, where the wildcard * matches the files in the current directory, and * * matches the files in multi-level directories.

For example:

 add_files("src/test_*.c") add_files("src/xxx/**.cpp") add_files("src/asm/*.S", "src/objc/**/hello.m")

The use of add_files is actually quite flexible and convenient. I borrowed the style of premake for its matching pattern, but improved and enhanced it.

This allows you to not only match files, but also filter and exclude a batch of files in the specified mode while adding files..

For example:

 --Recursively add all c files under src, but not all c files under src/impl/ add_files("src/**.c|impl/*.c") --Add all cpp files under src, but not src/test.cpp, src/hello.cpp, and all cpp files with xx_ prefix under src add_files("src/*.cpp|test.cpp|hello.cpp|xx_*.cpp")

The files that need to be excluded follow the | separator. These files also support matching patterns, and multiple filtering patterns can be added at the same time, as long as | is used in the middle..

Note: In order to simplify the description, the filter description after | is based on a mode: the directory before * in src/*. cpp.

Therefore, the files filtered in the above example are all files under src, which should be noted..

Let's take a look TBOX Example of add_files in xmake.lua:

 add_files("*.c")  add_files("asio/aioo.c")  add_files("asio/aiop.c")  add_files("math/**.c")  --Here libc/string/impl/* *. c is filtered add_files("libc/**.c|string/impl/**.c")  add_files("utils/*.c|option.c")  add_files("prefix/**.c")  add_files("memory/**.c")  add_files("string/**.c")  --Here stream/* */charset. c is filtered, stream/**/zip.c,stream/**async_**.c,stream/transfer_pool.c add_files("stream/**.c|**/charset.c|**/zip.c|**async_**.c|transfer_pool.c")  --All c files under network/impl/ssl are filtered here add_files("network/**.c|impl/ssl/*.c")  add_files("algorithm/**.c")  add_files("container/**.c")  add_files("libm/libm.c")  add_files("libm/idivi8.c")  add_files("libm/ilog2i.c")  add_files("libm/isqrti.c")  add_files("libm/isqrti64.c")  add_files("libm/idivi8.c")  add_files("platform/*.c|aicp.c") --If the current architecture is arm, add the asm optimization code related to arm if archs("arm.*") then add_files("utils/impl/crc_arm.S") end --If the charset module is currently enabled, add the corresponding c file (the files here are filtered out) --The options interface will be explained in detail later if options("charset") then  add_files("charset/**.c") add_files("stream/impl/filter/charset.c") end

One of the advantages of filtering some files when adding files is that it can provide a basis for adding files according to different switch logic.

In particular, xmake also supports adding object files and library files of. o/obj/. a/. lib directly to the target

This is different from add_links. Links are the code in the link library, while this is to directly merge the object files in the static library into the target program..

See Consolidated static library of advanced features


Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top