Migration from CMake to Bazel

116 views
Skip to first unread message

qzwxsaedc

unread,
Apr 6, 2024, 5:39:46 AMApr 6
to bazel-discuss
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:
  1. Choose whether to compile into an executable or a library by label provided on ctl.
  2. 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"
    ...
)

I want to reference to cc_binary and cc_library, but they use private API. 
Reply all
Reply to author
Forward
0 new messages