<commit_before>#
# CEN64: Cycle-Accurate Nintendo 64 Simulator.
# Copyright (C) 2014, <NAME>.
#
# This file is subject to the terms and conditions defined in
# 'LICENSE', which is part of this source code package.
#

cmake_minimum_required(VERSION 2.8)
project(cen64)

find_package(OpenGL REQUIRED)
find_package(Threads REQUIRED)

# If using GCC, configure it accordingly.
if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99")
  set(CEN64_DEV_FLAG "-DCEN64_DEVFEATURES")

  # Include architecture-specify machinery.
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
    OUTPUT_VARIABLE GCC_MACHINE)

  string(REGEX MATCH "([a-zA-Z0-9])+" GCC_MACHINE ${GCC_MACHINE})

  if (${GCC_MACHINE} MATCHES "x86.*" OR ${GCC_MACHINE} MATCHES "i.86.*")
    set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
    set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX Native)

    if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "Native")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
    endif ()

    if (${GCC_MACHINE} MATCHES "i.86.*")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffixed-xmm5 -ffixed-xmm6 -ffixed-xmm7")
    else ()
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffixed-xmm13 -ffixed-xmm14 -ffixed-xmm15")
    endif()

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maccumulate-outgoing-args")

    set(CEN64_ARCH_DIR "x86_64")
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/x86_64)
  endif (${GCC_MACHINE} MATCHES "x86.*" OR ${GCC_MACHINE} MATCHES "i.86.*")

  if (${GCC_MACHINE} STREQUAL "arm")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard -mfpu=neon")

    include_directories(${PROJECT_SOURCE_DIR}/arch/arm)
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/arm)
  endif (${GCC_MACHINE} STREQUAL "arm")

  # Set architecture-independent flags.
  set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -g3 -O0")
  set(CMAKE_C_FLAGS_MINSIZEREL "-Os -ffast-math -DNDEBUG -s -fmerge-all-constants")
  set(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG -s -fmerge-all-constants")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og")
  set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

  # Enable link time optimization on recent versions.
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
    OUTPUT_VARIABLE GCC_VERSION)

  if (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)
    set(GCC_FLTO_FLAGS "-flto -fdata-sections -ffunction-sections")
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GCC_FLTO_FLAGS}")
    set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${GCC_FLTO_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE} "-Wl,--gc-sections")
    set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} "-Wl,--gc-sections")
  endif (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)

  # Enable "unsafe" loop optimizations on recent versions.
  if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -funsafe-loop-optimizations")
    set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -funsafe-loop-optimizations")
  endif (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)

  # Check for undefined behaviour when debugging.
  if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined")
  endif (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)

  # Use fat LTO objects.
  if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffat-lto-objects")
  endif (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)

# If using Clang, configure it accordingly.
if (${CMAKE_C_COMPILER_ID} MATCHES Clang)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99")
  set(CEN64_DEV_FLAG "-DCEN64_DEVFEATURES")

  # Include architecture-specify machinery.
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
    OUTPUT_VARIABLE CLANG_MACHINE)

  string(REGEX MATCH "([a-zA-Z0-9])+" CLANG_MACHINE ${CLANG_MACHINE})

  if (${CLANG_MACHINE} MATCHES "x86.*" OR ${CLANG_MACHINE} MATCHES "i.86.*")
    set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
    set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX Native)

    if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "Native")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
    endif ()

    set(CEN64_ARCH_DIR "x86_64")
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/x86_64)
  endif (${CLANG_MACHINE} MATCHES "x86.*" OR ${CLANG_MACHINE} MATCHES "i.86.*")

  if (${CLANG_MACHINE} STREQUAL "arm")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard -mfpu=neon")

    set(CEN64_ARCH_DIR "arm")
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/arm)
  endif (${CLANG_MACHINE} STREQUAL "arm")

  # Set architecture-independent flags.
  set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -g3 -O0 -fsanitize=undefined")
  set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
  set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og")
  set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s")
  set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-s")

  set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
endif (${CMAKE_C_COMPILER_ID} MATCHES Clang)

# If using ICC, configure it accordingly.
if (${CMAKE_C_COMPILER_ID} MATCHES Intel)
  set(CMAKE_C_FLAGS "-Wall -Wno-unused-parameter -std=c99")
  set(CEN64_DEV_FLAG "-DCEN64_DEVFEATURES")

  set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
  set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX Native)

    if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSE2")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSE3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSSE3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSE4.1")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xAVX")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "Native")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xHost")
    endif ()

  set(CEN64_ARCH_DIR "x86_64")
  include_directories(${PROJECT_SOURCE_DIR}/os/unix/x86_64)

  # Set architecture-independent flags.
  set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
  set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG -ipo -ffunction-sections -fdata-sections")
  set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG -ipo -ffunction-sections -fdata-sections")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og")
  set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
