How to include vtk dll in my self projection?

I want to use vtk in my team projection. I firstly install vtk, and collect the necessary dll, and the fold is:


Thirdparty
    VTK
        bin
            Debug
                xxx.dll
                ...
            Release
                xxx.dll
                ...
        include
                xxx
                ...
        lib
            Debug
                xxx
                ...
            Release
                ...

In my CMakeLists.txt:

set(VTI_DIR "xxx/Thirdparty/VTK")
include_directories(
    ${VTK_DIR}/include
)
target_link_libraries(Pro
    vtkCommonCore-9.0
    ....
)

For VTK 8, the CMakeLists.txt is OK, but it cause bug for vtk 9.0.
The target_link_libraries(Pro vtkCommonCore-9.0 ....) is OK for release, but it is wrong for debug. Because, the dll is vtkCommonCore-9.0d for debug. The dll of debug has a more d than that of release.
If I use target_link_libraries(Pro vtkCommonCore-9.0d ....) , the code would be ok for debug but wrong for release.

Can I remove the d in the dll of debug?

How can I fix this problem? Any suggestion is appreciated~~~

As far as I know, the way to do this “properly” is to not use “vtkCommonCore-9.0” as library name in CMake directly, instead, use:

find_package(VTK)
if (VTK_VERSION VERSION_LESS "8.90.0")
  include(${VTK_USE_FILE})
  target_link_libraries(Pro ${VTK_LIBRARIES})
else()
  target_link_libraries(Pro ${VTK_LIBRARIES})
  vtk_module_autoinit(
    TARGETS Pro
    MODULES ${VTK_LIBRARIES}
    )
endif()

For more info I would recommend checking the VTK examples, especially the Tutorial

find_package(VTK) is very convenient if I have compiled VTK from source code in my computer.

However, if I don’t want to compile VTK in my computer, I only want to use VTK by dll/lib/include. How can I do?
I have find one solution after reading the explanation of cmake.

target_link_libraries(Pro
    debug vtkCommonCore-9.0d
    optimized vtkCommonCore-9.0
    ....
)

The keyword of debug and optimized can distinguish debug/release.

But the above solution seem to be inconvenient.

cmake provides another two methods:

  1. A plain library name
    I use it as: target_link_libraries(Pro -lvtkCommonCore), but it failed.

  2. A generator expression.
    I use it as target_link_libraries(Pro vtkCommonCore-9.0$<1:d;2:"">), but it also failed.

You should use VTK::CommonCore. That is a CMake target which will end up linking to the right thing for you.