Skip to contentSkip to conversation

Change in openvpn[master]: CMake: detect cmocka_version.h via include path, not by linking

Openvpn-devel In review stipa (Code Review) via Openvpn-devel 3 participants 6 messages Jun 29 – Jul 13 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1782719911000.Icc14b286f2409738c73873aa7550dcc005ee8cbb@gerrit.openvpn.net

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email

to review the following change.

Change subject: CMake: detect cmocka_version.h via include path, not by linking
......................................................................

CMake: detect cmocka_version.h via include path, not by linking

check_include_files() was invoked with cmocka in CMAKE_REQUIRED_LIBRARIES, which makes the probe link the (shared, imported) cmocka library. On some platforms that link step fails inside the minimal probe, so the header check reports failure and HAVE_CMOCKA_VERSION_H is left undefined even though cmocka_version.h is present.

test_common.h then selects its cmocka 1.x compatibility shims and redefines macros (check_expected_uint, expect_uint_value, ...) that cmocka 2.x already provides, which breaks the -Werror build of every unit test driver.

Detecting a header only needs the include search path, so pass cmocka's INTERFACE_INCLUDE_DIRECTORIES via CMAKE_REQUIRED_INCLUDES and drop the library link requirement from the probe.

Change-Id Icc14b286f2409738c73873aa7550dcc005ee8cbb

---
M CMakeLists.txt

1 file changed, 9 insertions(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/1739/1

CMakeLists.txt +9 -1
index 4779d69..8de836a 100644
@@ -385,12 +385,20 @@
     find_package(cmocka CONFIG)
     if (TARGET cmocka::cmocka)
         set(CMOCKA_LIBRARIES cmocka::cmocka)
+        get_target_property(CMOCKA_INCLUDE_DIRS cmocka::cmocka INTERFACE_INCLUDE_DIRECTORIES)
     else ()
         pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET)
         set(CMOCKA_LIBRARIES PkgConfig::cmocka)
+        set(CMOCKA_INCLUDE_DIRS ${cmocka_INCLUDE_DIRS})
     endif ()
-    set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES})
+    # cmocka_version.h exists since cmocka 2.0; its absence selects the
+    # cmocka 1.x compat shims in test_common.h. Detecting a header only needs
+    # the include path - do NOT add cmocka to CMAKE_REQUIRED_LIBRARIES, as that
+    # makes check_include_files link the shared library, which can fail in the
+    # probe for unrelated reasons and wrongly mis-detect cmocka 2.x as < 2.0.
+    set(CMAKE_REQUIRED_INCLUDES ${CMOCKA_INCLUDE_DIRS})
     check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H)
+    unset(CMAKE_REQUIRED_INCLUDES)
 endif ()
 
 configure_file(config.h.cmake.in config.h)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icc14b286f2409738c73873aa7550dcc005ee8cbb
Gerrit-Change-Number: 1739
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos, stipa.

flichtenheld has posted comments on this change by stipa. ( http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email )

Change subject: CMake: detect cmocka_version.h via include path, not by linking
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icc14b286f2409738c73873aa7550dcc005ee8cbb
Gerrit-Change-Number: 1739
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-Attention: stipa <[email protected]>
Gerrit-Comment-Date: Wed, 08 Jul 2026 15:38:00 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#3 lore raw

PATCH 1/1 CMake: detect cmocka_version.h via include path, not by linking

In reply to a message not in the archive

From: Lev Stipakov <[email protected]>

check_include_files() was invoked with cmocka in CMAKE_REQUIRED_LIBRARIES, which makes the probe link the (shared, imported) cmocka library. On some platforms that link step fails inside the minimal probe, so the header check reports failure and HAVE_CMOCKA_VERSION_H is left undefined even though cmocka_version.h is present.

test_common.h then selects its cmocka 1.x compatibility shims and redefines macros (check_expected_uint, expect_uint_value, ...) that cmocka 2.x already provides, which breaks the -Werror build of every unit test driver.

Detecting a header only needs the include search path, so pass cmocka's INTERFACE_INCLUDE_DIRECTORIES via CMAKE_REQUIRED_INCLUDES and drop the library link requirement from the probe.

Change-Id Icc14b286f2409738c73873aa7550dcc005ee8cbb

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1739
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1739
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]>

CMakeLists.txt +9 -1
index 4779d69..8de836a 100644
@@ -385,12 +385,20 @@
     find_package(cmocka CONFIG)
     if (TARGET cmocka::cmocka)
         set(CMOCKA_LIBRARIES cmocka::cmocka)
+        get_target_property(CMOCKA_INCLUDE_DIRS cmocka::cmocka INTERFACE_INCLUDE_DIRECTORIES)
     else ()
         pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET)
         set(CMOCKA_LIBRARIES PkgConfig::cmocka)
+        set(CMOCKA_INCLUDE_DIRS ${cmocka_INCLUDE_DIRS})
     endif ()
-    set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES})
+    # cmocka_version.h exists since cmocka 2.0; its absence selects the
+    # cmocka 1.x compat shims in test_common.h. Detecting a header only needs
+    # the include path - do NOT add cmocka to CMAKE_REQUIRED_LIBRARIES, as that
+    # makes check_include_files link the shared library, which can fail in the
+    # probe for unrelated reasons and wrongly mis-detect cmocka 2.x as < 2.0.
+    set(CMAKE_REQUIRED_INCLUDES ${CMOCKA_INCLUDE_DIRS})
     check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H)
+    unset(CMAKE_REQUIRED_INCLUDES)
 endif ()
 
 configure_file(config.h.cmake.in config.h)

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Acked-by Frank Lichtenheld on v1 1/1
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: CMake: detect cmocka_version.h via include path, not by linking

