The package libpq provides CMake integration:

    find_package(PostgreSQL REQUIRED)
    target_link_libraries(main PRIVATE PostgreSQL::PostgreSQL)