From: "d12fk (Code Review)" Date: Wed, 17 Jan 2024 03:49:59 +0000 References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <9e05cfffe76aed0ef7d93db19560a28a69c9ea41-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="gVhIYovbJSI="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: cmake: symlink whole build dir not just .json file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --gVhIYovbJSI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/501?usp=3Demail to review the following change. Change subject: cmake: symlink whole build dir not just .json file ...................................................................... cmake: symlink whole build dir not just .json file It turned out that symlinking compile_commands.json from the top level source dir has some issues: * file is not created on Windows and symlinking may cause an error * some IDEs create their own json and error out b/c a file exists Since clangd also looks for the json in build/ directories by default, we now symlink the whole build directory instead, not just the json file. This approach requires for the existing build/ dir in the repo to vanish. Luckily it only contains one automake include file, which is moved to the top level source dir. Lastly, make this an opt-in feature, so that the default configuration of the buildsystem never causes a build failure because of this. Change-Id: Ib1a5c788269949d8de95d1da2cb0c32a65bf13f2 Signed-off-by: Heiko Hund --- M .gitignore M CMakeLists.txt M Makefile.am M README.cmake.md D build/Makefile.am M configure.ac R ltrc.inc M src/openvpn/Makefile.am M src/openvpnmsica/Makefile.am M src/openvpnserv/Makefile.am M src/tapctl/Makefile.am 11 files changed, 32 insertions(+), 25 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/01/501/1 diff --git a/.gitignore b/.gitignore index 4153a3e..92d65bf 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,7 @@ m4/ltversion.m4 m4/lt~obsolete.m4 -compile_commands.json +build doc/openvpn-examples.5 doc/openvpn-examples.5.html doc/openvpn.8 diff --git a/CMakeLists.txt b/CMakeLists.txt index bc46c27..4e5c8fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,17 @@ 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 SYMBOLI= C) +option(ENABLE_COMPILE_COMMANDS "Generate compile_commands.json and a symli= nk for clangd to find it" OFF) +if (ENABLE_COMPILE_COMMANDS) + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build AND NOT IS_SYMLINK ${CMAK= E_CURRENT_SOURCE_DIR}/build) + message(FATAL_ERROR "The top level source directory contains a 'bu= ild' file or directory. Please remove or rename it. CMake creates a symlink= with that name during build.") + endif() + set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + add_custom_target( + symlink-build-dir ALL + ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR} ${C= MAKE_CURRENT_SOURCE_DIR}/build + ) +endif () # AddressSanitize - use CXX=3Dclang++ CC=3Dclang cmake -DCMAKE_BUILD_TYPE= =3Dasan to build with ASAN set(CMAKE_C_FLAGS_ASAN diff --git a/Makefile.am b/Makefile.am index 2305ab4..792588a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,6 +42,7 @@ EXTRA_DIST =3D \ contrib \ debug \ + ltrc.inc \ CMakeLists.txt \ CMakePresets.json \ config.h.cmake.in @@ -53,7 +54,7 @@ config-version.h endif -SUBDIRS =3D build distro include src sample doc tests +SUBDIRS =3D distro include src sample doc tests dist_doc_DATA =3D \ README \ diff --git a/README.cmake.md b/README.cmake.md index d181b64..4f41c70 100644 --- a/README.cmake.md +++ b/README.cmake.md @@ -135,3 +135,17 @@ The `unix-native` CMake preset is available for these builds. This preset = does not require VCPKG and instead assumes all build-dependencies are provided = by the system natively. + +Generating compile_commands.json +-------------------------------- + +To have the CMake buildsystem generate compile_commands.json you can speci= fy +`-DENABLE_COMPILE_COMMANDS=3DON` on the command line or enable the CMake o= ption +another way you like. For supported generators the file will then be creat= ed. +Additionally, the buildsystem will create a symlink `build/` to the --pres= et +build directory that contains the generated JSON file. This is done so that +clangd is able to find it. + +Enabling this option may cause an error on Windows, since creating a symli= nk +is a privileged operation there. If you enable Developer Mode for the syst= em, +symlinks can be created by regular users. diff --git a/build/Makefile.am b/build/Makefile.am deleted file mode 100644 index e7cc4d8..0000000 --- a/build/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -# -# OpenVPN -- An application to securely tunnel IP networks -# over a single UDP port, with support for SSL/TLS-based -# session authentication and key exchange, -# packet encryption, packet authentication, and -# packet compression. -# -# Copyright (C) 2002-2023 OpenVPN Inc -# - -MAINTAINERCLEANFILES =3D \ - $(srcdir)/Makefile.in - -EXTRA_DIST =3D \ - ltrc.inc diff --git a/configure.ac b/configure.ac index 2823f04..0710f71 100644 --- a/configure.ac +++ b/configure.ac @@ -1515,7 +1515,6 @@ AC_CONFIG_FILES([ Makefile - build/Makefile distro/Makefile distro/systemd/Makefile doc/Makefile diff --git a/build/ltrc.inc b/ltrc.inc similarity index 100% rename from build/ltrc.inc rename to ltrc.inc diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index b953961..1dc1dda 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -9,7 +9,7 @@ # Copyright (C) 2006-2012 Alon Bar-Lev # -include $(top_srcdir)/build/ltrc.inc +include $(top_srcdir)/ltrc.inc MAINTAINERCLEANFILES =3D \ $(srcdir)/Makefile.in diff --git a/src/openvpnmsica/Makefile.am b/src/openvpnmsica/Makefile.am index dc53f75..b10ce82 100644 --- a/src/openvpnmsica/Makefile.am +++ b/src/openvpnmsica/Makefile.am @@ -18,7 +18,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -include $(top_srcdir)/build/ltrc.inc +include $(top_srcdir)/ltrc.inc MAINTAINERCLEANFILES =3D $(srcdir)/Makefile.in diff --git a/src/openvpnserv/Makefile.am b/src/openvpnserv/Makefile.am index d8ba4eb..0c64cce 100644 --- a/src/openvpnserv/Makefile.am +++ b/src/openvpnserv/Makefile.am @@ -9,7 +9,7 @@ # Copyright (C) 2006-2012 Alon Bar-Lev # -include $(top_srcdir)/build/ltrc.inc +include $(top_srcdir)/ltrc.inc MAINTAINERCLEANFILES =3D $(srcdir)/Makefile.in diff --git a/src/tapctl/Makefile.am b/src/tapctl/Makefile.am index 69ea161..4c2958b 100644 --- a/src/tapctl/Makefile.am +++ b/src/tapctl/Makefile.am @@ -18,7 +18,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -include $(top_srcdir)/build/ltrc.inc +include $(top_srcdir)/ltrc.inc MAINTAINERCLEANFILES =3D $(srcdir)/Makefile.in -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/501?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ib1a5c788269949d8de95d1da2cb0c32a65bf13f2 Gerrit-Change-Number: 501 Gerrit-PatchSet: 1 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --gVhIYovbJSI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

