Home Explore Blog CI



neovim

2nd chunk of `src/nvim/CMakeLists.txt`
5527f10a0aba998502e22c3f4fce2354bffbbd21501a2c250000000100000fa3
 -Wshadow -Wconversion -Wvla
    -Wdouble-promotion
    -Wmissing-noreturn
    -Wmissing-format-attribute
    -Wmissing-prototypes
    -fsigned-char)

  # For O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW flags on older systems
  # (pre POSIX.1-2008: glibc 2.11 and earlier). #4042
  # For ptsname(). #6743
  target_compile_definitions(main_lib INTERFACE _GNU_SOURCE)
endif()

# -fstack-protector breaks Mingw-w64 builds
if(NOT MINGW)
  check_c_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG_FLAG)
  if(HAS_FSTACK_PROTECTOR_STRONG_FLAG)
    target_compile_options(main_lib INTERFACE -fstack-protector-strong)
    target_link_libraries(main_lib INTERFACE -fstack-protector-strong)
  else()
    check_c_compiler_flag(-fstack-protector HAS_FSTACK_PROTECTOR_FLAG)
    if(HAS_FSTACK_PROTECTOR_FLAG)
      target_compile_options(main_lib INTERFACE -fstack-protector --param ssp-buffer-size=4)
      target_link_libraries(main_lib INTERFACE -fstack-protector --param ssp-buffer-size=4)
    endif()
  endif()
endif()

# Compiler specific options
if(MSVC)
  target_compile_options(main_lib INTERFACE -W3)

  # Disable warnings that give too many false positives.
  target_compile_options(main_lib INTERFACE -wd4311 -wd4146 -wd4003 -wd4715)
  target_compile_definitions(main_lib INTERFACE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)

  target_sources(main_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/os/nvim.manifest)
elseif(MINGW)
  # Use POSIX compatible stdio in Mingw
  target_compile_definitions(main_lib INTERFACE __USE_MINGW_ANSI_STDIO)

  # wrapper for nvim.manifest
  target_sources(main_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/os/nvim.rc)
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  target_compile_options(main_lib INTERFACE
    -Wno-conversion
    -fno-common
    $<$<CONFIG:Release>:-Wno-unused-result>
    $<$<CONFIG:RelWithDebInfo>:-Wno-unused-result>
    $<$<CONFIG:MinSizeRel>:-Wno-unused-result>)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
  # On FreeBSD 64 math.h uses unguarded C11 extension, which taints clang
  # 3.4.1 used there.
  if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
    target_compile_options(main_lib INTERFACE -Wno-c11-extensions)
  endif()

  # workaround for clang-11 on macOS, supported on later versions
  if(NOT APPLE)
    target_link_libraries(nvim_bin PRIVATE -Wl,--no-undefined)
  endif()
endif()

# Platform specific options
if(UNIX)
  target_link_libraries(main_lib INTERFACE m)
  if (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
    target_link_libraries(main_lib INTERFACE util)
  endif()
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
  target_compile_definitions(main_lib INTERFACE _WIN32_WINNT=0x0602 MSWIN WIN32_LEAN_AND_MEAN)
  target_link_libraries(main_lib INTERFACE netapi32)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
  target_link_libraries(nvim_bin PRIVATE "-framework CoreServices")

  # Actually export symbols - symbols may not be visible even though
  # ENABLE_EXPORTS is set to true. See
  # https://github.com/neovim/neovim/issues/25295
  target_link_options(nvim_bin PRIVATE "-Wl,-export_dynamic")
elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  target_link_libraries(main_lib INTERFACE pthread c++abi)
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  target_link_libraries(nvim_bin PRIVATE -lsocket)
endif()

check_c_compiler_flag(-Wimplicit-fallthrough HAVE_WIMPLICIT_FALLTHROUGH_FLAG)
if(HAVE_WIMPLICIT_FALLTHROUGH_FLAG)
  target_compile_options(main_lib INTERFACE -Wimplicit-fallthrough)
endif()

check_c_compiler_flag(-fdiagnostics-color=auto HAS_DIAG_COLOR_FLAG)
if(HAS_DIAG_COLOR_FLAG)
  if(CMAKE_GENERATOR MATCHES "Ninja")
    target_compile_options(main_lib INTERFACE -fdiagnostics-color=always)
  else()
    target_compile_options(main_lib INTERFACE -fdiagnostics-color=auto)
  endif()
endif()

target_compile_definitions(main_lib INTERFACE INCLUDE_GENERATED_DECLARATIONS)

# Remove --sort-common from linker flags, as this seems to cause bugs (see #2641, #3374).
# TODO: Figure out the root cause.
if(CMAKE_EXE_LINKER_FLAGS MATCHES

Title: Compiler-Specific and Platform-Specific Options for Nvim
Summary
This section configures compiler and linker options based on the compiler (MSVC, MinGW, GNU, Clang) and the operating system (Windows, Darwin/macOS, OpenBSD, SunOS, Unix). It sets specific warning levels, disables certain warnings, defines preprocessor macros, and links necessary libraries for each platform. It also includes checks for compiler flags like `-Wimplicit-fallthrough` and `-fdiagnostics-color`, and adjusts compile options accordingly.