endif (${CMAKE_C_COMPILER_ID} MATCHES Intel)

# If using MSVC, configure it accordingly.
if (MSVC)
  set(CEN64_DEV_FLAG "/DCEN64_DEVFEATURES")

  set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
  set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX)

  if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__ /D__SSSE3__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__ /D__SSSE3__ /D__SSE4_1__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__ /D__SSSE3__ /D__SSE4_1__ /arch:AVX")
  endif ()

  enable_language(ASM_MASM) # Are you kidding me? Really?
  file(GLOB ASM_SOURCES ${PROJECT_SOURCE_DIR}/os/windows/x86_64/fpu/*.asm)

  set(CEN64_ARCH_DIR "x86_64")
  include_directories(${PROJECT_SOURCE_DIR}/os/windows/x86_64)
endif (MSVC)

# Print out MMIO register accesses?
option(DEBUG_MMIO_REGISTER_ACCESS "Print message on each MMIO register access?" OFF)

# Use VR4300's busy-wait-detection feature?
option(VR4300_BUSY_WAIT_DETECTION "Detect and special case VR4300 busy wait loops?" OFF)

# Glob all the files together.
include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/arch/${CEN64_ARCH_DIR})

file(GLOB AI_SOURCES ${PROJECT_SOURCE_DIR}/ai/*.c)
file(GLOB BUS_SOURCES ${PROJECT_SOURCE_DIR}/bus/*.c)
file(GLOB COMMON_SOURCES ${PROJECT_SOURCE_DIR}/common/*.c)
file(GLOB OS_COMMON_SOURCES ${PROJECT_SOURCE_DIR}/os/*.c)<commit_msg>Fix SSSE3 builds/regex mistake in CMakeLists.<commit_after>#
# CEN64: Cycle-Accurate Nintendo 64 Simulator.
# Copyright (C) 2014, <NAME>.
#
# This file is subject to the terms and conditions defined in
# 'LICENSE', which is part of this source code package.
#

cmake_minimum_required(VERSION 2.8)
project(cen64)

find_package(OpenGL REQUIRED)
find_package(Threads REQUIRED)

# If using GCC, configure it accordingly.
if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99")
  set(CEN64_DEV_FLAG "-DCEN64_DEVFEATURES")

  # Include architecture-specify machinery.
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
    OUTPUT_VARIABLE GCC_MACHINE)

  string(REGEX MATCH "([a-zA-Z0-9])+" GCC_MACHINE ${GCC_MACHINE})

  if (${GCC_MACHINE} MATCHES "x86.*" OR ${GCC_MACHINE} MATCHES "i.86.*")
    set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
    set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX Native)

    if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "Native")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
    endif ()

    if (${GCC_MACHINE} MATCHES "i.86.*")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffixed-xmm5 -ffixed-xmm6 -ffixed-xmm7")
    else ()
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffixed-xmm13 -ffixed-xmm14 -ffixed-xmm15")
    endif()

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maccumulate-outgoing-args")

    set(CEN64_ARCH_DIR "x86_64")
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/x86_64)
  endif (${GCC_MACHINE} MATCHES "x86.*" OR ${GCC_MACHINE} MATCHES "i.86.*")

  if (${GCC_MACHINE} STREQUAL "arm")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard -mfpu=neon")

    include_directories(${PROJECT_SOURCE_DIR}/arch/arm)
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/arm)
  endif (${GCC_MACHINE} STREQUAL "arm")

  # Set architecture-independent flags.
  set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -g3 -O0")
  set(CMAKE_C_FLAGS_MINSIZEREL "-Os -ffast-math -DNDEBUG -s -fmerge-all-constants")
  set(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG -s -fmerge-all-constants")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og")
  set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

  # Enable link time optimization on recent versions.
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
    OUTPUT_VARIABLE GCC_VERSION)

  if (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)
    set(GCC_FLTO_FLAGS "-flto -fdata-sections -ffunction-sections")
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GCC_FLTO_FLAGS}")
    set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${GCC_FLTO_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE} "-Wl,--gc-sections")
    set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} "-Wl,--gc-sections")
  endif (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)

  # Enable "unsafe" loop optimizations on recent versions.
  if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -funsafe-loop-optimizations")
    set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -funsafe-loop-optimizations")
  endif (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)

  # Check for undefined behaviour when debugging.
  if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined")
  endif (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)

  # Use fat LTO objects.
  if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffat-lto-objects")
  endif (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)

# If using Clang, configure it accordingly.
if (${CMAKE_C_COMPILER_ID} MATCHES Clang)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99")
  set(CEN64_DEV_FLAG "-DCEN64_DEVFEATURES")

  # Include architecture-specify machinery.
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
    OUTPUT_VARIABLE CLANG_MACHINE)

  string(REGEX MATCH "([a-zA-Z0-9])+" CLANG_MACHINE ${CLANG_MACHINE})

  if (${CLANG_MACHINE} MATCHES "x86.*" OR ${CLANG_MACHINE} MATCHES "i.86.*")
    set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
    set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX Native)

    if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "Native")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
    endif ()

    set(CEN64_ARCH_DIR "x86_64")
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/x86_64)
  endif (${CLANG_MACHINE} MATCHES "x86.*" OR ${CLANG_MACHINE} MATCHES "i.86.*")

  if (${CLANG_MACHINE} STREQUAL "arm")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard -mfpu=neon")

    set(CEN64_ARCH_DIR "arm")
    include_directories(${PROJECT_SOURCE_DIR}/os/unix/arm)
  endif (${CLANG_MACHINE} STREQUAL "arm")

  # Set architecture-independent flags.
  set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -g3 -O0 -fsanitize=undefined")
  set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
  set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og")
  set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s")
  set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-s")

  set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
endif (${CMAKE_C_COMPILER_ID} MATCHES Clang)

# If using ICC, configure it accordingly.
if (${CMAKE_C_COMPILER_ID} MATCHES Intel)
  set(CMAKE_C_FLAGS "-Wall -Wno-unused-parameter -std=c99")
  set(CEN64_DEV_FLAG "-DCEN64_DEVFEATURES")

  set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
  set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX Native)

    if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSE2")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSSE3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSE3")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xSSE4.1")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xAVX")
    elseif (${CEN64_ARCH_SUPPORT} MATCHES "Native")
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xHost")
    endif ()

  set(CEN64_ARCH_DIR "x86_64")
  include_directories(${PROJECT_SOURCE_DIR}/os/unix/x86_64)

  # Set architecture-independent flags.
  set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
  set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG -ipo -ffunction-sections -fdata-sections")
  set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG -ipo -ffunction-sections -fdata-sections")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og")
  set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
endif (${CMAKE_C_COMPILER_ID} MATCHES Intel)

# If using MSVC, configure it accordingly.
if (MSVC)
  set(CEN64_DEV_FLAG "/DCEN64_DEVFEATURES")

  set(CEN64_ARCH_SUPPORT "SSE2" CACHE STRING "Architectural extension(s) to use")
  set_property(CACHE CEN64_ARCH_SUPPORT PROPERTY STRINGS SSE2 SSE3 SSSE3 SSE4.1 AVX)

  if (${CEN64_ARCH_SUPPORT} MATCHES "SSE2")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSSE3")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__ /D__SSSE3__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE3")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "SSE4.1")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__ /D__SSSE3__ /D__SSE4_1__")
  elseif (${CEN64_ARCH_SUPPORT} MATCHES "AVX")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE2__ /D__SSE3__ /D__SSSE3__ /D__SSE4_1__ /arch:AVX")
  endif ()

  enable_language(ASM_MASM) # Are you kidding me? Really?
  file(GLOB ASM_SOURCES ${PROJECT_SOURCE_DIR}/os/windows/x86_64/fpu/*.asm)

  set(CEN64_ARCH_DIR "x86_64")
  include_directories(${PROJECT_SOURCE_DIR}/os/windows/x86_64)
endif (MSVC)

# Print out MMIO register accesses?
option(DEBUG_MMIO_REGISTER_ACCESS "Print message on each MMIO register access?" OFF)

# Use VR4300's busy-wait-detection feature?
option(VR4300_BUSY_WAIT_DETECTION "Detect and special case VR4300 busy wait loops?" OFF)

# Glob all the files together.
include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/arch/${CEN64_ARCH_DIR})

file(GLOB AI_SOURCES ${PROJECT_SOURCE_DIR}/ai/*.c)
file(GLOB BUS_SOURCES ${PROJECT_SOURCE_DIR}/bus/*.c)
file(GLOB COMMON_SOURCES ${PROJECT_SOURCE_DIR}/common/*.c)
file(GLOB OS_COMMON_SOURCES ${PROJECT_SOURCE_DIR}/os/*.c)
{'fraction_non_alphanumeric': 0.12295584627964024, 'fraction_numerical': 0.031020032706459526, 'mean_word_length': 5.3576998050682265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3164330', 'n_tokens_mistral': 8865, 'n_tokens_neox': 8078, 'n_words': 1442}