soci provides CMake targets:

    find_package(SOCI CONFIG REQUIRED)
    # Using core (loading backends at runtime)
    target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SOCI::soci_core>,SOCI::soci_core,SOCI::soci_core_static>)
