2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-28 08:43:26 +00:00
rules_foreign_cc/examples/cmake_crosstool/static/BUILD

135 lines
3.4 KiB
Python

# example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib
# for test only
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
exports_files([
"hello_client.c",
])
cmake_external(
name = "libhello",
lib_source = ":srcs",
# pass include/version123 to C/C++ provider as include directory
out_include_dir = "include/version123",
)
cmake_external(
name = "libhello_win",
cmake_options = ["-G \"Visual Studio 15 2017\" -A x64"],
generate_crosstool_file = True,
lib_name = "libhello",
lib_source = ":srcs",
make_commands = ["MSBuild.exe INSTALL.vcxproj"],
# pass include/version123 to C/C++ provider as include directory
out_include_dir = "include/version123",
static_libraries = ["hello.lib"],
)
cmake_external(
name = "libhello_win_ninja",
cmake_options = ["-GNinja"],
generate_crosstool_file = True,
lib_source = ":srcs",
make_commands = [
"ninja",
"ninja install",
],
# pass include/version123 to C/C++ provider as include directory
out_include_dir = "include/version123",
static_libraries = ["hello.lib"],
)
cmake_external(
name = "libhello_win_nmake",
cmake_options = ["-G \"NMake Makefiles\""],
generate_crosstool_file = True,
lib_source = ":srcs",
make_commands = [
"nmake",
"nmake install",
],
# pass include/version123 to C/C++ provider as include directory
out_include_dir = "include/version123",
static_libraries = ["hello.lib"],
)
cc_binary(
name = "libhello_example",
# includes just hello.h, include directory: "include/version123"
srcs = ["hello_client.c"],
deps = select({
"//:windows": [":libhello_win"],
"//conditions:default": [":libhello"],
}),
)
cc_binary(
name = "libhello_example_ninja",
# includes just hello.h, include directory: "include/version123"
srcs = ["hello_client.c"],
deps = select({
"//:windows": [":libhello_win_ninja"],
"//conditions:default": [":libhello"],
}),
)
cc_binary(
name = "libhello_example_nmake",
# includes just hello.h, include directory: "include/version123"
srcs = ["hello_client.c"],
deps = select({
"//:windows": [":libhello_win_nmake"],
"//conditions:default": [":libhello"],
}),
)
sh_test(
name = "test_hello",
srcs = ["test_hello.sh"],
args = ["libhello_example"],
data = [":libhello_example"],
tags = ["windows"],
visibility = ["//:__pkg__"],
)
sh_test(
name = "test_hello_ninja",
srcs = ["test_hello.sh"],
args = ["libhello_example_ninja"],
data = [":libhello_example_ninja"],
tags = ["windows"],
visibility = ["//:__pkg__"],
)
sh_test(
name = "test_hello_nmake",
srcs = ["test_hello.sh"],
args = ["libhello_example_nmake"],
data = [":libhello_example_nmake"],
tags = ["windows"],
visibility = ["//:__pkg__"],
)
cmake_external(
name = "libhello123",
lib_source = ":srcs",
out_include_dir = "include",
# the name of the static library != <name>.a, put it explicitly
static_libraries = ["libhello.a"],
)
cc_binary(
name = "libhello_example123",
# includes version123/hello.h, include directory: "include"
srcs = ["hello_client_version123.c"],
deps = [":libhello123"],
)