Skip to content

Commit

Permalink
cmake: create and link compile_commands.json file
Browse files Browse the repository at this point in the history
CMake has support to create a json file which contains exact information
how each file in the project is compiled. This file can be consumed by
clangd, which in turn provides precise symbol information to IDEs for
better code navigation and contextual information.

I use it with vscode to be able to quickly switch between native Linux and
mingw builds and have the symbols info change dynamically with it. So
handy that I think it is useful for others as well.

Bump required CMake version for CREATE_LINK.

Change-Id: Ib14c1161b4b0c9df797b9932ad14739e202cea64
Signed-off-by: Heiko Hund <[email protected]>
Acked-by: Frank Lichtenheld <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg27840.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
d12fk authored and cron2 committed Dec 20, 2023
1 parent 55d7395 commit 855030f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4

compile_commands.json
doc/openvpn-examples.5
doc/openvpn-examples.5.html
doc/openvpn.8
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;ASAN")
project(openvpn)

Expand Down Expand Up @@ -42,6 +42,11 @@ option(USE_WERROR "Treat compiler warnings as errors (-Werror)" ON)

set(PLUGIN_DIR /usr/local/lib/openvpn/plugins CACHE FILEPATH "Location of the plugin directory")

# Create machine readable compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
file(CREATE_LINK ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json SYMBOLIC)

# AddressSanitize - use CXX=clang++ CC=clang cmake -DCMAKE_BUILD_TYPE=asan to build with ASAN
set(CMAKE_C_FLAGS_ASAN
"-fsanitize=address,undefined -fno-sanitize-recover=all -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1"
Expand Down

0 comments on commit 855030f

Please sign in to comment.