<p dir="ltr">Speaking of imported targets, I'm wondering why alias imported targets aren't added to all default FindXXX.cmake scripts. This would help provide better examples, and have the community use better cmakelists.txt and hopefully reduce the bad usages of include_directories and such</p>
<br><div class="gmail_quote"><div dir="ltr">Le lun. 29 févr. 2016 09:43, Nils Gladitz <<a href="mailto:nilsgladitz@gmail.com">nilsgladitz@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 02/29/2016 03:34 PM, Patrick Boettcher wrote:<br>
> Hi list,<br>
><br>
> I came across the INTERFACE-type of libraries when writing a<br>
> FindModule.cmake-file for custom libraries installed by my<br>
> project.<br>
><br>
> Here is what I'm doing after having found the libraries and the<br>
> determined the paths: LIB1 is the library and LIB1_INCLUDE_DIRS its<br>
> include-dirs:<br>
><br>
>    add_library(name INTERFACE)<br>
><br>
>    target_link_libraries(name INTERFACE ${LIB1})<br>
><br>
>    if(FFTW3_FOUND)<br>
>       target_include_directories(name INTERFACE<br>
>               {$FFTW3_INCLUDE_DIRS})<br>
>       target_link_libraries(name INTERFACE ${FFTW3_LIBRARIES} )<br>
>    endif()<br>
><br>
>    target_include_directories(name INTERFACE ${LIB1_INCLUDE_DIRS})<br>
><br>
>    # need c++11 compile options for if-name<br>
>    set_property(TARGET name PROPERTY<br>
>               INTERFACE_COMPILE_FEATURES cxx_range_for)<br>
><br>
> This makes that in the CMakeLists.txt which includes my package-file a<br>
> user needing libname for his executable does:<br>
><br>
>    add_executable(main main.cpp)<br>
>    target_link_libraries(main name)<br>
><br>
> This will<br>
><br>
> 1) set C++11 flags for compilation<br>
> 2) set the right include-pathes<br>
> 3) link with the right libraries as per my order<br>
><br>
> Awesome. But is this a good practice? Are there any pitfalls?<br>
<br>
This sounds like a use case for IMPORTED rather than INTERFACE libraries.<br>
INTERFACE libraries can be IMPORTED as well but are not intended for<br>
pre-build linkable libraries (which you seem to have).<br>
<br>
This documents how to create find modules with IMPORTED targets:<br>
<a href="https://cmake.org/cmake/help/v3.4/manual/cmake-developer.7.html#find-modules" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/v3.4/manual/cmake-developer.7.html#find-modules</a><br>
<br>
Nils<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div>