[CMake] Good practice: using INTERFACE-libraries in FindABC.cmake?
Patrick Boettcher
patrick.boettcher at posteo.de
Mon Feb 29 09:34:53 EST 2016
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?
Thank you for your help in advance.
best regards,
--
Patrick.
More information about the CMake
mailing list