Skip to content

How to define 'srcs' based on OS or toolchain? #342

@brooksbp

Description

@brooksbp

How can I add a source file to the srcs list based on the target OS or CPU?

cc_library(
  ...
  srcs = [
    "file_util.cc",
    "file_util_posix.cc" if OS==LINUX else "",
    "file_util_win.cc" if OS==WIN else "",
    ...
    "widget.c",
    "widget_x86.c" if CPU==X86 else "",
    "widget_arm.c" if CPU==ARM else "",
  ],
  ...
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions