Back to all reviewers

target-specific CMake configurations

tree-sitter/tree-sitter
Based on 2 comments
Txt

Use target-specific CMake commands instead of global ones to ensure proper scoping and avoid polluting the global build environment. This improves maintainability and prevents unintended side effects when building multiple targets.

Configurations Txt

Reviewer Prompt

Use target-specific CMake commands instead of global ones to ensure proper scoping and avoid polluting the global build environment. This improves maintainability and prevents unintended side effects when building multiple targets.

Replace global configuration commands with their target-specific equivalents:

  • Use target_compile_definitions() instead of add_definitions()
  • Use target_compile_options() instead of setting CMAKE_C_FLAGS
  • Use target_include_directories() instead of include_directories()

Example:

# Avoid global settings
add_definitions(-D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE)
set(CMAKE_C_FLAGS "-O3 -Wall -Wextra -Wshadow")

# Prefer target-specific settings
target_compile_definitions(tree-sitter PRIVATE _POSIX_C_SOURCE=200112L _DEFAULT_SOURCE)
target_compile_options(tree-sitter PRIVATE -O3 -Wall -Wextra -Wshadow -Wno-unused-parameter -pedantic)

This approach ensures that configuration settings only apply to the intended targets and makes the build system more modular and predictable.

2
Comments Analyzed
Txt
Primary Language
Configurations
Category

Source Discussions