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

Le lun. 29 févr. 2016 09:43, Nils Gladitz <nilsglad...@gmail.com> a écrit :

> On 02/29/2016 03:34 PM, Patrick Boettcher wrote:
> > Hi list,
> >
> > I came across the INTERFACE-type of libraries when writing a
> > FindModule.cmake-file for custom libraries installed by my
> > project.
> >
> > Here is what I'm doing after having found the libraries and the
> > determined the paths: LIB1 is the library and LIB1_INCLUDE_DIRS its
> > include-dirs:
> >
> >    add_library(name INTERFACE)
> >
> >    target_link_libraries(name INTERFACE ${LIB1})
> >
> >    if(FFTW3_FOUND)
> >       target_include_directories(name INTERFACE
> >               {$FFTW3_INCLUDE_DIRS})
> >       target_link_libraries(name INTERFACE ${FFTW3_LIBRARIES} )
> >    endif()
> >
> >    target_include_directories(name INTERFACE ${LIB1_INCLUDE_DIRS})
> >
> >    # need c++11 compile options for if-name
> >    set_property(TARGET name PROPERTY
> >               INTERFACE_COMPILE_FEATURES cxx_range_for)
> >
> > This makes that in the CMakeLists.txt which includes my package-file a
> > user needing libname for his executable does:
> >
> >    add_executable(main main.cpp)
> >    target_link_libraries(main name)
> >
> > This will
> >
> > 1) set C++11 flags for compilation
> > 2) set the right include-pathes
> > 3) link with the right libraries as per my order
> >
> > Awesome. But is this a good practice? Are there any pitfalls?
>
> This sounds like a use case for IMPORTED rather than INTERFACE libraries.
> INTERFACE libraries can be IMPORTED as well but are not intended for
> pre-build linkable libraries (which you seem to have).
>
> This documents how to create find modules with IMPORTED targets:
>
> https://cmake.org/cmake/help/v3.4/manual/cmake-developer.7.html#find-modules
>
> Nils
> --
>
> 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
>
-- 

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

Reply via email to