add_library(NvGPUDirect::DVP SHARED IMPORTED)
target_include_directories(NvGPUDirect::DVP INTERFACE "${NV_GPU_DIRECT_INCLUDE_DIR}")
set_target_properties(NvGPUDirect::DVP
PROPERTIES
IMPORTED_IMPLIB ${NV_GPU_DIRECT_IMPLIB}
)
set_target_properties(NvGPUDirect::DVP
PROPERTIES
IMPORTED_LOCATION ${NV_GPU_DIRECT_DLL}
)
To reference the imported library, the following is enough (no need to configure include paths) :
target_link_libraries(UserTarget NvGPUDirect::DVP)
To copy DLL to some location :
get_target_property(NvGPUDirect_DVP_DLL NvGPUDirect::DVP LOCATION)
When doing install
targets, PUBLIC_HEADER
expects to have its DESTINATION
for each location.
I happened to need to install a target in different location, one with headers for shipping, one with runtime files only. In this case, I got a warning :
CMake Warning (dev) at MyDLL/CMakeLists.txt:241 (install):
Target MyDLL has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.
This warning is for project developers. Use -Wno-dev to suppress it.
I replaced PUBLIC_HEADER
property with FILE_SET HEADERS
and got rid of the warning.
add_library(myDLL SHARED PRIVATE ${SOURCES})
target_sources(myDLL PRIVATE ${HEADERS})
target_sources(myDLL PUBLIC ${HEADERS_PUBLIC})
...
target_sources(
MyDLL INTERFACE
FILE_SET HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/PublicHeaders/
FILES "${HEADERS_PUBLIC}"
)
...
install(
TARGETS MyDLL
...
FILE_SET HEADERS DESTINATION MyDLL-SDK/include
...
)