d12fk would like plaisthos and flichtenheld to review t= his change.

Vi= ew Change

cmake: symlink whole build dir not just .json file

It = turned out that symlinking compile_commands.json from the top level
sour= ce dir has some issues:
* file is not created on Windows and symlinkin= g may cause an error
* some IDEs create their own json and error out b= /c a file exists

Since clangd also looks for the json in build/ dire= ctories by default,
we now symlink the whole build directory instead, no= t just the json file.

This approach requires for the existing build/= dir in the repo to
vanish. Luckily it only contains one automake includ= e file, which is
moved to the top level source dir.

Lastly, make = this an opt-in feature, so that the default configuration
of the buildsy= stem never causes a build failure because of this.

Change-Id: Ib1a5c= 788269949d8de95d1da2cb0c32a65bf13f2
Signed-off-by: Heiko Hund <heiko@= ...2662...>
---
M .gitignore
M CMakeLists.txt
M Makefile.am<= br>M README.cmake.md
D build/Makefile.am
M configure.ac
R ltrc.inc=
M src/openvpn/Makefile.am
M src/openvpnmsica/Makefile.am
M src/op= envpnserv/Makefile.am
M src/tapctl/Makefile.am
11 files changed, 32 i= nsertions(+), 25 deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/01/501/1
diff --git a/.gitignore b/.gitig=
nore
index 4153a3e..92d65bf 100644
--- a/.g= itignore
+++ b/.gitignore
@@ -40,7 +40,7 @@=
m4/ltversion.m4
m4/lt~obsolete.m4=

