if(WIN32)
  add_definitions(-DUNICODE=1)
endif (WIN32)

if(MSVC)
  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/EHa->)   # Native AOT runtime does not use C++ exception handling
  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/EHs->)

  # CFG runtime checks in C++ code are unnecessary overhead unless Native AOT compiler produces CFG compliant code as well
  # and CFG is enabled in the linker
  if(CMAKE_CXX_FLAGS MATCHES "/guard:cf")
    string(REPLACE "/guard:cf" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  endif()
  if(CMAKE_C_FLAGS MATCHES "/guard:cf")
    string(REPLACE "/guard:cf" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  endif()

  # The code generated by the Native AOT compiler doesn't work with Link Time Code Generation
  add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/GL->)

  # Sets the options that create the fastest code in the majority of cases
  add_compile_options($<$<AND:$<COMPILE_LANGUAGE:C,CXX>,$<CONFIG:Release>>:/O2>)
endif (MSVC)

if(CLR_CMAKE_HOST_UNIX)
  add_compile_options(-fno-exceptions)    # Native AOT runtime doesn't use C++ exception handling
  add_compile_options(-nostdlib)

  if(CLR_CMAKE_TARGET_APPLE)
    add_definitions(-D_XOPEN_SOURCE)
    add_definitions(-DFEATURE_OBJCMARSHAL)
  endif(CLR_CMAKE_TARGET_APPLE)

  if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
    # Allow 16 byte compare-exchange
    add_compile_options(-mcx16)
  endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
endif (CLR_CMAKE_HOST_UNIX)

if(CLR_CMAKE_TARGET_LINUX_MUSL)
    # Fix up the main thread stack size for MUSL to more reasonable size.
    # TODO: https://github.com/dotnet/runtimelab/issues/791
    add_definitions(-DENSURE_PRIMARY_STACK_SIZE)
endif()

if(CLR_CMAKE_TARGET_ANDROID)
    add_definitions(-DFEATURE_EMULATED_TLS)
endif()

add_subdirectory(Bootstrap)
add_subdirectory(Runtime)
