Set CMAKE_INSTALL_PREFIX to the actual install directory to avoid copy (#575)
This commit is contained in:
parent
0a0f8fd6db
commit
46047ae15c
|
@ -101,7 +101,7 @@ Rule for building external library with CMake.
|
|||
| <a id="cmake-headers_only"></a>headers_only | __deprecated__: Use <code>out_headers_only</code> instead. | Boolean | optional | False |
|
||||
| <a id="cmake-install"></a>install | If True, the <code>cmake --install</code> comand will be performed after a build | Boolean | optional | True |
|
||||
| <a id="cmake-install_args"></a>install_args | Arguments for the CMake install command | List of strings | optional | [] |
|
||||
| <a id="cmake-install_prefix"></a>install_prefix | Relative install prefix to be passed to CMake in <code>-DCMAKE_INSTALL_PREFIX</code> | String | optional | "" |
|
||||
| <a id="cmake-install_prefix"></a>install_prefix | __deprecated__: This field is deprecated and is no longer used. | String | optional | "" |
|
||||
| <a id="cmake-interface_libraries"></a>interface_libraries | __deprecated__: Use <code>out_interface_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="cmake-lib_name"></a>lib_name | Library name. Defines the name of the install directory and the name of the static library, if no output files parameters are defined (any of static_libraries, shared_libraries, interface_libraries, binaries_names) Optional. If not defined, defaults to the target's name. | String | optional | "" |
|
||||
| <a id="cmake-lib_source"></a>lib_source | Label with source code to build. Typically a filegroup for the source of remote repository. Mandatory. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
|
||||
|
||||
cmake(
|
||||
name = "hello_world",
|
||||
generate_args = ["-GNinja"],
|
||||
lib_source = "@cmake_hello_world_variant_src//:all",
|
||||
out_binaries = select({
|
||||
"//:macos": ["CMakeHelloWorld"],
|
||||
"//:windows": ["CMakeHelloWorld.exe"],
|
||||
"//conditions:default": ["CMakeHelloWorld"],
|
||||
}),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "binary",
|
||||
srcs = [":hello_world"],
|
||||
output_group = select({
|
||||
"//:macos": "CMakeHelloWorld",
|
||||
"//:windows": "CMakeHelloWorld.exe",
|
||||
"//conditions:default": "CMakeHelloWorld",
|
||||
}),
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "test_hello_world",
|
||||
srcs = ["test_hello_world.sh"],
|
||||
args = ["$(location :binary)"],
|
||||
data = [":binary"],
|
||||
deps = ["@bazel_tools//tools/bash/runfiles"],
|
||||
)
|
|
@ -1,29 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# --- begin runfiles.bash initialization ---
|
||||
# The runfiles library itself defines rlocation which you would need to look
|
||||
# up the library's runtime location, thus we have a chicken-and-egg problem.
|
||||
#
|
||||
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
|
||||
set -euo pipefail
|
||||
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
|
||||
if [[ -f "$0.runfiles_manifest" ]]; then
|
||||
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
|
||||
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
|
||||
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
|
||||
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
|
||||
export RUNFILES_DIR="$0.runfiles"
|
||||
fi
|
||||
fi
|
||||
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
|
||||
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
|
||||
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
|
||||
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
|
||||
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
|
||||
else
|
||||
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
|
||||
exit 1
|
||||
fi
|
||||
# --- end runfiles.bash initialization ---
|
||||
|
||||
$(rlocation $TEST_WORKSPACE/$1)
|
|
@ -32,15 +32,3 @@ def repositories():
|
|||
sha256 = RULES_JVM_EXTERNAL_SHA,
|
||||
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
|
||||
)
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "cmake_hello_world_variant_src",
|
||||
build_file_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])""",
|
||||
strip_prefix = "cmake-hello-world-master",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/jameskbride/cmake-hello-world/archive/master.zip",
|
||||
"https://github.com/jameskbride/cmake-hello-world/archive/master.zip",
|
||||
],
|
||||
sha256 = "d613cf222bbb05b8cff7a1c03c37345ed33744a4ebaf3a8bfd5f56a76e25ca08",
|
||||
)
|
||||
|
|
|
@ -50,7 +50,6 @@ def _cmake_impl(ctx):
|
|||
generate_args = generate_args,
|
||||
configure_name = "CMake",
|
||||
create_configure_script = _create_configure_script,
|
||||
postfix_script = "##copy_dir_contents_to_dir## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ $$INSTALLDIR$$\n" + ctx.attr.postfix_script,
|
||||
tools_deps = tools_deps,
|
||||
cmake_path = cmake_data.path,
|
||||
)
|
||||
|
@ -117,14 +116,13 @@ def _create_configure_script(configureParameters):
|
|||
config = configuration,
|
||||
))
|
||||
|
||||
define_install_prefix = ["export INSTALL_PREFIX=\"" + _get_install_prefix(ctx) + "\""]
|
||||
configure_script = create_cmake_script(
|
||||
workspace_name = ctx.workspace_name,
|
||||
generator = attrs.generator,
|
||||
cmake_path = attrs.cmake_path,
|
||||
tools = tools,
|
||||
flags = flags,
|
||||
install_prefix = "$$INSTALL_PREFIX$$",
|
||||
install_prefix = "$$INSTALLDIR$$",
|
||||
root = root,
|
||||
no_toolchain_file = no_toolchain_file,
|
||||
user_cache = dict(ctx.attr.cache_entries),
|
||||
|
@ -134,7 +132,7 @@ def _create_configure_script(configureParameters):
|
|||
include_dirs = inputs.include_dirs,
|
||||
is_debug_mode = is_debug_mode(ctx),
|
||||
)
|
||||
return define_install_prefix + configure_script
|
||||
return configure_script
|
||||
|
||||
def _get_generator_target(ctx):
|
||||
"""Parse the genrator arguments for a generator declaration
|
||||
|
@ -206,13 +204,6 @@ def _get_generator_target(ctx):
|
|||
|
||||
fail("`{}` is not a known generator".format(generator))
|
||||
|
||||
def _get_install_prefix(ctx):
|
||||
if ctx.attr.install_prefix:
|
||||
return ctx.attr.install_prefix
|
||||
if ctx.attr.lib_name:
|
||||
return ctx.attr.lib_name
|
||||
return ctx.attr.name
|
||||
|
||||
def _attrs():
|
||||
attrs = dict(CC_EXTERNAL_RULE_ATTRIBUTES)
|
||||
attrs.update({
|
||||
|
@ -273,7 +264,7 @@ def _attrs():
|
|||
mandatory = False,
|
||||
),
|
||||
"install_prefix": attr.string(
|
||||
doc = "Relative install prefix to be passed to CMake in `-DCMAKE_INSTALL_PREFIX`",
|
||||
doc = "__deprecated__: This field is deprecated and is no longer used.",
|
||||
mandatory = False,
|
||||
),
|
||||
"make_commands": attr.string_list(
|
||||
|
|
Loading…
Reference in New Issue