The package giflib is compatible with built-in CMake targets:
find_package(GIF REQUIRED)
target_link_libraries(main PRIVATE GIF::GIF)