[Cmake] Dependency on generated file

Ken Martin ken.martin at kitware.com
Tue May 13 09:05:04 EDT 2003


> I have a file, called generator.c, which when compiled and run, dumps
to
> std
> out a bit of C code that I need to redirect to a file - out.c, for
> example.
> The file out.c is then #included into another file, lib.c, which I
want to
> compile into a static library.
> 
> How do I create a dependency between the generated file out.c and the
> generating executable made from generator.c so that they're built
first
> and
> lib.c can be properly compiled?
> 
> In other words,
> generator.c => generator
> generator ==> out.c
> out.c, lib.c == > libmylib


Custom commands are being cleaned up right now but the basic idea is the
same. Without testing I think the following is the basic idea:

    # add the executable
    ADD_EXECUTABLE(generator generator.c)

    # mark out.c as generated
    SET_SOURCE_FILE_PROPERTIES(${PROJECT_BINARY_DIR}/out.c GENERATED 1)

    # add a post build command (confusing...)
    ADD_CUSTOM_COMMAND(
      SOURCE generator
      COMMAND ${EXECUTABLE_OUTPUT_PATH}/generator${EXE_EXTENSION}
      ARGS your_args
      TARGET generator
      OUTPUTS ${PROJECT_BINARY_DIR}/out.c)

    # add the library
    ADD_LIBRARY(mylib lib.c ${PROJECT_BINARY_DIR}/out.c)

    # make sure the generator is built before mylib
    ADD_DEPENDENCIES(mylib generator)

- Ken

> 
> Thanks,
> DL
> _______________________________________________
> Cmake mailing list
> Cmake at public.kitware.com
> http://public.kitware.com/mailman/listinfo/cmake





More information about the CMake mailing list