Swift: cmake generator for better IDE support · github/codeql@b8b6b25 · GitHub
Skip to content

Commit b8b6b25

Browse files
committed
Swift: cmake generator for better IDE support
A cmake generator in bazel is introduced allowing to import the Swift extractor as a CMake project while keeping Bazel files as the source of truth for the build. Using the CMake project: * requires bazel and clang to be installed and available on the command line * does not require a previous bazel build, however * will require a CMake reconfiguration for changes to generated code (like changes to the schema)
1 parent 6c781b5 commit b8b6b25

6 files changed

Lines changed: 302 additions & 1 deletion

File tree

‎misc/bazel/cmake/BUILD.bazel‎

Whitespace-only changes.

‎misc/bazel/cmake/cmake.bzl‎

Lines changed: 250 additions & 0 deletions

‎misc/bazel/cmake/setup.cmake‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
option(BUILD_SHARED_LIBS "" 0)
2+
3+
execute_process(COMMAND bazel info workspace OUTPUT_VARIABLE BAZEL_WORKSPACE COMMAND_ERROR_IS_FATAL ANY OUTPUT_STRIP_TRAILING_WHITESPACE)
4+
5+
execute_process(COMMAND bazel info output_base OUTPUT_VARIABLE BAZEL_OUTPUT_BASE COMMAND_ERROR_IS_FATAL ANY OUTPUT_STRIP_TRAILING_WHITESPACE)
6+
string(REPLACE "-" "_" BAZEL_EXEC_ROOT ${PROJECT_NAME})
7+
set(BAZEL_EXEC_ROOT ${BAZEL_OUTPUT_BASE}/execroot/${BAZEL_EXEC_ROOT})
8+
9+
execute_process(COMMAND bazel query "kind(generate_cmake, //...)" OUTPUT_VARIABLE BAZEL_GENERATE_CMAKE_TARGETS COMMAND_ERROR_IS_FATAL ANY OUTPUT_STRIP_TRAILING_WHITESPACE)
10+
execute_process(COMMAND bazel build ${BAZEL_GENERATE_CMAKE_TARGETS} COMMAND_ERROR_IS_FATAL ANY)
11+
12+
string(REPLACE "//" "" BAZEL_GENERATE_CMAKE_TARGETS "${BAZEL_GENERATE_CMAKE_TARGETS}")
13+
string(REPLACE ":" "/" BAZEL_GENERATE_CMAKE_TARGETS "${BAZEL_GENERATE_CMAKE_TARGETS}")
14+
15+
foreach (target ${BAZEL_GENERATE_CMAKE_TARGETS})
16+
include(${BAZEL_WORKSPACE}/bazel-bin/${target}.cmake)
17+
endforeach ()
18+
19+
if (CMAKE_EXPORT_COMPILE_COMMANDS)
20+
file(CREATE_LINK ${PROJECT_BINARY_DIR}/compile_commands.json ${PROJECT_SOURCE_DIR}/compile_commands.json)
21+
endif ()

‎swift/.gitignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@
33

44
# output files created by running tests
55
*.o
6+
7+
# compilation database
8+
compile_commands.json
9+
10+
# CLion project data and build directories
11+
/.idea
12+
/cmake*
13+
14+
# VSCode default build directory
15+
/build

‎swift/CMakeLists.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# this uses generated cmake files to setup cmake compilation of the swift extractor
2+
# this is provided solely for IDE integration
3+
4+
cmake_minimum_required(VERSION 3.21)
5+
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
set(CMAKE_C_COMPILER clang)
10+
set(CMAKE_CXX_COMPILER clang++)
11+
12+
project(codeql)
13+
14+
include(../misc/bazel/cmake/setup.cmake)

‎swift/extractor/BUILD.bazel‎

Lines changed: 7 additions & 1 deletion

0 commit comments

Comments
 (0)