What is the best way to manage usage requirements for projects and
packages that are not part of your source tree?
Using find_package() to locate a dependency typically results in code
like:
add_executable(my_exe ${SOURCES})
find_package(Foo)
target_compile_definitions(my_exe SOME_DEF_NEEDED_TO_USE_FOO)
target_include_directories(my_exe ${FOO_INCLUDE_DIR})
target_link_libraries(my_exe ${FOO_LIBRARIES})
where the include directories, compiler definitions and libraries (Foo's
usage requirements) have to be found by reading the FindFoo.cmake
documentation.
Since 2.8.11, CMake has a much better approach for propagating usage
requirements between targets in the source tree [1]. The source target
specifies target_compile_definitions/include_directories/link_libraries
itself using the PUBLIC or INTERFACE keyword. Any target that links
with the source target automatically inherits all the usage
requirements.
What I would like is to be able to do is:
add_executable(my_exe ${SOURCES})
find_package(Foo)
target_link_libraries(my_exe Foo)
and have it Just Work. Is that possible?
I've tried doing it with ExternalProject instead of find_package:
add_executable(my_exe ${SOURCES})
ExternalProject_Add(Foo ...) # FAILS HERE
target_include_directories(Foo INTERFACE ...)
target_link_libraries(my_exe Foo)
But that fails with "target_include_directories called with
non-compilable target type".
Is there a better way? Is there something I'm missing?
I'd love to see a solution where adding a dependency with the Hunter
package manager [2] becomes a one-liner once you know the package name.
Right now, you still have to know the package-specific usage
requirements every time.
[1]
http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#build-specification-and-usage-requirements
[2] https://github.com/ruslo/hunter
Thanks,
Alex
--
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
--
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