• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Run the Completion Model Codegenerator on the model present in the
2# ${model} directory.
3# Produces a pair of files called ${filename}.h and  ${filename}.cpp in the
4# ${CMAKE_CURRENT_BINARY_DIR}. The generated header
5# will define a C++ class called ${cpp_class} - which may be a
6# namespace-qualified class name.
7function(gen_decision_forest model filename cpp_class)
8  set(model_compiler ${CMAKE_SOURCE_DIR}/../clang-tools-extra/clangd/quality/CompletionModelCodegen.py)
9
10  set(output_dir ${CMAKE_CURRENT_BINARY_DIR})
11  set(header_file ${output_dir}/${filename}.h)
12  set(cpp_file ${output_dir}/${filename}.cpp)
13
14  add_custom_command(OUTPUT ${header_file} ${cpp_file}
15    COMMAND "${Python3_EXECUTABLE}" ${model_compiler}
16      --model ${model}
17      --output_dir ${output_dir}
18      --filename ${filename}
19      --cpp_class ${cpp_class}
20    COMMENT "Generating code completion model runtime..."
21    DEPENDS ${model_compiler} ${model}/forest.json ${model}/features.json
22    VERBATIM )
23
24  set_source_files_properties(${header_file} PROPERTIES
25    GENERATED 1)
26  set_source_files_properties(${cpp_file} PROPERTIES
27    GENERATED 1)
28
29  # Disable unused label warning for generated files.
30  if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
31    set_source_files_properties(${cpp_file} PROPERTIES
32      COMPILE_FLAGS /wd4102)
33  else()
34    set_source_files_properties(${cpp_file} PROPERTIES
35      COMPILE_FLAGS -Wno-unused)
36  endif()
37endfunction()
38