Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] Handle multiple flags in ADDITIONAL_COMPILE_FLAGS properly #112703

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Oct 17, 2024

  1. [CMake] Handle multiple flags in ADDITIONAL_COMPILE_FLAGS properly

    When multiple space-separated compile flags are specified in an
    `ADDITIONAL_COMPILE_FLAGS` cache string, the resulting flags are
    enclosed by double quotes because `ADDITIONAL_COMPILE_FLAGS` is a
    string (i.e. not a list) and CMake `target_compile_options` treats the
    multiple space-separated arguments as single argument containing spaces.
    
    For example, when libcxx is configured with the following multiple
    space-separated additional compile flags:
    
        cmake ... "-DLIBCXX_ADDITIONAL_COMPILE_FLAGS=--flag1 --flag2" ...
    
    The resulting compiler command line is as follows:
    
        cc ... "--flag1 --flag2" ...
    
    The above can be problematic for some compilers -- for instance, GCC
    treats it as a file path and prints out an error.
    
    This patch, by calling `separate_arguments` on
    `ADDITIONAL_COMPILE_FLAGS` to convert it into the standard
    semicolon-separated list form, which is properly handled by
    `target_compile_options`, ensures that multiple compile flags are
    handled as such.
    
    With this change, the resulting compiler command line is as follows:
    
        cc ... --flag1 --flag2 ...
    
    Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
    stephanosio committed Oct 17, 2024
    Configuration menu
    Copy the full SHA
    3763d81 View commit details
    Browse the repository at this point in the history