Home Explore Blog CI



neovim

12th chunk of `src/nvim/CMakeLists.txt`
56732cae4683985c571f7fef496e12a6ef965d643253867f0000000100000956

set_target_properties(
  libnvim
  PROPERTIES
    OUTPUT_NAME ${LIBNVIM_NAME}
)
target_compile_definitions(libnvim PRIVATE MAKE_LIB)
target_link_libraries(libnvim PRIVATE main_lib PUBLIC libuv)

#-------------------------------------------------------------------------------
# Lint
#-------------------------------------------------------------------------------

find_program(CLANG_TIDY_PRG clang-tidy)
mark_as_advanced(CLANG_TIDY_PRG)
set(EXCLUDE_CLANG_TIDY typval_encode.c.h ui_events.in.h)
if(WIN32)
  list(APPEND EXCLUDE_CLANG_TIDY
    os/pty_proc_unix.h
    os/unix_defs.h)
else()
  list(APPEND EXCLUDE_CLANG_TIDY
    os/win_defs.h
    os/pty_proc_win.h
    os/pty_conpty_win.h
    os/os_win_console.h)
endif()
add_glob_target(
  TARGET lintc-clang-tidy
  COMMAND ${CLANG_TIDY_PRG}
  FILES ${LINT_NVIM_SOURCES}
  FLAGS --quiet
  EXCLUDE ${EXCLUDE_CLANG_TIDY})

# The checks we ignore are meant to be removed eventually, but we can only
# enable each warning after we fix all instances of that specific warning as to
# not break CI.
if(APPLE)
  string(APPEND CLANG_ANALYZER_IGNORE "-clang-analyzer-core.NonNullParamChecker,")
endif()
add_glob_target(
  TARGET clang-analyzer
  COMMAND ${CLANG_TIDY_PRG}
  FILES ${LINT_NVIM_SOURCES}
  FLAGS --quiet
  --checks='
  -*,
  clang-analyzer-*,
  -clang-analyzer-core.NullDereference,
  -clang-analyzer-core.UndefinedBinaryOperatorResult,
  -clang-analyzer-core.uninitialized.Assign,
  -clang-analyzer-optin.core.EnumCastOutOfRange,
  -clang-analyzer-optin.performance.Padding,
  -clang-analyzer-security.insecureAPI.strcpy,
  -clang-analyzer-unix.StdCLibraryFunctions,
  -clang-analyzer-unix.Stream,
  ${CLANG_ANALYZER_IGNORE}
  '
  EXCLUDE ${EXCLUDE_CLANG_TIDY})

add_custom_target(copy_compile_commands
  COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/compile_commands.json ${PROJECT_SOURCE_DIR}/compile_commands.json)
add_dependencies(copy_compile_commands nvim_bin)
add_dependencies(lintc-clang-tidy copy_compile_commands)
add_dependencies(clang-analyzer copy_compile_commands)

if(CI_BUILD)
  set(LINT_OUTPUT_FORMAT gh_action)
else()
  set(LINT_OUTPUT_FORMAT vs7)
endif()
add_glob_target(
  TARGET lintc-clint
  COMMAND ${PROJECT_SOURCE_DIR}/src/clint.py
  FLAGS --output=${LINT_OUTPUT_FORMAT}
  FILES ${LINT_NVIM_SOURCES}
  EXCLUDE
    tui/terminfo_defs.h)

set(UNCRUSTIFY_PRG ${DEPS_BIN_DIR}/uncrustify)
set(UNCRUSTIFY_CONFIG

Title: Linting Targets Configuration: clang-tidy, clang-analyzer, clint, and uncrustify
Summary
This section configures various linting targets, including `lintc-clang-tidy` and `clang-analyzer` using clang-tidy, and `lintc-clint` using a Python script, specifying source files, flags, and exclusions. It also configures `copy_compile_commands` to copy the compilation database, manages CI build outputs, and prepares for uncrustify integration.