How does opencv distinguish whether use debug or release version?

I’m debugging cmake files of opencv and I’ve noticed that seems opencv can smartly choice appropriate library without specifing debug and release version manually, i.e.

find_package(OpenCV REQUIRED)
target_include_directories(${pn} PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(${pn} PRIVATE ${OpenCV_LIBS}) # no need to specify xxxd.lib or xxx.lib

If the project I build is debug version, opencv will choice opencvXXXd.lib otherwise opencvXXX.lib. I’m curious of this feature and haven’t found where it implements in *.cmake.

It’s not opencv but cmake read CMake Documentation and Community