On 12/21/2016 07:12 AM, Florent Castelli wrote:
> find_package(foo)
> if(NOT FOO_FOUND)
> add_library(foo STATIC foo.cpp)
> endif()
Instead do
find_package(foo)
if(NOT FOO_FOUND)
add_subdirectory(bundled_foo)
endif()
so that the imported targets are visible. Inside the bundled_foo you can build
the target and then crate an ALIAS library whose name matches what the imported
target would have been.
> make imported libraries global by default
The reason they are locally scoped is that find_package() may load
different, possibly conflicting, external packages in separate directories.
The find_package() call should be made at the highest level that contains
anything that directly references the target. See above example.
An alternative is:
find_package(foo)
add_library(Foo INTERFACE)
target_link_libraries(Foo PUBLIC FOO::FOO)
That will make a globally visible Foo target that when used forwards all
usage requirements from the imported target.
-Brad
--
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