[CMake] Generating include files
Craig Scott
craig.scott at crascit.com
Fri May 19 17:24:56 EDT 2017
A bit of a long-shot, have you tried generating the file with the extension
.h instead of .c? That might allow it to be picked up by the dependency
scanner (I don't know if it treats file extensions differently). Also, the
add_custom_command(OUTPUT...) call needs to be in the same CMakeLists.txt
file as the one where you create the target that pulls in foo.c or else the
dependency relationship isn't created by CMake. I wrote an article on working
with generated sources
<https://crascit.com/2017/04/18/generated-sources-in-cmake-builds/>
recently which covers some of these details, maybe it contains some useful
info for you.
On Sat, May 20, 2017 at 7:00 AM, Urs Thuermann <urs at isnogud.escape.de>
wrote:
> Michael Ellery <mellery451 at gmail.com> writes:
>
> > if your source can be generated by simple substitution of variable
> > values (like a template file), then configure_file() will do the
> > trick. If the process to create the file is more complex, then
> > add_custom_command() with an appropriate OUTPUT specification is
> > probably what you want, something like:
>
> Yes, the awk example was a simplification. The table to be generated
> is much larger using a somewhat more complex specification. I don't
> want to calculate at run-time in foo.c, but at compile-time so that it
> can go into a static const int array.
>
> > add_custom_command(OUTPUT tab.c COMMAND "awk -f mktab > tab.c")
>
> I have tried dozens of combinations with add_custom_command(),
> include_directories(), and ${CMAKE_BINARY_DIR}. Also the way you
> show. But the only way I found to have tab.c actually generated was
> to put tab.c into the add_executable() specification, but then it
> generates a tab.o which is linked into the executable. But I want to
> have the tab[] static, i.e. included into a C file, not linked in.
>
> > You will need to make sure that some other target explicitly depends
> > on tab.c (or whatever you name the output) to cause this custom rule
> > to be executed.
>
> Is there a way to specify that foo.o depends on tab.c? For some
> reason cmake's scan does not seem to find this.
>
> urs
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
--
Craig Scott
Melbourne, Australia
https://crascit.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170520/9662cc6d/attachment.html>
More information about the CMake
mailing list