neovim/contrib/local.mk.example
Daiki Noda ac5a6d9ff5
build: fix RelWithDebInfo optimization flags #31802
Problem:
RelWithDebInfo generates redundant flags:

    Compilation: /usr/bin/cc -O2 -g -Og -g

The `CMAKE_C_FLAGS_RELWITHDEBINFO` variable is being modified in a way
that caused duplicate `-Og` and `-g` flags to be added. The resulting
flags were `-O2 -g -Og -g`.

- `-Og` (Optimize for debugging) and `-O2` (Optimize for performance)
  are different optimization levels. We can't use both at once.
- The duplicate `-g` flag is redundant and no effect.

multiple -O flags has no effect for code, just redundant.

> If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Solution:
Adjust the flags to use the more appropriate `-O2 -g`.

    Compilation: /usr/bin/cc -O2 -g

BEFORE:

```
:verbose version
NVIM v0.11.0-dev-1443+ge00cd1ab40
Build type: RelWithDebInfo
LuaJIT 2.1.1734355927
Compilation: /usr/bin/cc -O2 -g -Og -g -flto -fno-fat-lto-ob
jects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict
...
```

AFTER:

```
:verbose version
NVIM v0.11.0-dev-e00cd1ab4-dirty
Build type: RelWithDebInfo
LuaJIT 2.1.1734355927
Compilation: /usr/bin/cc -O2 -g -flto -fno-fat-lto-objects -
Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-protot
...
```
2025-01-05 11:28:31 -08:00

60 lines
2.3 KiB
Plaintext

# Copy this to 'local.mk' in the repository root.
# Individual entries must be uncommented to take effect.
# By default, the installation prefix is '/usr/local'.
# CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=/usr/local/nvim-latest
# These CFLAGS can be used in addition to those specified in CMakeLists.txt:
# CMAKE_EXTRA_FLAGS="-DCMAKE_C_FLAGS=-ftrapv -Wlogical-op"
# To turn compiler warnings into errors:
# CMAKE_EXTRA_FLAGS += "-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -Werror"
# Sets the build type; defaults to Debug. Valid values:
#
# - Debug: Disables optimizations (-O0), enables debug information.
#
# - RelWithDebInfo: Enables optimizations (-O2) with debug information.
#
# - MinSizeRel: Enables all -O2 optimization that do not typically
# increase code size, and performs further optimizations
# designed to reduce code size (-Os).
# Disables debug information.
#
# - Release: Same as RelWithDebInfo, but disables debug information.
#
# CMAKE_BUILD_TYPE := Debug
# With non-Debug builds interprocedural optimization (IPO) (which includes
# link-time optimization (LTO)) is enabled by default, which causes the link
# step to take a significant amount of time, which is relevant when building
# often. You can disable it explicitly:
# CMAKE_EXTRA_FLAGS += -DENABLE_LTO=OFF
# Log levels: DEBUG, INFO, WARNING, ERROR
# For Debug builds all log levels are used
# For Release and RelWithDebInfo builds only WARNING and ERROR are used, unless:
# CMAKE_EXTRA_FLAGS += -DLOG_DEBUG
# By default, nvim uses bundled versions of its required third-party
# dependencies.
# Uncomment these entries to instead use system-wide installations of
# them.
#
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_BUSTED=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_GETTEXT=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_LIBICONV=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_LIBUV=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_LUAJIT=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_LUV=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_TS=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_TS_PARSERS=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_UNIBILIUM=OFF
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED_UTF8PROC=OFF
#
# Or disable all bundled dependencies at once.
#
# DEPS_CMAKE_FLAGS += -DUSE_BUNDLED=OFF
# .DEFAULT_GOAL := nvim