[Openvpn-devel] CMake: Throw a clear error when config.h in top-level source directory

Message ID 20230703153925.48990-1-frank@lichtenheld.com
State Accepted
Headers show
Series [Openvpn-devel] CMake: Throw a clear error when config.h in top-level source directory | expand

Commit Message

Frank Lichtenheld July 3, 2023, 3:39 p.m. UTC
This causes weird, difficult to debug compilation errors. Usually
caused by trying to run CMake against a source that had an
in-tree autoconfig build.

Note that you're able to do out-of-tree autoconfig builds and
they can obviously mix with out-of-tree cmake builds.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
---
 CMakeLists.txt | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Arne Schwabe July 4, 2023, 11:03 a.m. UTC | #1
Am 03.07.23 um 18:39 schrieb Frank Lichtenheld:
> This causes weird, difficult to debug compilation errors. Usually
> caused by trying to run CMake against a source that had an
> in-tree autoconfig build.
> 
> Note that you're able to do out-of-tree autoconfig builds and
> they can obviously mix with out-of-tree cmake builds.
> 

Acked-By: Arne Schwabe <arne@rfc2549.org>
Gert Doering July 4, 2023, 11:45 a.m. UTC | #2
Sounds & looks reasonable.  Not that I could really verify this, or have
tested it, but that's what we have an ACK from Arne for :-)

Your patch has been applied to the master branch.

commit 0652ae84f4528daa57da344eee28b7385a6659a1
Author: Frank Lichtenheld
Date:   Mon Jul 3 17:39:25 2023 +0200

     CMake: Throw a clear error when config.h in top-level source directory

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Arne Schwabe <arne@rfc2549.org>
     Message-Id: <20230703153925.48990-1-frank@lichtenheld.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26809.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index acebbb73..597dc907 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,10 @@  if (NOT WIN32 AND NOT ${UNSUPPORTED_BUILDS})
     message(FATAL_ERROR "Note: on Unix platform the official and supported build method is using autoconfig. CMake based build should be only used for Windows and internal testing/development.")
 endif()
 
+if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.h")
+    message(FATAL_ERROR "The top level source directory has a config.h file. Note that you can't mix in-tree autoconfig builds with out-of-tree cmake builds.")
+endif ()
+
 option(MBED "BUILD with mbed" OFF)
 option(WOLFSSL "BUILD with wolfSSL" OFF)
 option(ENABLE_LZ4 "BUILD with lz4" ON)