-compile_co= mmands.json
+build
doc/openvpn-examples.5
doc/openvpn-examples= .5.html
doc/openvpn.8
diff --git a/CMakeLi= sts.txt b/CMakeLists.txt
index bc46c27..4e5c8fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,9 +43,17 @@
set(PLUGIN_DIR /usr/local/li= b/openvpn/plugins CACHE FILEPATH "Location of the plugin directory&quo= t;)

# Create machine readable compile co= mmands
-set(CMAKE_EXPOR= T_COMPILE_COMMANDS 1)
-= file(CREATE_LINK ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json- ${CMAKE_CURRE= NT_SOURCE_DIR}/compile_commands.json SYMBOLIC)
+option(ENABLE_COMPILE_COMMANDS "Generate co= mpile_commands.json and a symlink for clangd to find it" OFF)+if (ENABLE_COMPILE_COMMANDS)=
+ if (EXISTS ${CM= AKE_CURRENT_SOURCE_DIR}/build AND NOT IS_SYMLINK ${CMAKE_CURRENT_SOURCE_DIR= }/build)
+ mes= sage(FATAL_ERROR "The top level source directory contains a 'build= ' file or directory. Please remove or rename it. CMake creates a symlin= k with that name during build.")
+ endif()
+ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
+ add_custom_target(
+ symlink-build-dir ALL
<= span style=3D"color: hsl(120, 100%, 40%);">+ ${CMAKE_COMMAND} -E cre= ate_symlink ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/build
+ )
<= span style=3D"color: hsl(120, 100%, 40%);">+endif ()


# AddressSanitize - use CXX=3Dclang++ CC=3Dclang cmake -DCMAKE= _BUILD_TYPE=3Dasan to build with ASAN
set(CMAKE_C_FLAGS_AS= AN
diff --git a/Makefile.am b/Makefile.am
i= ndex 2305ab4..792588a 100644
--- a/Makefile.am
+++ b/Makefile.am

@@ -42,6 +42,7 @@
EX= TRA_DIST =3D \
contrib \
debug \=
+ ltrc.inc \
CMakeLists.txt \

CMakePresets.json \
= config.h.cmake.in
@@ -53,7 +54,7 @@
con= fig-version.h
endif

-SUBDIRS =3D build distro include src sampl= e doc tests
+SUBDIRS = =3D distro include src sample doc tests

= dist_doc_DATA =3D \
README \
diff --git a= /README.cmake.md b/README.cmake.md
index d181b64..4f41c70 1= 00644
--- a/README.cmake.md
+++ b/README.cm= ake.md
@@ -135,3 +135,17 @@
The `unix-nati= ve` CMake preset is available for these builds. This preset does
= not require VCPKG and instead assumes all build-dependencies are pro= vided by
the system natively.
+
+Generating compile_commands.json
+--------------------------------
+
+To have the CMake buildsystem generate compile_commands.json= you can specify
+`-D= ENABLE_COMPILE_COMMANDS=3DON` on the command line or enable the CMake optio= n
+another way you li= ke. For supported generators the file will then be created.
+Additionally, the buildsystem will = create a symlink `build/` to the --preset

+build directory that contains the generated JSON file= . This is done so that
+
+Enabling = this option may cause an error on Windows, since creating a symlink<= br>+is a privileged operation t= here. If you enable Developer Mode for the system,
+symlinks can be created by regular users.
diff --git a/build/Makefile.am b/build/Makefile.am
= deleted file mode 100644
index e7cc4d8..0000000
--- a/build/Makefile.am
+++ /dev/null
= @@ -1,15 +0,0 @@
= -#
-# OpenVPN -- An ap= plication to securely tunnel IP networks
-# over a single UDP port, with support for S= SL/TLS-based
-# = session authentication and key exchange,
-# packet encryption, packet authenticat= ion, and
-# = packet compression.
-#=
-# Copyright (C) 2002= -2023 OpenVPN Inc <sales@...515...>
-#
-=
-MAINTAINERCLEANFILES = =3D \
- $(srcdir)/Makef= ile.in
-
-EXTRA_DIST =3D \

- ltrc.inc
diff --git a/co= nfigure.ac b/configure.ac
index 2823f04..0710f71 100644
--- a/configure.ac
+++ b/configure.ac@@ -1515,7 +1515,6 @@

AC_CONFIG_= FILES([
Makefile
- build/Makefile
distro/Makefile
distro/systemd/Makefile

doc/Makefile
diff --git a/build/ltrc.inc b/ltrc.inc

similarity index 1= 00%
rename from build/ltrc.inc
rename to lt= rc.inc
diff --git a/src/openvpn/Makefile.am b/src/openvpn/M= akefile.am
index b953961..1dc1dda 100644
--= - a/src/openvpn/Makefile.am
+++ b/src/openvpn/Makefile.am
@@ -9,7 +9,7 @@
# Copyright (C) 2006-2012 = Alon Bar-Lev <alon.barlev@...277...>
#

-include $(top_src= dir)/build/ltrc.inc
+= include $(top_srcdir)/ltrc.inc

MAINTAINE= RCLEANFILES =3D \
$(srcdir)/Makefile.in
d= iff --git a/src/openvpnmsica/Makefile.am b/src/openvpnmsica/Makefile.am
index dc53f75..b10ce82 100644
--- a/src/openvp= nmsica/Makefile.am
+++ b/src/openvpnmsica/Makefile.am
@@ -18,7 +18,7 @@
# 51 Franklin Street, Fifth = Floor, Boston, MA 02110-1301 USA.
#

-include $(top_srcdir)/buil= d/ltrc.inc
+include $= (top_srcdir)/ltrc.inc

MAINTAINERCLEANFIL= ES =3D $(srcdir)/Makefile.in

diff --git a= /src/openvpnserv/Makefile.am b/src/openvpnserv/Makefile.am
= index d8ba4eb..0c64cce 100644
--- a/src/openvpnserv/Makefil= e.am
+++ b/src/openvpnserv/Makefile.am
@@ -= 9,7 +9,7 @@
# Copyright (C) 2006-2012 Alon Bar-Lev <al= on.barlev@...277...>
#

-include $(top_srcdir)/build/ltrc.inc=

+include $(top_srcdi= r)/ltrc.inc

MAINTAINERCLEANFILES =3D $(s= rcdir)/Makefile.in

diff --git a/src/tapct= l/Makefile.am b/src/tapctl/Makefile.am
index 69ea161..4c295= 8b 100644
--- a/src/tapctl/Makefile.am
+++ = b/src/tapctl/Makefile.am
@@ -18,7 +18,7 @@
= # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
<= span> #


-include $(top_srcdir)/build/ltrc.inc
+include $(top_srcdir)/ltrc.inc

MAINTAINERCLEANFILES =3D $(srcdir)/Makefile.in
=

To view, visit change 501. To unsubscribe,= or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib1a5c788269949d8de95d1da2cb= 0c32a65bf13f2
Gerrit-Change-Number: 501
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--gVhIYovbJSI=--