Discussion:
[cmake-developers] why can target_include_directories() not be applied to custom targets?
Drew Parsons
2018-07-07 19:27:26 UTC
Permalink
Commit 510fdcb18801076e2041eaae2941375eecc93ec2 at
https://gitlab.kitware.com/cmake/cmake/commit/510fdcb18801076e2041eaae2941375eecc93ec2
prevents custom targets from using target_include_directories().

This makes no sense to me. A custom target is still a target. It needs
to be compiled, it uses -I flags.

Can you explain the ban on applying target_include_directories() to
custom targets?

Drew
--
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-developers
Petr Kmoch
2018-07-08 09:16:46 UTC
Permalink
Hi Drew,

a custom target can do literally anything, it's just a buildsystem wrapper
for running arbitrary executables; or often not even that, and is just a
collection of custom commands. There is nothing CMake automatically does
with the properties [INTERFACE_]INCLUDE_DIRECTORIES set on a custom command.

Note that if you need the properties set for some reason (i.e. if your
custom command/target code uses them for something), you can still set them
just fine using set_property() or set_target_properties(). However, I
expect this to be a very rare thing to do, so I think it's OK
target_include_directories() actually errors out on custom targets. IMO
it's much more likely that a non-custom target was intended.

(Note that I am just an ordinary CMake user, so the above is in no way
"official.")

Petr
Post by Drew Parsons
Commit 510fdcb18801076e2041eaae2941375eecc93ec2 at
https://gitlab.kitware.com/cmake/cmake/commit/
510fdcb18801076e2041eaae2941375eecc93ec2
prevents custom targets from using target_include_directories().
This makes no sense to me. A custom target is still a target. It needs
to be compiled, it uses -I flags.
Can you explain the ban on applying target_include_directories() to
custom targets?
Drew
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake-developers
Attila Krasznahorkay
2018-07-09 13:02:25 UTC
Permalink
Hi,

Just to say that setting INCLUDE_DIRECTORIES on a custom target is indeed a bit of an obscure thing, but we do use it. You can find the full reasoning in:

https://gitlab.kitware.com/cmake/cmake/issues/16830

Because of that, I understood that CMake will provide this functionality in the future as well, so we can rely on this build setup.

Cheers,
Attila
Post by Petr Kmoch
Hi Drew,
a custom target can do literally anything, it's just a buildsystem wrapper for running arbitrary executables; or often not even that, and is just a collection of custom commands. There is nothing CMake automatically does with the properties [INTERFACE_]INCLUDE_DIRECTORIES set on a custom command.
Note that if you need the properties set for some reason (i.e. if your custom command/target code uses them for something), you can still set them just fine using set_property() or set_target_properties(). However, I expect this to be a very rare thing to do, so I think it's OK target_include_directories() actually errors out on custom targets. IMO it's much more likely that a non-custom target was intended.
(Note that I am just an ordinary CMake user, so the above is in no way "official.")
Petr
Commit 510fdcb18801076e2041eaae2941375eecc93ec2 at
https://gitlab.kitware.com/cmake/cmake/commit/510fdcb18801076e2041eaae2941375eecc93ec2
prevents custom targets from using target_include_directories().
This makes no sense to me. A custom target is still a target. It needs
to be compiled, it uses -I flags.
Can you explain the ban on applying target_include_directories() to
custom targets?
Drew
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
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
https://cmake.org/mailman/listinfo/cmake-developers
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
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
https://cmake.org/mailman/listinfo/cmake-developers
--
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-developers
Drew Parsons
2018-07-09 14:32:42 UTC
Permalink
Post by Attila Krasznahorkay
Hi,
Just to say that setting INCLUDE_DIRECTORIES on a custom target is
indeed a bit of an obscure thing, but we do use it. You can find the
https://gitlab.kitware.com/cmake/cmake/issues/16830
Because of that, I understood that CMake will provide this
functionality in the future as well, so we can rely on this build
setup.
Cheers,
Attila
Post by Petr Kmoch
Hi Drew,
a custom target can do literally anything, it's just a buildsystem
wrapper for running arbitrary executables; or often not even that,
and is just a collection of custom commands. There is nothing CMake
automatically does with the properties
[INTERFACE_]INCLUDE_DIRECTORIES set on a custom command.
Thanks for the explanation Petr, and Attila.

Looks like

set_property(TARGET mylib PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})

does what I have in mind, it can stand in place of
target_include_directories() for custom targets.

Drew
--
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-developers
Loading...