cmake_minimum_required(VERSION 3.20)

project(iggy_reconstructed C CXX)

function(configure_iggy_reconstructed_target target language_standard)
  target_compile_features(${target} PUBLIC ${language_standard})
  target_compile_definitions(${target} PRIVATE __RADINSTATICLIB__)
  target_include_directories(
    ${target}
    PUBLIC
      ${CMAKE_CURRENT_SOURCE_DIR}
      ${CMAKE_CURRENT_SOURCE_DIR}/../../include
  )

  if(MSVC)
    target_compile_options(${target} PRIVATE /W4 /WX)
  else()
    target_compile_options(${target} PRIVATE -Wall -Wextra -Werror)
  endif()
endfunction()

add_library(iggy_reconstructed_rrmath STATIC rrMath.cpp)
configure_iggy_reconstructed_target(iggy_reconstructed_rrmath cxx_std_17)

add_library(iggy_reconstructed_rrstring STATIC rrstring.c)
configure_iggy_reconstructed_target(iggy_reconstructed_rrstring c_std_11)

add_library(
  iggy_reconstructed_arena_allocator
  STATIC
  iggy_arena_allocator.c
)
configure_iggy_reconstructed_target(
  iggy_reconstructed_arena_allocator
  c_std_11
)

add_library(
  iggy_reconstructed_api_global
  STATIC
  iggy_api_functions_global.c
)
configure_iggy_reconstructed_target(iggy_reconstructed_api_global c_std_11)

