Ok, just to finalize this. Instead of the cmake code I attached above to link FFmpeg libraries, I used the same FindFFmpeg.cmake file that used by OBS Studio project on GitHub, and it worked as expected!
I don't know what is the difference yet, I need to read through it carefully and find the differences.