Hej Rainer,
>
> project-dir
> +- component1
> | +- src
> | +- include-dir1
> | +- include-dir2
> +- component2
>
> Let's say I want "component2" to add "include-dir1" and "include-dir2"
> from "component1" as include directories without "component2" knowing
> that these two directories exist.
>
There is no way this is possible afaik, because if component2 uses any header
file in one of the include directories, you would need to pass these
directories to your compiler (most of the times using a -I or /I option
depending on the OS).
However,
is it maybe possible that what you’re *really* asking is, whether it would be
possible to say something like:
target_link_libraries(component1 component2)
*without* explicitly spilling out the include directories, which would look
something like:
target_include_directories(component1 PRIVATE
$<OBJECT_PROPERTY:component1,INTERFACE_INCLUDE_DIRECTORIES>)
then the answer would be ‘yes’. You’d need to study the concept of IMPORTed
and EXPORTed targets in CMake, see for instance
http://www.cmake.org/cmake/help/v3.0/command/add_executable.html
<http://www.cmake.org/cmake/help/v3.0/command/add_executable.html>,
http://www.cmake.org/cmake/help/v3.0/command/add_library.html
<http://www.cmake.org/cmake/help/v3.0/command/add_library.html> and
http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets
<http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets>
These concepts were originally created to nicely handle external dependencies
(check out for instance the Qt5 documentation on integration with CMake, see
http://doc.qt.io/qt-5/cmake-manual.html - you simply link with the proper Qt5
library, and these are set up such that automatically all required include
folders are added to the list of include locations to build your component).
However, with some work (essentially, creating some wrapper functions/macros)
it can just as easily be made to work for dependencies inside a project. I
don’t know about details, I just know that the infrastructure guys in the team
I’m working in, made it work like that (borrowing a lot from the CMake files
that come with Qt5) and it works like a charm!
> Therefore my question: Is there a way to import project
> settings/properties which have been exported from other
> subdirectories? And is cmake intended to be used like that?
>
> I don't know whether I use the correct terms here but I hope that the
> idea is clear.
If you meant to ask what I wrote above, then the question was entirely correct,
but the idea clear (in particular because I use it that way) and yes, there is
a way. Whether CMake is ‘intended to be used like that I really wouldn’t know.
My feeling is that this is definitely not the original intention of the
feature. However, looking at how it works, this approach certainly also will
not break as long as the feature is there.
Sincerely,
Jakob van Bethlehem
--
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