add_library(iggy_reconstructed_swf_state STATIC swf_state.c)
configure_iggy_reconstructed_target(iggy_reconstructed_swf_state c_std_11)

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_math_${platform})
  add_library(${target} STATIC swf_math.c)
  target_compile_definitions(
    ${target}
    PUBLIC IGGY_RECONSTRUCT_SWF_MATH_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_unicode_${platform})
  add_library(${target} STATIC iggy_unicode.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_UNICODE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_util_${platform})
  add_library(${target} STATIC as3vm_util.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_UTIL_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_file_reader_${platform})
  add_library(${target} STATIC iggy_file_reader.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_FILE_READER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_platform_deps_${platform})
  add_library(${target} STATIC iggy_platform_deps.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_PLATFORM_DEPS_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_filter_${platform})
  add_library(${target} STATIC swf_draw_filter.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_FILTER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_mixer_${platform})
  add_library(${target} STATIC iggy_mixer.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_MIXER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_lib_${platform})
  add_library(${target} STATIC swf_draw_lib.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_LIB_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_renderstate_${platform})
  add_library(${target} STATIC swf_draw_renderstate.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_RENDERSTATE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_filltype_${platform})
  add_library(${target} STATIC swf_draw_filltype.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_FILLTYPE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_texture_${platform})
  add_library(${target} STATIC swf_draw_texture.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_TEXTURE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_interface_${platform})
  add_library(${target} STATIC swf_draw_interface.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_INTERFACE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_triangulate_ears_${platform})
  add_library(${target} STATIC triangulate_ears.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_TRIANGULATE_EARS_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_triangulate_${platform})
  add_library(${target} STATIC swf_draw_triangulate.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_TRIANGULATE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_shape_${platform})
  add_library(${target} STATIC swf_draw_shape.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_fontcache_${platform})
  add_library(${target} STATIC swf_fontcache.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_FONTCACHE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_polygonalize_${platform})
  add_library(${target} STATIC swf_polygonalize.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_POLYGONALIZE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

add_library(
  iggy_reconstructed_as3vm_debugger_interface
  STATIC
  as3vm_debugger_interface.c
)
configure_iggy_reconstructed_target(
  iggy_reconstructed_as3vm_debugger_interface
  c_std_11
)

add_library(iggy_reconstructed_as3vm_op_strings STATIC as3vm_op_strings.c)
configure_iggy_reconstructed_target(
  iggy_reconstructed_as3vm_op_strings
  c_std_11
)

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_platform_audio_${platform})
  add_library(${target} STATIC iggy_platform_audio.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AUDIO_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_${platform})
  add_library(${target} STATIC swf_draw.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_draw_text_${platform})
  add_library(${target} STATIC swf_draw_text.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_TEXT_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

add_library(iggy_reconstructed_avm2_microcode STATIC avm2_microcode.c)
configure_iggy_reconstructed_target(iggy_reconstructed_avm2_microcode c_std_11)

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_iggy_allocation_${platform})
  add_library(${target} STATIC iggy_allocation.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_IGGY_ALLOCATION_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_iggy_font_provider_${platform})
  add_library(${target} STATIC iggy_font_provider.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_IGGY_FONT_PROVIDER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_iggy_sound_${platform})
  add_library(${target} STATIC iggy_sound.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_IGGY_SOUND_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_stb_truetype_wrapper_${platform})
  add_library(${target} STATIC stb_truetype_wrapper.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_STB_TRUETYPE_WRAPPER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_gr_strokepath_${platform})
  add_library(${target} STATIC gr_strokepath.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_GR_STROKEPATH_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_names_${platform})
  add_library(${target} STATIC as3vm_names.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_NAMES_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_create_${platform})
  add_library(${target} STATIC as3vm_create.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_CREATE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_gc_${platform})
  add_library(${target} STATIC as3vm_gc.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_GC_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_class -- AS3 / AVM2 ABC class linker (4-platform).  Imports memcpy /
# memset / longjmp, so guard against libcall re-synthesis with -fno-builtin
# (clang/gcc) or /Oi- (MSVC), matching the sibling as3vm_gc / as3vm_create.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_class_${platform})
  add_library(${target} STATIC as3vm_class.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_CLASS_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_convert -- AS3 / AVM2 ECMAScript type conversion (4-platform).  Imports
# fmod / floor / memcmp, so guard against libcall re-synthesis with -fno-builtin
# (clang/gcc) or /Oi- (MSVC).  floor is inlined on orbis and memcmp is inlined
# on durango, matching the per-target lowering recovered from the objects.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_convert_${platform})
  add_library(${target} STATIC as3vm_convert.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_CONVERT_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_property -- AS3 / AVM2 property-resolution core (4-platform).  Imports
# memset (no memcpy / longjmp), so guard against libcall re-synthesis with
# -fno-builtin (clang/gcc) or /Oi- (MSVC), matching the sibling as3vm_gc /
# as3vm_class / as3vm_convert.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_property_${platform})
  add_library(${target} STATIC as3vm_property.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_PROPERTY_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_imp_array -- AS3 / AVM2 Array + Vector class (4-platform).  Imports
# memcpy (no memset / longjmp), so guard against libcall re-synthesis with
# -fno-builtin (clang/gcc) or /Oi- (MSVC), matching the sibling as3vm_gc /
# as3vm_class / as3vm_convert / as3vm_property.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_imp_array_${platform})
  add_library(${target} STATIC as3vm_imp_array.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_IMP_ARRAY_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_imp_math -- AS3 / AVM2 Math class (4-platform).  Imports the libm
# transcendentals + fabs / ceil / floor / sqrt (a portable -ffreestanding
# -fno-builtin build re-emits every one as a call), so guard against libcall /
# builtin re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC), matching
# the sibling as3vm_gc / as3vm_class / as3vm_convert / as3vm_property /
# as3vm_imp_array.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_imp_math_${platform})
  add_library(${target} STATIC as3vm_imp_math.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_IMP_MATH_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3_component_helpers -- AS3 / AVM2 value-marshalling helper layer
# (4-platform).  The F32 getters/setters widen / narrow float<->double, so guard
# against libcall / builtin re-synthesis with -fno-builtin (clang/gcc) or /Oi-
# (MSVC); on vita the armv7a-gnueabihf hard-float target lowers the casts to VFP
# vcvt, pulling NO __aeabi soft-float helpers.  Matches the sibling as3vm_convert /
# as3vm_imp_math / as3vm_imp_string stanzas.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3_component_helpers_${platform})
  add_library(${target} STATIC as3_component_helpers.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3_COMPONENT_HELPERS_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_imp_string -- AS3 / AVM2 String class (4-platform).  Imports memcmp
# (every substring compare: indexOf / lastIndexOf / search / replace / split) and
# memcpy (the substring / replace builders), so guard against libcall re-synthesis
# with -fno-builtin (clang/gcc) or /Oi- (MSVC), matching the sibling as3vm_gc /
# as3vm_class / as3vm_convert / as3vm_property / as3vm_imp_array / as3vm_imp_math.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_imp_string_${platform})
  add_library(${target} STATIC as3vm_imp_string.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_IMP_STRING_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_classes_base_dummy -- Iggy's E4X XML / QName / XMLList AS3-class DUMMY
# layer (4-platform; 80 exports).  E4X XML is UNSUPPORTED, so every method is a
# uniform stub that loads frame[0] and raises exception code 0x74 through the
# module's ONLY import (as3vm_exception_GC).  No libc / libm / float / string
# helpers are touched (the raw .c is a byte-identical 883 lines everywhere), so
# -- unlike the sibling as3vm_* stanzas -- NO -fno-builtin / /Oi- guard is
# needed.  Owns no data global and carries no rodata message string.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_classes_base_dummy_${platform})
  add_library(${target} STATIC as3vm_classes_base_dummy.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_CLASSES_BASE_DUMMY_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

# as3vm_classes_flash_dummy -- Iggy's flash.* AS3-class DUMMY layer (4-platform;
# 223 exports).  These flash.* classes are UNSUPPORTED, so every method is the
# same uniform stub that loads frame[0] and raises exception code 0x74 through
# the module's ONLY import (as3vm_exception_GC).  No libc / libm / float / string
# helpers are touched (raw .c is 2456 lines everywhere), so NO -fno-builtin /
# /Oi- guard is needed.  Owns no data global and carries no rodata message string.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_classes_flash_dummy_${platform})
  add_library(${target} STATIC as3vm_classes_flash_dummy.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_CLASSES_FLASH_DUMMY_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
endforeach()

add_library(iggy_reconstructed_win32_rrThreads2_durango STATIC win32_rrThreads2.c)
target_compile_definitions(
  iggy_reconstructed_win32_rrThreads2_durango
  PRIVATE IGGY_RECONSTRUCT_WIN32_RRTHREADS2_DURANGO=1
)
configure_iggy_reconstructed_target(iggy_reconstructed_win32_rrThreads2_durango c_std_11)

add_library(iggy_reconstructed_win32_rrAtomics_durango STATIC win32_rrAtomics.c)
target_compile_definitions(
  iggy_reconstructed_win32_rrAtomics_durango
  PRIVATE IGGY_RECONSTRUCT_WIN32_RRATOMICS_DURANGO=1
)
configure_iggy_reconstructed_target(iggy_reconstructed_win32_rrAtomics_durango c_std_11)

add_library(iggy_reconstructed_durango_rrCpu_durango STATIC durango_rrCpu.c)
target_compile_definitions(
  iggy_reconstructed_durango_rrCpu_durango
  PRIVATE IGGY_RECONSTRUCT_DURANGO_RRCPU_DURANGO=1
)
configure_iggy_reconstructed_target(iggy_reconstructed_durango_rrCpu_durango c_std_11)

# durango_rrAtomics_x64 -- the durango-only x64 inline-asm atomic compare-exchange
# primitives (asm_x64_cmpxchg64 -> LOCK CMPXCHGQ, asm_x64_cmpxchg128 -> LOCK
# CMPXCHG16B).  2 exports, durango-only, owns no data global and imports nothing
# (a pure leaf).  Reproduced instruction-exact from the retail object.
add_library(iggy_reconstructed_durango_rrAtomics_x64_durango STATIC durango_rrAtomics_x64.c)
target_compile_definitions(
  iggy_reconstructed_durango_rrAtomics_x64_durango
  PRIVATE IGGY_RECONSTRUCT_DURANGO_RRATOMICS_X64_DURANGO=1
)
configure_iggy_reconstructed_target(iggy_reconstructed_durango_rrAtomics_x64_durango c_std_11)

add_library(iggy_reconstructed_win32_rrTime_durango STATIC win32_rrTime.c)
target_compile_definitions(
  iggy_reconstructed_win32_rrTime_durango
  PRIVATE IGGY_RECONSTRUCT_WIN32_RRTIME_DURANGO=1
)
configure_iggy_reconstructed_target(iggy_reconstructed_win32_rrTime_durango c_std_11)

add_library(iggy_reconstructed_radss_xaudio2_durango STATIC radss_xaudio2.c)
target_compile_definitions(
  iggy_reconstructed_radss_xaudio2_durango
  PRIVATE IGGY_RECONSTRUCT_RADSS_XAUDIO2_DURANGO=1
)
configure_iggy_reconstructed_target(iggy_reconstructed_radss_xaudio2_durango c_std_11)

# as3vm_interpreter -- AS3 / AVM2 bytecode interpreter + core VM op layer
# (4-platform; the VM cluster keystone).  Imports fmod / memcpy (the AS3 '%'
# operator + value/scope moves), so guard against libcall re-synthesis with
# -fno-builtin (clang/gcc) or /Oi- (MSVC), matching the sibling as3vm_gc /
# as3vm_class / as3vm_convert / as3vm_property / as3vm_imp_array.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_interpreter_${platform})
  add_library(${target} STATIC as3vm_interpreter.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_INTERPRETER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_verifier -- AVM2 bytecode verifier + translator (4-platform; part of the
# AS3/AVM2 VM cluster).  Two exports on all four; the internal helper count
# varies (8/5/5/4) as vita/orbis fully expand the opcode/translate switch while
# durango/ps3 stay compact behind a &__ImageBase type-byte jump table.  Imports
# memcpy / memset (the flag-array memset + the translated-buffer memcpy) plus the
# verifier.txt debug-dump file I/O (fopen/fclose/fprintf, +fwrite on orbis/ps3);
# guard against libcall re-synthesis with -fno-builtin (clang/gcc) or /Oi-
# (MSVC), matching the sibling as3vm_interpreter / as3vm_property.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_verifier_${platform})
  add_library(${target} STATIC as3vm_verifier.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_VERIFIER_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_abc_decode -- the ABC (AVM2 bytecode) file parser (4-platform; part of
# the AS3/AVM2 VM cluster).  One export (iggy_abc_file) on all four; the internal
# helper count varies (20/3/5/8) as Ghidra split the file-statics differently per
# target.  Owns no data global (the 27 diagnostics are rodata string COMDATs on
# durango, local literals elsewhere).  Imports memset everywhere; memcmp on
# orbis/ps3/vita (durango open-codes the wide-"Vector" compare); no soft-float on
# vita (the double pool is copied as eight raw bytes and every varint is
# open-coded).  Guard against libcall re-synthesis with -fno-builtin (clang/gcc)
# or /Oi- (MSVC), matching the sibling as3vm_verifier / as3vm_interpreter.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_abc_decode_${platform})
  add_library(${target} STATIC as3vm_abc_decode.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_ABC_DECODE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# rrCore: 4-platform, data-only TU (one owned global, zero functions).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_rrCore_${platform})
  add_library(${target} STATIC rrCore.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_RRCORE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm -- AS3 / AVM2 VM top level: the public IggyValue*/IggyValuePath*/
# IggyPlayer* ValueRef API, the VM bootstrap glue, and the arena-backed value
# POOL allocator every sibling VM module imports (4-platform; 49 exports).
# Imports memcpy / memset / setjmp / longjmp (value moves + API guards) plus a
# per-platform UTF8 length loop (durango inlines it; the others lower strlen);
# guard against libcall re-synthesis with -fno-builtin (clang/gcc) or /Oi-
# (MSVC), matching the sibling as3vm_interpreter / as3vm_property.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_${platform})
  add_library(${target} STATIC as3vm.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# zlib -- Iggy's DEFLATE / inflate decompressor (streaming stb_image fork;
# 4-platform, 8 exports).  Owns no exported data global (the DEFLATE tables are
# file-static).  Imports the STBM allocator pair plus per-platform libc: durango
# / vita lower only memset (the open-coded struct copy avoids memcpy), while
# orbis / ps3 additionally lower the decoder struct copy to memcpy.  Guard
# against libcall re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_zlib_${platform})
  add_library(${target} STATIC zlib.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_ZLIB_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_jpeg -- Iggy's JPEG decoder (baseline stb_image fork; 4-platform, 7
# exports).  Owns no exported data global (the bmask / jbias / dezigzag spec
# tables and the YCbCr coefficients are file-static; the durango __FILE__ + __xmm
# COMDATs are rodata artifacts).  Imports the STBM allocator pair, the zlib
# {cur,end} byte reader and the image-storage output pair, plus per-platform
# libc: all four lower only memset (every aggregate copy is open-coded, so no
# memcpy is emitted).  Guard against libcall re-synthesis with -fno-builtin
# (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_jpeg_${platform})
  add_library(${target} STATIC swf_jpeg.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_JPEG_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# dtoa -- Iggy's port of David M. Gay's correctly-rounded float <-> decimal
# string conversion (netlib dtoa.c / strtod; 4-platform, 3 exports).  Owns no
# exported data global (the tens / bigtens / tinytens tables are file-static).
# Imports per-platform libc: durango / ps3 lower free + memcpy + memset; orbis /
# vita additionally pull the CRT rounding-mode query _Fltrounds under
# Honor_FLT_ROUNDS; vita additionally pulls the armv7 soft 32-bit unsigned
# divide (__udivsi3) for the Bigint quotient.  Guard against libcall
# re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_dtoa_${platform})
  add_library(${target} STATIC dtoa.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_DTOA_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_playhead -- Iggy's SWF timeline / frame-navigation unit (gotoAndPlay /
# gotoAndStop, frame seeking, frame labels, creation-placeobject expansion;
# 4-platform, 9 exports).  Owns no exported data global (the durango ??_C@
# rodata COMDATs are the "(iggy/tick)..." marker strings + the __FILE__ path; no
# .data section).  Imports the 14 invariant cross-module externs (2 satisfied:
# rrCompareInsensitiveUTF16toUTF16, rrwcslen; 12 sibling swf_play / iggy_main
# callbacks + data globals) plus per-platform libc: durango / orbis / ps3 lower
# memset + setjmp; vita additionally pulls the libgcc signed-modulo helper
# __modsi3 for the `int % int` sprite-loop framescript wrap (ARM has no hardware
# idiv).  Guard against libcall re-synthesis with -fno-builtin (clang/gcc) or
# /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_playhead_${platform})
  add_library(${target} STATIC swf_playhead.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_PLAYHEAD_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_as3_bitmap_data -- Iggy's AS3 / AVM2 flash.display.BitmapData class
# (__construct / __finalize / clone / get_width / get_height / get_transparent
# plus 28 "unsupported" exception stubs; 4-platform, 34 exports).  Owns no
# exported data global (the durango ??_C@ rodata COMDATs are the "dd?bu"
# parse-format literal + the __FILE__ path, local on orbis / ps3 / vita).
# Imports the six invariant cross-module externs (as3vm_component_parse_-
# arguments_GC, as3vm_exception_GC, as3vm_make_object_no_constructor_GC,
# as3vm_truefalse_storage [DATA], iggy_free_alloc, iggy_malloc_fileline) plus
# libc memcpy for clone's pixel-buffer copy.  Guard against libcall
# re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_as3_bitmap_data_${platform})
  add_library(${target} STATIC swf_as3_bitmap_data.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_AS3_BITMAP_DATA_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_as3_misc -- Iggy's grab-bag of AS3 / AVM2 builtin classes (ApplicationDomain,
# ByteArray, Capabilities, IggyFunctions.translate, Mouse, Security, Sound,
# SoundChannel, SoundMixer, SoundTransform, System).  70 exports on every
# platform (12 pure 0x74 stubs + 58 real bodies carrying 7 bad-args 0x78 raises,
# one conditional 0x74 and one 0x72); durango additionally recovers two file
# statics (set_pan / swf_free_voice) so its source_functions == 72.  Owns no
# exported data global -- the durango ??_C@ COMDATs are the per-platform
# Capabilities constants + parse-format literals + three __real@ floats, MSVC
# read-only artifacts (local on orbis / ps3 / vita).  Imports the 21 invariant
# cross-module externs plus per-platform libm/libc (set_pan's sqrt on
# durango / vita, inlined on orbis / ps3; a struct-copy memcpy on vita).  Guard
# against sqrt / memcpy libcall re-synthesis with -fno-builtin (clang/gcc) or
# /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_as3_misc_${platform})
  add_library(${target} STATIC swf_as3_misc.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_AS3_MISC_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# as3vm_imp_misc -- Iggy's assorted AS3 / AVM2 builtin classes, dominated by the
# Date class (Boolean, Class, Date, Error, ExternalInterface, Function, IME,
# MethodClosure, Namespace, Number, Object, the global methods parseInt /
# parseFloat / isNaN / isFinite / getTimer / trace / getDefinitionByName / ...,
# plus the two IggyPlayerCall{Function,Method}RS_core call-machinery entry
# points).  133 exports on every platform (13 pure 0x74 stubs + 120 real bodies
# carrying the 1x0x75 / 1x0x76 / 31x0x78 error tails); durango recovers the most
# file statics so its source_functions == 143 (vs 137 / 136 / 136).  Owns no
# exported data global -- the durango ??_C@ / __real@ / __xmm@ COMDATs are MSVC
# read-only artifacts (local on orbis / ps3 / vita), and the boolean / NaN /
# infinity sentinels are DATA imports from as3vm_interpreter.  Imports the 55
# invariant cross-module externs plus per-platform libc (memcpy + setjmp on all
# four; vita additionally lowers abs / strcpy).  Guard against memcpy / setjmp /
# abs / strcpy libcall re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_as3vm_imp_misc_${platform})
  add_library(${target} STATIC as3vm_imp_misc.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_AS3VM_IMP_MISC_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# iggy_api_functions -- Iggy's PUBLIC C API surface (the IggyPlayer* /
# IggyLibrary* / IggyGeneric* entry points a host application calls; 4-platform,
# 65 exports on every target).  The export count is the load-bearing invariant;
# the raw source_functions count diverges (65 / 68 / 68 / 69) only in the
# file-static explorer / resource-install helpers durango inlines.  Owns EXACTLY
# two exported data globals -- iggy_max_visible_chars (.data, 2000) and
# iggy_char_buffer (common/bss scratch pointer) -- both written by
# IggySetFontCachingCalculationBuffer; every other durango external data symbol
# is an MSVC ??_C@ string / __real@ float COMDAT artifact.  Imports the 39
# invariant cross-module externs (rrAtomicCmpXchg32, rrUTF8toUTF16 / rrUTF16toUTF8,
# as3vm_interpreter_initialize, IggyPlayerGotoFrameRS_core [DONE] + 15 unbuilt
# swf_play *_core targets, the iggy_main / draw / audio callbacks and the five
# data globals) plus the libc setjmp used by the three exception guards.  Guard
# against setjmp libcall re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_iggy_api_functions_${platform})
  add_library(${target} STATIC iggy_api_functions.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_IGGY_API_FUNCTIONS_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_as3_textfield -- Iggy's AS3 / AVM2 text-and-font binding layer
# (flash.text.Font / TextField / TextFormat / TextLineMetrics plus the
# as3vm_make_font_GC / as3vm_make_textformat_GC factories and the shared
# as3vm_textfield_bool_getter / _bool_setter accessors).  126 exports on every
# platform (8 pure 0x74 stubs + 118 real bodies carrying 61 bad-args 0x78 tails,
# one conditional 0x74 and one 0x78); durango additionally recovers three file
# statics (get_text_range_GC, merge_format, split_chunk) so its source_functions
# == 129 vs 127.  Owns no exported data global -- the durango ??_C@ / __real@
# COMDATs are MSVC read-only artifacts (local on orbis / ps3 / vita), and the
# boolean / NaN / null / true-false sentinels are DATA imports from
# as3vm_interpreter.  ps3 is 32-bit big-endian; vita is 32-bit hard-float (no
# soft-float helper).  Imports the 30 invariant cross-module externs plus
# per-platform libm/libc (sqrt in get_width/get_height + ceil in get_textHeight
# on durango/vita, inlined on orbis/ps3 which lowers ceil to ceilf; memcpy /
# memset struct + text copies).  Guard against libcall re-synthesis with
# -fno-builtin (clang/gcc) or /Oi- (MSVC), matching the sibling swf_as3_misc.
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_as3_textfield_${platform})
  add_library(${target} STATIC swf_as3_textfield.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_AS3_TEXTFIELD_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# iggy_main -- Iggy's central init / runtime / error / translation hub (the
# runtime keystone).  Exports EXACTLY 36 entry points and OWNS 17 data globals on
# all four platforms; the source-function count diverges (durango 57 / orbis 46 /
# ps3 44 / vita 46 -- durango inlined many file-static helpers the RISC
# toolchains kept separate) while the 36-export ABI stays invariant.  Guard the
# memcpy/memset/setjmp/qsort and the per-platform strcpy/memcmp libc lowering
# against builtin re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_iggy_main_${platform})
  add_library(${target} STATIC iggy_main.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_IGGY_MAIN_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_as3vm_flash_events -- Iggy's AVM2 flash.events binding layer (Event /
# EventDispatcher / FocusEvent / KeyboardEvent / MouseEvent / TextEvent /
# TimerEvent and siblings).  118 exports on every platform, invariant ABI; the
# per-platform source_functions diverges (durango 123 / orbis 121 / ps3 120 /
# vita 122) because the RISC toolchains keep more file-static dispatch helpers
# separate.  Owns no exported data global -- the durango R symbols are all
# ??_C@ MSVC string COMDATs, and ps3's D symbols are .opd function descriptors.
# The three-phase capture/target/bubble dispatch machinery and the do_*_event_GC
# entry points are reconstructed from the durango raw + object and the ps3/vita
# 32-bit layouts; the genuinely-unbuilt text/display engine is reached only
# through the frozen 32-symbol cross-module import set.  ps3 is 32-bit
# big-endian (Event flag / phase writes are byte-wise); vita is 32-bit hard-
# float with no soft-float helper.  Guard the memcpy / memset against builtin
# re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_as3vm_flash_events_${platform})
  add_library(${target} STATIC swf_as3vm_flash_events.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_EVENTS_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_as3vm -- Iggy's AS3<->display glue: the class registry/map, predefined-
# class + global initialization, ABC-state-from-SWF building, and scene-list
# building.  EXACTLY 10 exports on every platform; the per-platform
# source_functions diverges (durango 29 / orbis 23 / ps3 19 / vita 29 -- the RISC
# toolchains inline different file-static registration helpers) while the 10-
# export ABI stays invariant.  Owns no exported data global (durango's ~1359 R
# symbols are all ??_C@ / __real@ MSVC COMDAT artifacts; ps3's D are .opd
# descriptors).  The heavy init/ABC bodies reference ~1401 invariant cross-module
# imports (nearly every as3vm_*__construct / __finalize plus the allocator) and
# are width-gated field-for-field for the 32-bit ps3/vita targets; ps3 is 32-bit
# big-endian.  Guard the memcmp / memcpy / memset (and per-platform strcmp)
# against builtin re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_as3vm_${platform})
  add_library(${target} STATIC swf_as3vm.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_AS3VM_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_decode -- Iggy's SWF/.iggy tag decoder + library/export bookkeeping.
# EXACTLY 9 exports on every platform; per-platform source_functions diverges
# (durango 69 / orbis 41 / ps3 48 / vita 57 -- the RISC toolchains inline
# differently) while the 9-export ABI stays invariant.  OWNS 4 data globals
# (iggy_libraries 0x100/0x80, iggy_load_imports 0x600/0x300,
# iggy_load_processing_num_libraries 0x4, last_abc 0xc8/0x78 -- BSS, sizes halve
# 64->32-bit) plus a file-static id bitmask.  The swf_decode_contents tag
# dispatch is reconstructed to match the retail MSVC jump table (per-tag handler
# + version variant) with the full DefineShape/Font/Text/Button/MorphShape/
# DefineFontInfo/DoABC/ExportAssets/SymbolClass/ImportAssets2 handler bodies;
# every deep-body struct/field offset is width-gated field-for-field for the
# 32-bit ps3/vita targets (ps3 is 32-bit big-endian).  References the 34
# invariant cross-module imports; guard memcpy/memset/qsort (+abs on vita)
# against builtin re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_decode_${platform})
  add_library(${target} STATIC swf_decode.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_DECODE_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_play -- Iggy's movie playback + display-list execution runtime (the
# IggyPlayer tick/play/pause/focus/clipboard, advance_movie, do_placeobject,
# play_framescripts, sprite/textfield/button/shape create+destroy, hit-testing,
# input dispatch, audio/voice).  EXACTLY 68 exports on every platform; per-
# platform source_functions diverges (durango 112 / orbis 90 / ps3 90 / vita 93)
# while the 68-export ABI stays invariant.  OWNS 1 data global
# (iggy_double_click_time, a 4-byte float defaulting to 0.5 -- big-endian on
# ps3).  Every deep-engine struct/field offset is width-gated field-for-field
# for the 32-bit ps3/vita targets (ps3 is 32-bit big-endian).  References the 72
# invariant cross-module imports (nearly the whole as3vm/iggy movie+render
# surface plus swf_decode's iggy_libraries); guard memset/setjmp against builtin
# re-synthesis with -fno-builtin (clang/gcc) or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_play_${platform})
  add_library(${target} STATIC swf_play.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_PLAY_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()

# swf_as3vm_flash_display -- Iggy's AVM2 flash.display + flash.filters +
# flash.geom class bindings (the LARGEST unit: DisplayObject/InteractiveObject/
# Container/Sprite/MovieClip/Stage/Shape/SimpleButton/Bitmap, the filter family
# Blur/Glow/Bevel/DropShadow/Gradient*/ColorMatrix/BitmapFilter, Graphics,
# Matrix/Point/Rectangle/ColorTransform/Transform/Matrix3D/Vector3D/
# PerspectiveProjection, and the IggyTextureSubstitution* C API).  EXACTLY 537
# exports on every platform; per-platform source_functions diverges (durango 580
# / orbis 553 / ps3 561 / vita 563) while the 537-export ABI stays invariant.
# OWNS 1 data global (iggy_direct_texture_pool_mutex, 0x80 BSS) plus file-static
# texture-pool state; every deep struct/field offset is width-gated field-for-
# field for the 32-bit ps3/vita targets (ps3 is 32-bit big-endian).  References
# the 73 invariant cross-module imports; the value-cell sentinels and libm
# (acos/atan/tan/sin/cos/... + rrMutexLock/Unlock) are DATA/PLATFORM imports.
# Guard memcpy/memset against builtin re-synthesis with -fno-builtin (clang/gcc)
# or /Oi- (MSVC).
foreach(platform IN ITEMS durango orbis ps3 vita)
  string(TOUPPER ${platform} platform_upper)
  set(target iggy_reconstructed_swf_as3vm_flash_display_${platform})
  add_library(${target} STATIC swf_as3vm_flash_display.c)
  target_compile_definitions(
    ${target}
    PRIVATE IGGY_RECONSTRUCT_SWF_AS3VM_FLASH_DISPLAY_${platform_upper}
  )
  configure_iggy_reconstructed_target(${target} c_std_11)
  if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -fno-builtin)
  elseif(MSVC)
    target_compile_options(${target} PRIVATE /Oi-)
  endif()
endforeach()
