Adding a custom_command dependency to all sources

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Adding a custom_command dependency to all sources

Pentecost, Caleb

Howdy,

 

I’m looking to add a dependency to all source files to ensure that a generated file is up-to-date before compilation. This generated file is “passed in” to the compiler via a global compiler definition. Is there an easy or built-in way to do this, or will I need to manually add a made-up target to every file in every library directory?

 

Currently, the generated file is created in the CMake Options file, using an exec_program command near the top of the file. The output of this process is not tracked, but the GLOBAL_DEFS variable applied to every source file includes a line that directs the compiler to consume the new file. It looks a little like this:

 

Lib_options.cmake

[…]

exec_program(

    <executable>

    ARGS

    -o <outputFile>

    -I <inputFile>

    -x <extraArgs…>

)

[…]

set (GLOBAL_DEFS

  -D<definitions…>

  -@<outputFile>

)

[…]

 

However, the dependency tree is not aware of this file and will not prepare it in any way on a per-file bases. In this case the program is executed every build regardless of if <inputFile> has been modified. This adds unnecessary time to an incremental build if no change is made, and if <inputFile> does happen to change CMake will not recompile the sources accordingly. I have to do a clean/rebuild in order for the changes to “take”.

 

What I would like to see is a way to actually add <outputFile> as a dependency to each source file. Now, I’m no CMake expert, but I think it would look something like this:

 

Lib_options.cmake

[…]

# Create a command/target for our output file

add_custom_command(

  OUTPUT

    <outputFile>

  DEPENDS

    <inputFile>

  COMMAND

  <executable>

    ARGS

      -o <outputFile>

      -I <inputFile>

      -x <extraArgs…>

)

 

# Do something to make all source files depend on <outputFile>

# <Magic goes here>

 

[…]

set (GLOBAL_DEFS

  -D<definitions…>

  -@<outputFile>

)

[…]

 

Would this be a feasible thing to do in CMake, especially at the options file level? If you need any more information please let me know.

 

Thank you in advance!


--

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:
https://cmake.org/mailman/listinfo/cmake