Build a library with different options in one run

I have several configurations in my main project and each configuration depends on an external library. But for different configurations it is necessary to compile this library with different options. The library is compiled along with the main project. How can I create multiple targets by connecting the same subdirectory several times with different options?

foreach (variant IN LISTS variants)
  add_subdirectory(src "${CMAKE_CURRENT_BINARY_DIR}/src-${variant}")
endforeach ()