# Candidate-only cross-build helpers. Keep the locked FreeCAD source tree clean
# and forbid its fallback FetchContent path from reaching the network.
set(FETCHCONTENT_FULLY_DISCONNECTED ON CACHE BOOL "Disable network fallback" FORCE)
set(fmt_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake/fmt" CACHE PATH "Candidate header-only fmt package" FORCE)

# FreeCAD 1.1.1 has no dedicated Emscripten branch in FCConfig.h. Emscripten's
# POSIX layer follows the Linux code paths for this headless candidate.
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
  if(NOT FREECAD_WASM_OCCT_COMPAT_INCLUDE
     OR NOT EXISTS "${FREECAD_WASM_OCCT_COMPAT_INCLUDE}/TopTools_ListOfShape.hxx")
    message(FATAL_ERROR
      "FREECAD_WASM_OCCT_COMPAT_INCLUDE must point to OCCT's Deprecated/NCollectionAliases directory")
  endif()
  add_compile_definitions(__linux__=1)
  include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/wasm-compat")
  include_directories(BEFORE SYSTEM "${FREECAD_WASM_OCCT_COMPAT_INCLUDE}")
  # FreeCAD's native UNIX branch adds --undefined,dynamic_lookup, which is
  # incompatible with Emscripten's relocatable-object emulation of SHARED.
  set(UNIX FALSE)
  # Qt disables its timezone backend on WASM. FreeCAD calls systemTimeZone()
  # only when formatting diagnostic timestamps, so use deterministic UTC.
  add_compile_options(
    "$<$<COMPILE_LANGUAGE:CXX>:-include${CMAKE_CURRENT_LIST_DIR}/freecad-wasm-sdk-compat.h>"
    "$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-declarations>"
  )
endif()

# The headless SDK does not ship Qt LinguistTools, while FreeCAD Base/App invoke
# qt_add_translation unconditionally. Keep their resource targets valid without
# pulling host-generated .qm files into the wasm candidate.
set(FREECAD_WASM_EMBED_TRANSLATIONS OFF CACHE BOOL "Embed FreeCAD translations in the candidate wasm SDK")
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
   AND NOT FREECAD_WASM_EMBED_TRANSLATIONS
   AND NOT COMMAND qt_add_translation)
  function(qt_add_translation output_variable)
    set(${output_variable} "" PARENT_SCOPE)
  endfunction()
endif()
