[CMake] How to depend on files generated in a subdirectory?

Attila Krasznahorkay attila.krasznahorkay at gmail.com
Wed Nov 18 12:55:49 EST 2015


Dear All,

I'm trying to do something that may be very easy to implement, but I'm really struggling with it at the moment...

I have a project in which I generate various files in subdirectories. Which I add to the main project file using add_subdirectory(...). Some of these files I need to merge into a single file at the end of the build. For which I tried to set up a custom command in my main project file. But I can't convince this main project file to find out how to generate the files whose generation rule sits in a subdirectory.

Attached is a simple example of what I mean. In this example it is possible to execute the following commands successfully:

make SubdirTarget
make

Since by the time the main target is built, its source files are already available. But if I try to just execute "make" first, I get:

Scanning dependencies of target MergeFiles
make[2]: *** No rule to make target `subdir/file3.txt', needed by `merged.txt'.  Stop.
make[1]: *** [CMakeFiles/MergeFiles.dir/all] Error 2
make: *** [all] Error 2

I tried a number of different directory/file name combinations by now, but the problematic thing in the end seems to be that these files are generated in a different directory than where I try to use them.

Do you have a suggestion on how I could do something like this?

Cheers,
            Attila

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mergeGeneratedExample.tar.bz2
Type: application/x-bzip2
Size: 644 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151118/0eb03046/attachment.bin>


More information about the CMake mailing list