From f49f6430a1a3c5e55f9a2d923e311a7f6ec07088 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 24 Oct 2022 14:10:49 +0200 Subject: [PATCH 1/2] Bazel/CMake: make cmake runnable from outside the workspace Also added a small `README.md` file. --- misc/bazel/cmake/README.md | 12 ++++++++++++ misc/bazel/cmake/setup.cmake | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 misc/bazel/cmake/README.md diff --git a/misc/bazel/cmake/README.md b/misc/bazel/cmake/README.md new file mode 100644 index 00000000000..f70b3d6dce5 --- /dev/null +++ b/misc/bazel/cmake/README.md @@ -0,0 +1,12 @@ +This directory contains a Bazel to CMake generator intended mainly for IDE integration. + +[`cmake.bzl`](./cmake.bzl) contains the Bazel side, with the `cmake_aspect` rule gathering the necessary information +from `cc_*` rules and `generate_cmake` translating that information into CMake commands. `generate_cmake` targets also +depend on all files that are either generated or fetched from external repositories, so that Bazel will fill in those +dependencies before letting CMake to the C/C++ compilation. + +[`setup.cmake`](./setup.cmake) contains the generic CMake setup, setting up some Bazel related global variables and +providing an `include_generated` macro to be used in `CMakeLists.txt` to include a specific `generate_cmake` Bazel +target. + +See Swift's [`CMakeLists.txt`](../../../swift/CMakeLists.txt) file for an example usage. diff --git a/misc/bazel/cmake/setup.cmake b/misc/bazel/cmake/setup.cmake index a1e94384602..81e5aeeb8b5 100644 --- a/misc/bazel/cmake/setup.cmake +++ b/misc/bazel/cmake/setup.cmake @@ -6,7 +6,10 @@ if (CREATE_COMPILATION_DATABASE_LINK) endif () macro(bazel) - execute_process(COMMAND bazel ${ARGN} COMMAND_ERROR_IS_FATAL ANY OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND bazel ${ARGN} + COMMAND_ERROR_IS_FATAL ANY + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endmacro() bazel(info workspace OUTPUT_VARIABLE BAZEL_WORKSPACE) From 1866a98c77080b24fed8ce5cc56617d53b4d1422 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 24 Oct 2022 14:19:11 +0200 Subject: [PATCH 2/2] Bazel/CMake: fix typo in `README.md` --- misc/bazel/cmake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/bazel/cmake/README.md b/misc/bazel/cmake/README.md index f70b3d6dce5..921a793fe12 100644 --- a/misc/bazel/cmake/README.md +++ b/misc/bazel/cmake/README.md @@ -3,7 +3,7 @@ This directory contains a Bazel to CMake generator intended mainly for IDE integ [`cmake.bzl`](./cmake.bzl) contains the Bazel side, with the `cmake_aspect` rule gathering the necessary information from `cc_*` rules and `generate_cmake` translating that information into CMake commands. `generate_cmake` targets also depend on all files that are either generated or fetched from external repositories, so that Bazel will fill in those -dependencies before letting CMake to the C/C++ compilation. +dependencies before letting CMake do the C/C++ compilation. [`setup.cmake`](./setup.cmake) contains the generic CMake setup, setting up some Bazel related global variables and providing an `include_generated` macro to be used in `CMakeLists.txt` to include a specific `generate_cmake` Bazel