On Thu, 2019-03-28 at 15:26 -0400, Norton Allen wrote:
> On 3/28/2019 3:11 PM, Kyle Edwards wrote:
> > On Thu, 2019-03-28 at 14:58 -0400, Norton Allen wrote:
> > > because mygeneratedfile is not a 'target', and I can't make it
> > > into a target with add_custom_target() because that's talking
> > > about something else entirely (commands that will be run
> > > unconditionally, not based on dependencies)
> > What exactly do you mean by "based on dependencies"? Do you mean
> > that this file has dependencies on something else, or that
> > something else has dependencies on it?
> I mean this file depends on some source files--if the source files
> change, I want to rerun the generation step.
Using the DEPENDS argument of add_custom_command() will do this.
However, add_custom_command() on its own isn't enough to ensure that
the file is generated before installation. You need to pair
add_custom_command() with add_custom_target(). Example:
add_custom_command(
  OUTPUT mygeneratedfile
  COMMAND mytool -o mygeneratedfile
  DEPENDS mysourcefile
)
add_custom_target(mygeneratedtarget
  DEPENDS mygeneratedfile
)

This is different from:

add_custom_target(mygeneratedtarget
  COMMAND mytool -o mygeneratedfile
  BYPRODUCTS mygeneratedfile
  DEPENDS mysourcefile
)

because it will only run mytool when it needs to (when mysourcefile has
changed).

Kyle
-- 

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

Reply via email to