Skip to content

Commit a4258ea

Browse files
authored
Merge pull request #10953 from github/redsun82/cmake-generator
Bazel/CMake: make cmake runnable from outside the workspace
2 parents c4ba644 + 1866a98 commit a4258ea

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

misc/bazel/cmake/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This directory contains a Bazel to CMake generator intended mainly for IDE integration.
2+
3+
[`cmake.bzl`](./cmake.bzl) contains the Bazel side, with the `cmake_aspect` rule gathering the necessary information
4+
from `cc_*` rules and `generate_cmake` translating that information into CMake commands. `generate_cmake` targets also
5+
depend on all files that are either generated or fetched from external repositories, so that Bazel will fill in those
6+
dependencies before letting CMake do the C/C++ compilation.
7+
8+
[`setup.cmake`](./setup.cmake) contains the generic CMake setup, setting up some Bazel related global variables and
9+
providing an `include_generated` macro to be used in `CMakeLists.txt` to include a specific `generate_cmake` Bazel
10+
target.
11+
12+
See Swift's [`CMakeLists.txt`](../../../swift/CMakeLists.txt) file for an example usage.

misc/bazel/cmake/setup.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ if (CREATE_COMPILATION_DATABASE_LINK)
66
endif ()
77

88
macro(bazel)
9-
execute_process(COMMAND bazel ${ARGN} COMMAND_ERROR_IS_FATAL ANY OUTPUT_STRIP_TRAILING_WHITESPACE)
9+
execute_process(COMMAND bazel ${ARGN}
10+
COMMAND_ERROR_IS_FATAL ANY
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
1013
endmacro()
1114

1215
bazel(info workspace OUTPUT_VARIABLE BAZEL_WORKSPACE)

0 commit comments

Comments
 (0)