Modify hello world example with CMake to build on Windows (#86)
- with MSBuild generator (the path to it should be on the PATH) - use CMake crosstool file
This commit is contained in:
parent
0aab4e65c5
commit
10ab431c38
|
@ -1,12 +1,21 @@
|
|||
tests = [
|
||||
"//examples/cmake:test_libgd",
|
||||
"//examples/cmake:test_libpng",
|
||||
"//examples/cmake:test_zlib",
|
||||
"//examples/cmake_cares:test_c_ares",
|
||||
"//examples/cmake_hello_world_lib:test_hello",
|
||||
"//examples/cmake_nghttp2:test_nghttp2",
|
||||
"//examples/ninja:test_ninja_version",
|
||||
"//test:cmake_script_test_suite",
|
||||
]
|
||||
|
||||
test_suite(
|
||||
name = "tests",
|
||||
tests = [
|
||||
"//examples/cmake:test_libgd",
|
||||
"//examples/cmake:test_libpng",
|
||||
"//examples/cmake:test_zlib",
|
||||
"//examples/cmake_cares:test_c_ares",
|
||||
"//examples/cmake_nghttp2:test_nghttp2",
|
||||
"//examples/ninja:test_ninja_version",
|
||||
"//test:cmake_script_test_suite",
|
||||
],
|
||||
tests = tests,
|
||||
)
|
||||
|
||||
test_suite(
|
||||
name = "win_tests",
|
||||
tags = ["windows"],
|
||||
tests = tests,
|
||||
)
|
||||
|
|
|
@ -4,22 +4,45 @@
|
|||
filegroup(
|
||||
name = "srcs",
|
||||
srcs = glob(["**"]),
|
||||
visibility = ["//visibility:public"]
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
load("//tools/build_defs:cmake.bzl", "cmake_external")
|
||||
|
||||
cmake_external(
|
||||
name = "libhello",
|
||||
lib_source = ":srcs",
|
||||
# pass include/version123 to C/C++ provider as include directory
|
||||
out_include_dir = "include/version123"
|
||||
out_include_dir = "include/version123",
|
||||
)
|
||||
|
||||
cmake_external(
|
||||
name = "libhello_win",
|
||||
cmake_options = ["-G \"Visual Studio 15 2017 Win64\""],
|
||||
generate_crosstool_file = True,
|
||||
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"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "libhello_example",
|
||||
# includes just hello.h, include directory: "include/version123"
|
||||
srcs = ["hello_client.c"],
|
||||
deps = [":libhello"]
|
||||
deps = select({
|
||||
"@bazel_tools//src/conditions:windows": [":libhello_win"],
|
||||
"//conditions:default": [":libhello"],
|
||||
}),
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "test_hello",
|
||||
srcs = ["test_hello.sh"],
|
||||
data = [":libhello_example"],
|
||||
tags = ["windows"],
|
||||
visibility = ["//:__pkg__"],
|
||||
)
|
||||
|
||||
cmake_external(
|
||||
|
@ -27,11 +50,12 @@ cmake_external(
|
|||
lib_source = ":srcs",
|
||||
out_include_dir = "include",
|
||||
# the name of the static library != <name>.a, put it explicitly
|
||||
static_libraries = ["libhello.a"]
|
||||
static_libraries = ["libhello.a"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "libhello_example123",
|
||||
# includes version123/hello.h, include directory: "include"
|
||||
srcs = ["hello_client_version123.c"],
|
||||
deps = [":libhello123"]
|
||||
deps = [":libhello123"],
|
||||
)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
${TEST_SRCDIR}/rules_foreign_cc/examples/cmake_hello_world_lib/libhello_example
|
Loading…
Reference in New Issue