Skip to content

Instantly share code, notes, and snippets.

@rotoglup
Last active December 20, 2022 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rotoglup/f9d31b3fabded55631c210d483d4f943 to your computer and use it in GitHub Desktop.
Save rotoglup/f9d31b3fabded55631c210d483d4f943 to your computer and use it in GitHub Desktop.
Some notes about CMake constructs I had to use here and there

IMPORTED library

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)

FILE_SET HEADERS instead of PUBLIC_HEADER

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
    ...
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment