Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

1.8 KB
Raw Blame
cmake_minimum_required(VERSION 3.20)  # script mode: enables IN_LIST (CMP0057) on older CMake
# Fail unless every laya-cpp translation unit was compiled with every flag in REQUIRED_FLAGS
# ("|" separated). Reads the compile_commands.json CMake wrote.
foreach(var COMPILE_COMMANDS SOURCE_DIR REQUIRED_FLAGS)
  if(NOT DEFINED ${var})
    message(FATAL_ERROR "check_compile_flags: ${var} is not set")
  endif()
endforeach()
file(READ "${COMPILE_COMMANDS}" json)
string(JSON count LENGTH "${json}")
string(REPLACE "|" ";" required "${REQUIRED_FLAGS}")
set(checked 0)
math(EXPR last "${count} - 1")
foreach(i RANGE ${last})
  string(JSON file GET "${json}" ${i} file)
  # Only our own sources; fetched code (googletest) lives under the build tree.
  if(NOT file MATCHES "^${SOURCE_DIR}/(src|tests)/")
    continue()
  endif()
  string(JSON command GET "${json}" ${i} command)
  separate_arguments(args UNIX_COMMAND "${command}")
  foreach(flag IN LISTS required)
    if(NOT flag IN_LIST args)
      message(FATAL_ERROR "${file} was compiled without ${flag}:\n${command}")
    endif()
  endforeach()
  # A later flag overrides an earlier one, so a conflicting flag anywhere fails, whoever added it
  # (target options, CMAKE_CXX_FLAGS or the environment).
  foreach(arg IN LISTS args)
    if(arg MATCHES "^(-ffast-math|-Ofast|-ffp-contract=(on|fast)|-funsafe-math-optimizations|-fassociative-math|-ffinite-math-only|-freciprocal-math|-fno-signed-zeros)$")
      message(FATAL_ERROR "${file} was compiled with ${arg}, which overrides the required flags:\n${command}")
    endif()
  endforeach()
  math(EXPR checked "${checked} + 1")
endforeach()
if(checked LESS 2)
  message(FATAL_ERROR "expected at least 2 laya-cpp translation units, found ${checked}")
endif()
message(STATUS "compile flags ok on ${checked} translation units")