tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: [PATCH] cmake/build.mk: Hide non-buildlink3 libraries from cmake
Revised cmake patch: this one sets CMAKE_PREFIX_PATH,
CMAKE_INCLUDE_PATH, and CMAKE_LIBRARY_PATH as environment variables
rather than as cmake variables.
The difference is that the cmake variables are intended to be set by
the project (i.e., the package being built), not by the end-user:
> By default this is empty. It is intended to be set by the project.
https://cmake.org/cmake/help/v3.31/variable/CMAKE_PREFIX_PATH.html#variable:CMAKE_PREFIX_PATH
And some projects, like print/scribus-qt5, do set CMAKE_PREFIX_PATH,
overriding whatever pkgsrc had set it to, leading to weird failures
like:
CMake Error at /pkg/2024Q4/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
Call Stack (most recent call first):
/pkg/2024Q4/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
/pkg/2024Q4/share/cmake-3.31/Modules/FindJPEG.cmake:107 (find_package_handle_standard_args)
CMakeLists_Dependencies.cmake:188 (find_package)
CMakeLists.txt:427 (include)
It is tempting to try to use CMAKE_SYSTEM_PREFIX_PATH instead of
CMAKE_PREFIX_PATH, but cmake's Platform/UnixPaths.cmake module
unconditionally fills CMAKE_SYSTEM_PREFIX_PATH with garbage. So
between the three options:
1. CMAKE_SYSTEM_PREFIX_PATH (env var or cmake var),
2. CMAKE_PREFIX_PATH env var, and
3. CMAKE_PREFIX_PATH cmake var,
it looks like only option (2) is safe for us to set _and_ safe to
expose; option (1) leads cmake to search in garbage locations and
option (3) may be overwritten by the project.
The attached updated patch series also tweaks qt5-qtbase/buildlink3.mk
files to put ${BUILDLINK_DIR}/qt5 rather than ${PREFIX}/qt5 into
CMAKE_PREFIX_PATH, and similarly for qt6. And it puts ${PREFIX} in
CMAKE_IGNORE_PREFIX_PATH to stop cmake from directly searching for any
files under ${PREFIX} (though it may still find things via, e.g.,
pkg-config).
With any luck, this should help resolve some of the fallout, other
than the Wayland -isystem/__STDC_VERSION__ issue which needs to be
addressed another way. I've kicked off another bulk build to see what
happens.
From 6989fc2a165e088de8fcf419226b99a99776a654 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Wed, 27 Nov 2024 03:57:19 +0000
Subject: [PATCH 1/3] devel/cmake/build.mk: Limit cmake's perspective to
buildlink3.
Hide LOCALBASE from cmake functions like find_package, find_path, &c.
But don't hide COMPILER_INCLUDE_DIRS and COMPILER_LIB_DIRS -- we only
want to hide undeclared pkgsrc packages, not system libraries.
Pass pkgsrc-defined CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH through
to cmake as environment variables rather than as cmake variables, and
do the same with CMAKE_PREFIX_PATH. This way, the project can define
its own paths -- as cmake intends -- without overriding pkgsrc's
BUILDLINK_DIR paths.
While here, set CMAKE_IGNORE_PREFIX_PATH to ignore ${LOCALBASE} in an
attempt to conceal it harder. It doesn't stop cmake from finding
things it shouldn't through paths exposed by pkg-config but it might
stop cmake from finding things it shouldn't by other paths like
projects putting ${PREFIX} or /usr/pkg in CMAKE_PREFIX_PATH
explicitly.
XXX Need to do a mass revbump of all packages that use cmake -- and
probably deal with a lot of fallout.
---
devel/cmake/build.mk | 7 +++++++
devel/cmake/configure-settings.mk | 21 ++++++++++++++++++++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/devel/cmake/build.mk b/devel/cmake/build.mk
index 6401528ab819..b825daa5e8e5 100644
--- a/devel/cmake/build.mk
+++ b/devel/cmake/build.mk
@@ -58,6 +58,13 @@ OPSYSVARS+= CMAKE_CONFIGURE_ARGS
# mid-build.
CMAKE_CONFIGURE_ARGS+= -DFETCHCONTENT_FULLY_DISCONNECTED=ON
+# Ensure cmake only looks in system files or in the sanitized buildlink
+# directory for find_package/program/library/file/path.
+CMAKE_CONFIGURE_ARGS+= -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH:BOOL=OFF
+CMAKE_CONFIGURE_ARGS+= -DCMAKE_IGNORE_PREFIX_PATH:STRING=${LOCALBASE}
+CMAKE_PREFIX_PATH+= ${BUILDLINK_DIR}
+CMAKE_INCLUDE_PATH+= ${COMPILER_INCLUDE_DIRS:@.d.@${_CROSS_DESTDIR:U}${.d.}@}
+CMAKE_LIBRARY_PATH+= ${COMPILER_LIB_DIRS:@.d.@${_CROSS_DESTDIR:U}${.d.}@}
CONFIGURE_ENV+= BUILDLINK_DIR=${BUILDLINK_DIR}
diff --git a/devel/cmake/configure-settings.mk b/devel/cmake/configure-settings.mk
index d3b2742dadb0..39ce720c9a9d 100644
--- a/devel/cmake/configure-settings.mk
+++ b/devel/cmake/configure-settings.mk
@@ -27,6 +27,12 @@
# buildlink3.mk so that packages that depend on it can find its
# cmake modules if they use cmake to build.
#
+# CMAKE_INCLUDE_PATH
+# Like CMAKE_PREFIX_PATH but just for include files.
+#
+# CMAKE_LIBRARY_PATH
+# Like CMAKE_PREFIX_PATH but just for libraries.
+#
# CMAKE_USE_GNU_INSTALL_DIRS
# If set to yes, set GNU standard installation directories with pkgsrc
# configured settings. The default is yes.
@@ -81,6 +87,19 @@ CMAKE_CONFIGURE_ARGS+= -DCMAKE_INSTALL_LOCALEDIR:PATH=${PKGLOCALEDIR}/locale
CMAKE_CONFIGURE_ARGS+= -DCMAKE_APPLE_SILICON_PROCESSOR=arm64
.endif
+# We define the environment variables CMAKE_PREFIX_PATH &c., rather
+# than cmake variables of the same name, because the environment
+# variables are meant to be set by the caller (e.g., packaging system),
+# while the cmake variables are meant to be set by the project (i.e.,
+# CMakeFiles.txt and similar), and some projects do set them.
.if defined(CMAKE_PREFIX_PATH)
-CMAKE_CONFIGURE_ARGS+= -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH:ts;:Q}
+CONFIGURE_ENV+= CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH:ts::Q}
+.endif
+
+.if defined(CMAKE_INCLUDE_PATH)
+CONFIGURE_ENV+= CMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH:ts::Q}
+.endif
+
+.if defined(CMAKE_LIBRARY_PATH)
+CONFIGURE_ENV+= CMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH:ts::Q}
.endif
From 1b1eaaa175055ad695d589cb007d298e459a3f08 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Thu, 16 Jan 2025 10:45:24 +0000
Subject: [PATCH 2/3] x11/qt5-qtbase: Put ${BUILDLINK_DIR}/qt5 into
CMAKE_PREFIX_PATH.
Don't put ${PREFIX}/qt5 there -- limit cmake's view to what is meant
to be exposed through buildlink.
---
x11/qt5-qtbase/buildlink3.mk | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/x11/qt5-qtbase/buildlink3.mk b/x11/qt5-qtbase/buildlink3.mk
index 2c81d9ff9ab7..0b7bb2bc89ac 100644
--- a/x11/qt5-qtbase/buildlink3.mk
+++ b/x11/qt5-qtbase/buildlink3.mk
@@ -13,8 +13,8 @@ BUILDLINK_INCDIRS.qt5-qtbase+= qt5/include
BUILDLINK_LIBDIRS.qt5-qtbase+= qt5/lib
BUILDLINK_LIBDIRS.qt5-qtbase+= qt5/plugins
-QTDIR= ${BUILDLINK_PREFIX.qt5-qtbase}/qt5
-CMAKE_PREFIX_PATH+= ${QTDIR}
+QTDIR= ${BUILDLINK_PREFIX.qt5-qtbase}/qt5
+CMAKE_PREFIX_PATH+= ${BUILDLINK_DIR}/qt5
CONFIGURE_ENV+= QTDIR=${QTDIR}
MAKE_ENV+= QTDIR=${QTDIR}
From b4a488384db031061f09b7fa98f10f8559a18cd0 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Thu, 16 Jan 2025 10:46:24 +0000
Subject: [PATCH 3/3] x11/qt6-qtbase: Put ${BUILDLINK_DIR}/qt6 into
CMAKE_PREFIX_PATH.
Don't put ${PREFIX}/qt6 there -- limit cmake's view to what is meant
to be exposed through buildlink.
---
x11/qt6-qtbase/buildlink3.mk | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/x11/qt6-qtbase/buildlink3.mk b/x11/qt6-qtbase/buildlink3.mk
index ca5ddb39e709..0e80818afe06 100644
--- a/x11/qt6-qtbase/buildlink3.mk
+++ b/x11/qt6-qtbase/buildlink3.mk
@@ -23,8 +23,8 @@ BUILDLINK_FILES.qt6-qtbase+= qt6/bin/*
BUILDLINK_FILES.qt6-qtbase+= qt6/libexec/*
# \todo Fix duplication with prefix coded in Makefile.common
-QTDIR= ${BUILDLINK_PREFIX.qt6-qtbase}/qt6
-CMAKE_PREFIX_PATH+= ${QTDIR}
+QTDIR= ${BUILDLINK_PREFIX.qt6-qtbase}/qt6
+CMAKE_PREFIX_PATH+= ${BUILDLINK_DIR}/qt6
# https://doc.qt.io/qt-6/supported-platforms.html
GCC_REQD+= 9
Home |
Main Index |
Thread Index |
Old Index