tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

cmake: (better) build dir support



Hi!

The cmake build tool prefers building in a separate build directory.
(Actually, autotools also recommends this, but it's not enforced,
cmake sometimes does.)

Lots of packages have a manual workaround that creates a build
directory in pre-configure. I would like to fold this into the
infrastructure, but I'm not quite sure how this should interact with
the CONFIGURE_DIRS/BUILD_DIRS variables.

I tend to just disallow the combination.

A basic untested patch is attached, this is just for getting some
ideas.

Thanks,
 Thomas
Index: configure/cmake.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/configure/cmake.mk,v
retrieving revision 1.20
diff -u -r1.20 cmake.mk
--- configure/cmake.mk	12 Aug 2020 14:10:11 -0000	1.20
+++ configure/cmake.mk	7 Oct 2020 20:40:49 -0000
@@ -1,10 +1,16 @@
 # $NetBSD: cmake.mk,v 1.20 2020/08/12 14:10:11 schmonz Exp $
 #
 # This file handles packages that use CMake as their primary build
-# system. For more information about CMake, see http://www.cmake.org/.
+# system. For more information about CMake, see https://cmake.org/.
 #
 # Package-settable variables:
 #
+# CMAKE_BUILD_DIR
+#	Directory to use for out-of-source-tree builds of cmake,
+#	i.e. the working directory where cmake writes its output files.
+#	Relative path below ${WRKRC}.
+#	Defaults to "build".
+#
 # CMAKE_DEPENDENCIES_REWRITE
 #	A list of files (XXX: variable name) relative to WRKSRC in
 #	which, after configuring the package, buildlink3 dependencies
@@ -45,6 +51,8 @@
 
 _CMAKE_DIR=	${BUILDLINK_DIR}/cmake-Modules
 
+CMAKE_BUILD_DIR?=		build
+
 CMAKE_USE_GNU_INSTALL_DIRS?=	yes
 
 CMAKE_INSTALL_PREFIX?=	${PREFIX}
@@ -96,6 +104,7 @@
 do-configure-pre-hook: __cmake-copy-module-tree
 __cmake-copy-module-tree: .PHONY
 	${RUN} cd ${PKGSRCDIR}/mk; ${CP} -R cmake-Modules ${_CMAKE_DIR}
+	${RUN} ${MKDIR} -p ${WRKSRC}/${CMAKE_BUILD_DIR}
 
 ### The cmake function export_library_dependencies() writes out
 ### library dependency info to a file and this may contain buildlink
Index: configure/configure.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/configure/configure.mk,v
retrieving revision 1.31
diff -u -r1.31 configure.mk
--- configure/configure.mk	23 Feb 2020 20:24:46 -0000	1.31
+++ configure/configure.mk	7 Oct 2020 20:40:49 -0000
@@ -245,12 +245,14 @@
 
 .PHONY: do-configure-cmake
 do-configure-cmake:
-.for _dir_ in ${CONFIGURE_DIRS}
+.if ${CONFIGURE_DIRS:[#]} != 1
+	${ECHO} multiple CONFIGURE_DIRS not supported by the cmake build infrastructure
+	${ECHO} please report this issue to the tech-pkg mailing list
+.endif
 	${RUN}${_ULIMIT_CMD}						\
-	cd ${WRKSRC} && cd ${_dir_} &&					\
+	cd ${WRKSRC}/${CMAKE_BUILD_DIR} &&				\
 	${PKGSRC_SETENV} ${_CONFIGURE_CMAKE_ENV}			\
-		cmake ${CMAKE_ARGS} ${CMAKE_ARG_PATH}
-.endfor
+		cmake ${CMAKE_ARGS} ${WRKSRC}/${CMAKE_ARG_PATH}
 
 ######################################################################
 ### pre-configure, do-configure, post-configure (PUBLIC, override)


Home | Main Index | Thread Index | Old Index