[CMake] add_executable with generated files

Tom Kacvinsky tom.kacvinsky at vectorcast.com
Wed May 20 16:18:59 EDT 2015


On Wed, May 20, 2015 at 3:27 PM, Tom Kacvinsky <tom.kacvinsky at vectorcast.com
> wrote:

>
> On Wed, May 20, 2015 at 2:57 PM, Tom Kacvinsky <
> tom.kacvinsky at vectorcast.com> wrote:
>
>> I have need to make an executable that depends on a generated file.  I've
>> read several tutorials on how to do this, but even after following those
>> instructions, I get this error:
>>
>> CMake Error at CMakeLists.txt:436 (add_executable):
>>   Cannot find source file:
>>
>>     .chop/maint.adb
>>
>>   Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
>>
>> has anyone done this, and if so, do you have tips on how to proceed?
>>
>> Thanks,
>>
>> Tom
>>
>
> My mistake, the tutorials I looked at were for using generated files in
> add_library.  I do have a working add_library with generated files, but I
> can't seem to get generated files to work with add_executable.  So is there
> a difference between the two?  add_library allows for use of generated
> files, but add_executable does not?
>
>
OK, figured something out.  If the rule to generate the file is at the same
level CMakeLists.txt (or higher) than the CMakeLists.txt that contains the
add_executable command which uses the gnerated file, then everything is
OK.  But if the add_executable is at a higher level than the "rule" that
gnerates the file, everything falls apart.  This is why my add_library
example worked but by add_executable example was not.  To confuse the issue
even further, I have this setup

foo/CMakeLists.txt -> contains macro that uses add_executable
foo/vcast/CMakeLists.txt -> contains rule to generate file
foo/vcast/progs/CMakeLists.txt -> invokes macro defined at level 1, using
the file generated at level 2

Apparently this is enough to thow things off.  I though the add_executable
would have "occurred" at level 3 as that is where the macro is expanded,
but I am guessing cmake expansion of macros doesn't work that way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150520/b48ba193/attachment.html>


More information about the CMake mailing list