Hi Craig,

thanks for the tip.

My use case is specifically with external projects producing files that I don't 
know about in advance, so I thought OBJECT_DEPENDS wouldn't really work. But 
then I realised that if I can extract the name of the "done" stamp, this would 
do the trick.

So I end up with an external project declaration something like this:

ExternalProject_Add(foo URL foo.tgz
        BUILD_COMMAND make -C <SOURCE_DIR> all
        INSTALL_COMMAND make -C <SOURCE_DIR> install
)

_ep_get_step_stampfile(foo "done" foo_done_stamp_file)
add_library(libfoo INTERFACE IMPORTED)
add_dependencies(libfoo foo)
set_target_properties(libfoo PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/include)

And then simply a project declaration like this:

project(bar)

set_source_files_properties(bar.c OBJECT_DEPENDS ${foo_done_stamp_file})
add_executable(bar bar.c)
target_link_libraries(bar libfoo)

And very happily, it doesn't try to compile bar.c until the "foo" external 
project has been installed. It's unfortunate to have to use an internal 
ExternalProject function but AFAICT this is the best way without repeating 
logic to get the complete filepath of the stamp.

Thanks again,
    W
________________________________________
From: Craig Scott [[email protected]]
Sent: 07 December 2017 19:50
To: Wouter Klouwen
Cc: CMake Developers
Subject: Re: [cmake-developers] Source file dependencies

[External email]

Have a look at the documentation for the OBJECT_DEPENDS source 
property<https://cmake.org/cmake/help/latest/prop_sf/OBJECT_DEPENDS.html>, 
which explains some options that may be relevant for your question.

On Fri, Dec 8, 2017 at 5:08 AM, Wouter Klouwen 
<[email protected]<mailto:[email protected]>> wrote:
Hi all,

In trying to improve our build rules, one of the problems I encountered
is that I effectively have some source files that cannot be compiled
unless certain targets are run.

I noticed that cmSourceFile has the AddDepend() method, which looks to
do the kind of thing that I want to do.
cmFlTKWrapUICommand and cmCPluginAPI are the only users of this, with
there being no way of setting this from a CMakeLists.txt.
The former seems to do exactly the kind of think that I need, which is
to set up some code generation.

It would be nice if I could add items to this list, perhaps through
setting a property on the source files themselves, e.g this rather
contrived short example:

add_custom_command(OUTPUT bar.h COMMAND touch bar.h)
add_custom_target(bar DEPENDS generate_bar bar.h)
set_source_files_properties(foo.cpp PROPERTIES DEPENDS bar)

Is this a bad idea? Would there be a better way?

Thanks,
    W
This transmission contains information that may be confidential and contain 
personal views which are not necessarily those of YouView TV Ltd. YouView TV 
Ltd (Co No:7308805) is a limited liability company registered in England and 
Wales with its registered address at YouView TV Ltd, 3rd Floor, 10 Lower Thames 
Street, London, EC3R 6YT. For details see our web site at http://www.youview.com
--

Powered by www.kitware.com<http://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-developers



--
Craig Scott
Melbourne, Australia
https://crascit.com


[External email. Treat hyperlinks and attachments with caution]

-- 

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-developers

Reply via email to