I have a CMake project and I want to migration it to bazel.
In original CMake project, I have some components which can be compiled as an executable or as a static library with certain conditions enabled.
For example:
if(SOME_FLAG)
add_executable(hello main.cpp lib.cpp)
else()
add_library(
hello STATIC lib.cpp)
endif()
...
In other words, I hope the following conditions to be met:
- Choose whether to compile into an executable or a library by label provided on ctl.
- If output an executable, the name should be "hello"(in this case). If output a static library, the name should be "libhello.a"(in this case).
genrule is a solution, but I want to implement it by rule like:
my_cc_binary_or_library(
name = "hello",
target = select({":library": "static_library", ":binary": "binary"}),
hdrs = [...] # enable when target is "static_library" or "dynamic_library"
...
)