"Build stuff, for the unit tests", so not directly code affecting and not scrutinized further - if Lev and Frank say this is good, make it so :-)

Your patch has been applied to the master and release/2.7 branch ("build environment / testing improvements").

commit 2c2fec4a965cf046b3d71b3250f8d84f6af81b89 (master) commit b6b6af3d7c70f56a3a51f042ba7fe57f8d96e345 (release/2.7)

Author: Lev Stipakov
Date:   Thu Jul 9 16:42:40 2026 +0200

CMake: detect cmocka_version.h via include path, not by linking

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1739
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37552.html

--
kind regards,

Gert Doering

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by stipa. ( http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: CMake: detect cmocka_version.h via include path, not by linking
......................................................................

CMake: detect cmocka_version.h via include path, not by linking

check_include_files() was invoked with cmocka in CMAKE_REQUIRED_LIBRARIES, which makes the probe link the (shared, imported) cmocka library. On some platforms that link step fails inside the minimal probe, so the header check reports failure and HAVE_CMOCKA_VERSION_H is left undefined even though cmocka_version.h is present.

test_common.h then selects its cmocka 1.x compatibility shims and redefines macros (check_expected_uint, expect_uint_value, ...) that cmocka 2.x already provides, which breaks the -Werror build of every unit test driver.

Detecting a header only needs the include search path, so pass cmocka's INTERFACE_INCLUDE_DIRECTORIES via CMAKE_REQUIRED_INCLUDES and drop the library link requirement from the probe.

Change-Id Icc14b286f2409738c73873aa7550dcc005ee8cbb

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1739
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37552.html

---
M CMakeLists.txt

1 file changed, 9 insertions(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/1739/2

CMakeLists.txt +9 -1
index 4779d69..8de836a 100644
@@ -385,12 +385,20 @@
     find_package(cmocka CONFIG)
     if (TARGET cmocka::cmocka)
         set(CMOCKA_LIBRARIES cmocka::cmocka)
+        get_target_property(CMOCKA_INCLUDE_DIRS cmocka::cmocka INTERFACE_INCLUDE_DIRECTORIES)
     else ()
         pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET)
         set(CMOCKA_LIBRARIES PkgConfig::cmocka)
+        set(CMOCKA_INCLUDE_DIRS ${cmocka_INCLUDE_DIRS})
     endif ()
-    set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES})
+    # cmocka_version.h exists since cmocka 2.0; its absence selects the
+    # cmocka 1.x compat shims in test_common.h. Detecting a header only needs
+    # the include path - do NOT add cmocka to CMAKE_REQUIRED_LIBRARIES, as that
+    # makes check_include_files link the shared library, which can fail in the
+    # probe for unrelated reasons and wrongly mis-detect cmocka 2.x as < 2.0.
+    set(CMAKE_REQUIRED_INCLUDES ${CMOCKA_INCLUDE_DIRS})
     check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H)
+    unset(CMAKE_REQUIRED_INCLUDES)
 endif ()
 
 configure_file(config.h.cmake.in config.h)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icc14b286f2409738c73873aa7550dcc005ee8cbb
Gerrit-Change-Number: 1739
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email )

Change subject: CMake: detect cmocka_version.h via include path, not by linking
......................................................................

CMake: detect cmocka_version.h via include path, not by linking

check_include_files() was invoked with cmocka in CMAKE_REQUIRED_LIBRARIES, which makes the probe link the (shared, imported) cmocka library. On some platforms that link step fails inside the minimal probe, so the header check reports failure and HAVE_CMOCKA_VERSION_H is left undefined even though cmocka_version.h is present.

test_common.h then selects its cmocka 1.x compatibility shims and redefines macros (check_expected_uint, expect_uint_value, ...) that cmocka 2.x already provides, which breaks the -Werror build of every unit test driver.

Detecting a header only needs the include search path, so pass cmocka's INTERFACE_INCLUDE_DIRECTORIES via CMAKE_REQUIRED_INCLUDES and drop the library link requirement from the probe.

Change-Id Icc14b286f2409738c73873aa7550dcc005ee8cbb

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1739
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37552.html

---
M CMakeLists.txt

1 file changed, 9 insertions(+), 1 deletion(-)
CMakeLists.txt +9 -1
index 4779d69..8de836a 100644
@@ -385,12 +385,20 @@
     find_package(cmocka CONFIG)
     if (TARGET cmocka::cmocka)
         set(CMOCKA_LIBRARIES cmocka::cmocka)
+        get_target_property(CMOCKA_INCLUDE_DIRS cmocka::cmocka INTERFACE_INCLUDE_DIRECTORIES)
     else ()
         pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET)
         set(CMOCKA_LIBRARIES PkgConfig::cmocka)
+        set(CMOCKA_INCLUDE_DIRS ${cmocka_INCLUDE_DIRS})
     endif ()
-    set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES})
+    # cmocka_version.h exists since cmocka 2.0; its absence selects the
+    # cmocka 1.x compat shims in test_common.h. Detecting a header only needs
+    # the include path - do NOT add cmocka to CMAKE_REQUIRED_LIBRARIES, as that
+    # makes check_include_files link the shared library, which can fail in the
+    # probe for unrelated reasons and wrongly mis-detect cmocka 2.x as < 2.0.
+    set(CMAKE_REQUIRED_INCLUDES ${CMOCKA_INCLUDE_DIRS})
     check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H)
+    unset(CMAKE_REQUIRED_INCLUDES)
 endif ()
 
 configure_file(config.h.cmake.in config.h)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1739?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icc14b286f2409738c73873aa7550dcc005ee8cbb
Gerrit-Change-Number: 1739
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel