2

I have a C++ project with its source files (.cpp and .h files) in a directory called src and its subdirectories. I want, once my project is compiled, to copy all the header files from this source folder into another directory, maintaining the folderstructure of src.

I have tried to copy these files with post-build commands:

postbuildcommands
{
    "{COPY} src/*.h include"
}

and

postbuildcommands
{
    "{COPY} src/**.h include"
}

But these only copy the .h files directly in src and not those in subdirectories. For example, this

src
+-- a.h
+-- a.cpp
+-- sub
|   +-- b.h
|   +-- b.cpp

becomes

include
+-- a.h

instead of

include
+-- a.h
+-- sub
|   +-- b.h
dranjohn
  • 673
  • 7
  • 22
  • {COPY} expands to `cp -rf` (Unix) or `xcopy /E ...` (Windows) which support folder copy, but not ** matching. If you had all your headers in a separate folder, it would be trivial, but when put together with cpp, you'll need a more complex command to extract them. I don't have a cross-platform solution so this is a comment, not an answer, but you can start with this on Linux: https://stackoverflow.com/questions/10176849/how-can-i-copy-only-header-files-in-an-entire-nested-directory-to-another-direct If you find the equivalent for Windows, add both commands in os filters and it should work. – hsandt Jul 27 '20 at 15:14

1 Answers1

0

Are you using windows linux or mac? Or does it need to be cross platform?

It looks like the {copy} token doesn't pass the /s flag to xcopy on windows https://github.com/premake/premake-core/wiki/Tokens https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy

One possible solution is to find all files or get them from the project somehow and create a postbuild command for each header file which might be a lot slower

Mihai Sebea
  • 398
  • 2
  • 10
  • Actually token {COPY} now contains xcopy /Q /E /Y /I {args} on Windows, and /e copies subfolders even if empty (so even "stronger" than /s). The problem for the OP is that he's using ** not folder copy, which doesn't seem to work with cp. – hsandt Jul 27 '20 at 15:10