From: Lev Stipakov Date: Thu, 9 Jul 2026 14:42:40 +0000 (+0200) Subject: CMake: detect cmocka_version.h via include path, not by linking X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2c2fec4a965cf046b3d71b3250f8d84f6af81b89;p=thirdparty%2Fopenvpn.git 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 Signed-off-by: Lev Stipakov Acked-by: Frank Lichtenheld Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1739 Message-Id: <20260709144240.61362-1-frank@lichtenheld.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg37552.html Signed-off-by: Gert Doering --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4779d69a3..8de836a71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,12 +385,20 @@ if (BUILD_TESTING) 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)