# Included via CMAKE_USER_MAKE_RULES_OVERRIDE, i.e. AFTER Platform/Windows.cmake
# and Platform/Windows-Embarcadero*.cmake have run. This file corrects settings
# that the built-in Embarcadero platform module generates for the classic
# ilink64/bcc32 driver but that are wrong for bcc64x (clang-20 + ld.lld).

# Windows.cmake sets CMAKE_LINK_LIBRARY_SUFFIX ".lib" (MSVC/ilink convention),
# which turns bare link libs into -lfoo.lib — unresolvable by ld.lld. bcc64x
# uses MinGW/lld: bare names must be -lfoo so lld finds libfoo.a.
set(CMAKE_LINK_LIBRARY_SUFFIX "")

# The built-in __embarcadero_language() uses the classic ilink64 driver flags:
#   compile: -tR -DWIN32 ...
#   link:    -tR -tD -e<TARGET> ... && implib -c -w <TARGET_IMPLIB> <TARGET>
# bcc64x rejects -e<TARGET> (error: unknown argument). Override with the
# correct clang+ld.lld conventions used by the VTK bcc64x build.
foreach(_bcc_lang C CXX)
  set(CMAKE_${_bcc_lang}_CREATE_SHARED_LIBRARY
    "<CMAKE_${_bcc_lang}_COMPILER> --rsp-quoting=windows -shared -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES> -lc++")
  set(CMAKE_${_bcc_lang}_CREATE_SHARED_MODULE
    "<CMAKE_${_bcc_lang}_COMPILER> --rsp-quoting=windows -shared -o <TARGET> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES> -lc++")
  set(CMAKE_${_bcc_lang}_LINK_EXECUTABLE
    "<CMAKE_${_bcc_lang}_COMPILER> --rsp-quoting=windows -o <TARGET> <LINK_FLAGS> <FLAGS> <OBJECTS> <LINK_LIBRARIES> -lc++")
  set(CMAKE_${_bcc_lang}_CREATE_STATIC_LIBRARY
    "<CMAKE_AR> qc <TARGET> <OBJECTS>")
  # Clear the Borland standard-library list; bcc64x links against libc++ (added
  # explicitly via -lc++ above) and MinGW's libgcc/libmsvcrt automatically.
  set(CMAKE_${_bcc_lang}_STANDARD_LIBRARIES "")
endforeach()
unset(_bcc_lang)
