> On May 19, 2017, at 2:00 PM, Urs Thuermann <[email protected]> wrote: > > Michael Ellery <[email protected]> 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. >
well, if you rename tab.c to tab.h, I’m pretty sure CMAKE will honor it as a dependency but won’t compile it..so that might be the easiest. Alternatively, use set_source_file_properties to set https://cmake.org/cmake/help/v3.8/prop_sf/OBJECT_DEPENDS.html#prop_sf:OBJECT_DEPENDS -Mike -- 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
