<commit_before>cmake_minimum_required(VERSION 2.8)
project(kernel)

find_package(qibuild)

qi_sanitize_compile_flags(HIDDEN_SYMBOLS)


#find python
find_program(_python_executable
    NAMES python2 python python.exe
    NO_CMAKE_FIND_ROOT_PATH)
  if (NOT _python_executable)
    qi_error("needs python executable in PATH")
  endif()


add_subdirectory(sdk-remote)

qi_create_config_h(KCONFIG_H
   ${CMAKE_CURRENT_SOURCE_DIR}/include/urbi/kernel/config.h.in
   urbi/kernel/config.h
)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sdk-remote/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sdk-remote/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sdk-remote/libport/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/sdk-remote/libport/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/urbi)

add_definitions(-DLIBPORT_LIBSFX="")
add_definitions(-DLIBPORT_LIBDIRNAME="lib")
add_definitions(-D_USE_MATH_DEFINES)
#add_definitions(/w)


if (HAVE_CUSTOM_BISON)

MESSAGE("Using bison")

#invoke flex on utoken.l
qi_generate_src(
  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw
  SRC src/parser/utoken.l
  COMMAND flex -+ -o${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw ${CMAKE_CURRENT_SOURCE_DIR}/src/parser/utoken.l
)

#fix flex output
qi_generate_src(
  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc
  SRC ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw
  COMMAND ${_python_executable} ${CMAKE_CURRENT_SOURCE_DIR}/dev/fix-utoken.py ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc
)

# You need a bison patched by gostai, in the urbi-sdk/bison repository.
set(BISON_OPTS
  --defines --report=all -xml
)
set(BISON
  bison
)

qi_generate_src(
  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/ugrammar.cc
  SRC src/parser/ugrammar.y
  COMMAND ${BISON} ${BISON_OPTS} ${CMAKE_CURRENT_SOURCE_DIR}/src/parser/ugrammar.y -o  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/ugrammar.cc
)

function(astgen target command)
 qi_generate_src(
   ${CMAKE_CURRENT_SOURCE_DIR}/${target}
  SRC src/ast/ast.yml
  COMMAND ${_python_executable} ${CMAKE_CURRENT_SOURCE_DIR}/dev/ast-${command}-gen ${CMAKE_CURRENT_SOURCE_DIR}/src/ast < ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/ast.yml
 )
endfunction()


astgen(src/ast/all.cc all)
astgen(src/ast/cloner.cc cloner)
astgen(src/ast/transformer.cc transformer)
astgen(src/ast/fwd.hh fwd)
astgen(src/ast/default-visitor.hh default-visitor)
astgen(src/ast/visitor.hh visitor)
astgen(src/ast/pretty-printer.cc pretty-printer)
astgen(src/ast/dot-printer.cc dot-printer)
astgen(src/ast/serializer.hh serializer)
astgen(src/ast/implicit.hh nodes)

set(GENERATED_SRC
  src/ast/visitor.hh
  src/ast/implicit.hh
  src/ast/all.cc
  src/ast/cloner.hxx
  src/ast/cloner.cc
  src/ast/dot-printer.cc
  src/ast/pretty-printer.cc
  src/ast/transformer.cc
  src/ast/default-visitor.hh
  src/ast/fwd.hh
)

else()
  MESSAGE("No bison specified, using pregenerated grammar and AST files.")
  qi_generate_src(
    ${CMAKE_CURRENT_BINARY_DIR}/src/parser/ugrammar.cc
    ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc
    SRC src/parser/ugrammar.y src/ast/ast.yml
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src/parser/pregenerated/ ${CMAKE_CURRENT_BINARY_DIR}/src/parser/
  )

  # HACK, to avoid a qi_generate_src rule for all 100 files,
  # merge the ccs into one merged.cc and declare arule just for it
  qi_generate_src(
    ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/merged.cc
    SRC src/ast/ast.yml
    COMMAND ${CMAKE_COMMAND} -E copy_directory   ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/pregenerated/ ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/
  )
  set(GENERATED_SRC
    src/ast/merged.cc
  )

endif(HAVE_CUSTOM_BISON)


set(UOBJECT_PLUGIN_SRC
${CMAKE_CURRENT_BINARY_DIR}/include/urbi/kernel/config.h
${GENERATED_SRC}
src/ast/analyzer.cc
src/ast/analyzer.hh
src/ast/catches-type.cc
src/ast/catches-type.hh
src/ast/dot-print.cc
src/ast/dot-print.hh
src/ast/event-match.cc<commit_msg>cmake: Fix dependency of pregenerated grammar copy rule.<commit_after>cmake_minimum_required(VERSION 2.8)
project(kernel)

find_package(qibuild)

qi_sanitize_compile_flags(HIDDEN_SYMBOLS)


#find python
find_program(_python_executable
    NAMES python2 python python.exe
    NO_CMAKE_FIND_ROOT_PATH)
  if (NOT _python_executable)
    qi_error("needs python executable in PATH")
  endif()


add_subdirectory(sdk-remote)

qi_create_config_h(KCONFIG_H
   ${CMAKE_CURRENT_SOURCE_DIR}/include/urbi/kernel/config.h.in
   urbi/kernel/config.h
)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sdk-remote/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sdk-remote/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sdk-remote/libport/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/sdk-remote/libport/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/urbi)

add_definitions(-DLIBPORT_LIBSFX="")
add_definitions(-DLIBPORT_LIBDIRNAME="lib")
add_definitions(-D_USE_MATH_DEFINES)
#add_definitions(/w)


if (HAVE_CUSTOM_BISON)

MESSAGE("Using bison")

#invoke flex on utoken.l
qi_generate_src(
  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw
  SRC src/parser/utoken.l
  COMMAND flex -+ -o${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw ${CMAKE_CURRENT_SOURCE_DIR}/src/parser/utoken.l
)

#fix flex output
qi_generate_src(
  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc
  SRC ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw
  COMMAND ${_python_executable} ${CMAKE_CURRENT_SOURCE_DIR}/dev/fix-utoken.py ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc.raw ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc
)

# You need a bison patched by gostai, in the urbi-sdk/bison repository.
set(BISON_OPTS
  --defines --report=all -xml
)
set(BISON
  bison
)

qi_generate_src(
  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/ugrammar.cc
  SRC src/parser/ugrammar.y
  COMMAND ${BISON} ${BISON_OPTS} ${CMAKE_CURRENT_SOURCE_DIR}/src/parser/ugrammar.y -o  ${CMAKE_CURRENT_BINARY_DIR}/src/parser/ugrammar.cc
)

function(astgen target command)
 qi_generate_src(
   ${CMAKE_CURRENT_SOURCE_DIR}/${target}
  SRC src/ast/ast.yml
  COMMAND ${_python_executable} ${CMAKE_CURRENT_SOURCE_DIR}/dev/ast-${command}-gen ${CMAKE_CURRENT_SOURCE_DIR}/src/ast < ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/ast.yml
 )
endfunction()


astgen(src/ast/all.cc all)
astgen(src/ast/cloner.cc cloner)
astgen(src/ast/transformer.cc transformer)
astgen(src/ast/fwd.hh fwd)
astgen(src/ast/default-visitor.hh default-visitor)
astgen(src/ast/visitor.hh visitor)
astgen(src/ast/pretty-printer.cc pretty-printer)
astgen(src/ast/dot-printer.cc dot-printer)
astgen(src/ast/serializer.hh serializer)
astgen(src/ast/implicit.hh nodes)

set(GENERATED_SRC
  src/ast/visitor.hh
  src/ast/implicit.hh
  src/ast/all.cc
  src/ast/cloner.hxx
  src/ast/cloner.cc
  src/ast/dot-printer.cc
  src/ast/pretty-printer.cc
  src/ast/transformer.cc
  src/ast/default-visitor.hh
  src/ast/fwd.hh
)

else()
  MESSAGE("No bison specified, using pregenerated grammar and AST files.")
  qi_generate_src(
    ${CMAKE_CURRENT_BINARY_DIR}/src/parser/ugrammar.cc
    ${CMAKE_CURRENT_BINARY_DIR}/src/parser/utoken.cc
    SRC src/parser/ugrammar.y src/ast/ast.yml src/parser/pregenerated/ugrammar.cc
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src/parser/pregenerated/ ${CMAKE_CURRENT_BINARY_DIR}/src/parser/
  )

  # HACK, to avoid a qi_generate_src rule for all 100 files,
  # merge the ccs into one merged.cc and declare arule just for it
  qi_generate_src(
    ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/merged.cc
    SRC src/ast/ast.yml
    COMMAND ${CMAKE_COMMAND} -E copy_directory   ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/pregenerated/ ${CMAKE_CURRENT_SOURCE_DIR}/src/ast/
  )
  set(GENERATED_SRC
    src/ast/merged.cc
  )

endif(HAVE_CUSTOM_BISON)


set(UOBJECT_PLUGIN_SRC
${CMAKE_CURRENT_BINARY_DIR}/include/urbi/kernel/config.h
${GENERATED_SRC}
src/ast/analyzer.cc
src/ast/analyzer.hh
src/ast/catches-type.cc
src/ast/catches-type.hh
src/ast/dot-print.cc
src/ast/dot-print.hh
src/ast/event-match.cc
{'fraction_non_alphanumeric': 0.12213551343986126, 'fraction_numerical': 0.0014864362690449647, 'mean_word_length': 5.4181240063593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3570737', 'n_tokens_mistral': 3344, 'n_tokens_neox': 3144, 'n_words': 409}