Subject: cmake. Was: USE_TOOLS=imake versus USE_IMAKE
To: None <tech-pkg@netbsd.org>
From: Mark Davies <mark@mcs.vuw.ac.nz>
List: tech-pkg
Date: 12/05/2007 02:05:48
--Boundary-00=_sCVVH2TnnN3DvXA
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
On Saturday 01 December 2007 08:55:37 Johnny C. Lam wrote:
> USE_TOOLS+=imake means the package uses the tool during "some part
> of the build", whether that be the configure stage or the build
> stage or whatever. Some packages have GNU configure scripts that
> (inexplicably) call imake or xmkmf for some (stupid) reasons known
> only to the authors.
>
> USE_IMAKE means that the package uses the *.cf files to build
> Makefiles in the configure stage that are used in the build and
> install phases. These types of packages are "X11" packages that
> rely on those silly *.cf files for path information.
>
> USE_IMAKE does imply USE_TOOLS+=imake while the converse is not
> true.
I thought that was what I said, just not as precisely.
Anyway, on a vaguely related matter: As cmake is now being used to
configure/build an increasing number of packages (most obviously
KDE4) I've been looking at adding support for it to pkgsrc.
I've added cmake as a tool for those packages that use it during "some
part of the build" and, analogous to imake, USE_CMAKE=yes for when
cmake is used in the configure stage to produce the Makefiles used in
the build and install phases.
CMAKE_ARGS is the list of arguments passed to cmake and CMAKE_ARG_PATH
is the path to the top of the build relative to CONFIGURE_DIRS
(defaults to "."). So by appropriately setting CONFIGURE_DIRS and
CMAKE_ARG_PATH its possible to do builds in a directory separate from
the source, which is cmake's preferred way.
There is some initial work to get cmake to play nice with buildlink,
overriding its default paths to search for includes and libs but
thats tricky as individual packages are prone to add extra paths to
search in ways that are difficult to catch generically. So currently
cmake is still quite prone to find things that happen to be installed
on your system rather than just those buildlinked but I think the
framework is there to improve that once get more of a feel for
precisely how it works.
Attached are the patches. Comments?
I'd like to commit this soon so I can commit to wip some packages that
make use of it.
cheers
mark
--Boundary-00=_sCVVH2TnnN3DvXA
Content-Type: text/x-diff;
charset="iso-8859-1";
name="diffs"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="diffs"
Index: mk/configure/configure.mk
===================================================================
RCS file: /src/cvs/netbsd/pkgsrc/mk/configure/configure.mk,v
retrieving revision 1.19
diff -u -r1.19 configure.mk
--- mk/configure/configure.mk 1 Nov 2007 08:37:24 -0000 1.19
+++ mk/configure/configure.mk 4 Dec 2007 12:15:27 -0000
@@ -48,14 +48,17 @@
_USER_VARS.configure= CONFIG_SHELL_FLAGS
_PKG_VARS.configure= CONFIGURE_ENV CONFIG_SHELL CONFIGURE_SCRIPT \
CONFIGURE_ARGS OVERRIDE_GNU_CONFIG_SCRIPTS HAS_CONFIGURE \
- GNU_CONFIGURE PKGCONFIG_OVERRIDE USE_PKGLOCALEDIR
+ GNU_CONFIGURE PKGCONFIG_OVERRIDE USE_PKGLOCALEDIR \
+ CMAKE_ARGS CMAKE_ARG_PATH
CONFIGURE_SCRIPT?= ./configure
CONFIGURE_ENV+= ${ALL_ENV}
CONFIGURE_ARGS?= # empty
CONFIG_SHELL?= ${SH}
CONFIG_SHELL_FLAGS?= # none
-_BUILD_DEFS+= CONFIGURE_ENV CONFIGURE_ARGS
+CMAKE_ARGS?= # empty
+CMAKE_ARG_PATH?= .
+_BUILD_DEFS+= CONFIGURE_ENV CONFIGURE_ARGS CMAKE_ARGS
.if defined(GNU_CONFIGURE)
. include "${PKGSRCDIR}/mk/configure/gnu-configure.mk"
@@ -76,6 +79,9 @@
.if defined(USE_PKGLOCALEDIR)
. include "${PKGSRCDIR}/mk/configure/replace-localedir.mk"
.endif
+.if defined(USE_CMAKE)
+. include "${PKGSRCDIR}/mk/configure/cmake.mk"
+.endif
######################################################################
### configure (PUBLIC)
@@ -223,6 +229,25 @@
.endfor
######################################################################
+### do-configure-cmake (PRIVATE)
+######################################################################
+### do-configure-cmake runs cmake to configure the software for
+### building.
+###
+_CONFIGURE_CMAKE_ENV+= BUILDLINK_DIR=${BUILDLINK_DIR}
+_CONFIGURE_CMAKE_ENV+= ${CONFIGURE_ENV}
+
+
+.PHONY: do-configure-cmake
+do-configure-cmake:
+.for _dir_ in ${CONFIGURE_DIRS}
+ ${_PKG_SILENT}${_PKG_DEBUG}${_ULIMIT_CMD} \
+ cd ${WRKSRC} && cd ${_dir_} && \
+ ${SETENV} ${_CONFIGURE_CMAKE_ENV} \
+ cmake ${CMAKE_ARGS} ${CMAKE_ARG_PATH}
+.endfor
+
+######################################################################
### pre-configure, do-configure, post-configure (PUBLIC, override)
######################################################################
### {pre,do,post}-configure are the heart of the package-customizable
@@ -232,6 +257,7 @@
_DO_CONFIGURE_TARGETS+= ${HAS_CONFIGURE:D do-configure-script}
_DO_CONFIGURE_TARGETS+= ${USE_IMAKE:D do-configure-imake}
+_DO_CONFIGURE_TARGETS+= ${USE_CMAKE:D do-configure-cmake}
.if !target(do-configure)
do-configure: ${_DO_CONFIGURE_TARGETS}
Index: mk/tools/defaults.mk
===================================================================
RCS file: /src/cvs/netbsd/pkgsrc/mk/tools/defaults.mk,v
retrieving revision 1.52
diff -u -r1.52 defaults.mk
--- mk/tools/defaults.mk 10 Aug 2007 03:46:10 -0000 1.52
+++ mk/tools/defaults.mk 4 Dec 2007 12:13:09 -0000
@@ -63,6 +63,7 @@
_TOOLS_VARNAME.chgrp= CHGRP
_TOOLS_VARNAME.chmod= CHMOD
_TOOLS_VARNAME.chown= CHOWN
+_TOOLS_VARNAME.cmake= CMAKE
_TOOLS_VARNAME.cmp= CMP
_TOOLS_VARNAME.cp= CP
_TOOLS_VARNAME.csh= CSH
Index: mk/tools/replace.mk
===================================================================
RCS file: /src/cvs/netbsd/pkgsrc/mk/tools/replace.mk,v
retrieving revision 1.201
diff -u -r1.201 replace.mk
--- mk/tools/replace.mk 8 Nov 2007 19:31:40 -0000 1.201
+++ mk/tools/replace.mk 4 Dec 2007 12:13:02 -0000
@@ -283,6 +283,17 @@
. endif
.endfor
+.if !defined(TOOLS_IGNORE.cmake) && !empty(_USE_TOOLS:Mcmake)
+. if !empty(PKGPATH:Mdevel/cmake)
+MAKEFLAGS+= TOOLS_IGNORE.cmake=
+. elif !empty(_TOOLS_USE_PKGSRC.cmake:M[yY][eE][sS])
+TOOLS_DEPENDS.cmake?= cmake>=2.4.6nb3:../../devel/cmake
+TOOLS_CREATE+= cmake
+TOOLS_FIND_PREFIX+= TOOLS_PREFIX.cmake=cmake
+TOOLS_PATH.cmake= ${TOOLS_PREFIX.cmake}/bin/cmake
+. endif
+.endif
+
.if !defined(TOOLS_IGNORE.csh) && !empty(_USE_TOOLS:Mcsh)
. if !empty(PKGPATH:Mshells/tcsh)
MAKEFLAGS+= TOOLS_IGNORE.csh=
--- /dev/null 2007-12-05 01:58:36.000000000 +1300
+++ mk//configure/cmake.mk 2007-12-05 01:15:35.000000000 +1300
@@ -0,0 +1,76 @@
+# $NetBSD$
+
+USE_TOOLS+= cmake
+CMAKE_ARGS+= -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX}
+CMAKE_ARGS+= -DCMAKE_MODULE_PATH:PATH=${PKGSRCDIR}/mk/cmake-Modules
+
+CMAKE_MODULE_PATH_OVERRIDE?= # empty
+
+CMAKE_MODULE_PATH_OVERRIDE+= CMakeLists.txt
+
+######################################################################
+### configure-cmake-override (PRIVATE)
+######################################################################
+### configure-cmake-override modifies the cmake CMakeLists.txt file in
+### ${WRKSRC} so that if CMAKE_MODULE_PATH is set we add our Module
+### directory before any others.
+###
+
+SUBST_CLASSES+= cmake
+SUBST_STAGE.cmake= do-configure-pre-hook
+SUBST_MESSAGE.cmake= Fixing CMAKE_MODULE_PATH in CMakeLists.txt
+SUBST_FILES.cmake= ${CMAKE_MODULE_PATH_OVERRIDE}
+SUBST_SED.cmake= \
+ 's|set *( *CMAKE_MODULE_PATH |set (CMAKE_MODULE_PATH "${PKGSRCDIR}/mk/cmake-Modules" |'
+
+######################################################################
+### cmake-dependencies-rewrite (PRIVATE)
+######################################################################
+### The cmake function export_library_dependencies() writes out
+### library dependency info to a file and this may contain buildlink
+### paths.
+### cmake-dependencies-rewrite modifies any such files, listed in
+### ${CMAKE_DEPENDENCIES_REWRITE} (relative to ${WRKSRC}) to have the
+### real dependencies
+###
+
+do-configure-post-hook: cmake-dependencies-rewrite
+
+_SCRIPT.cmake-dependencies-rewrite= \
+ ${AWK} '{ \
+ match($$0, "_LIB_DEPENDS \""); \
+ if (RSTART == 0) { \
+ print; \
+ } else { \
+ printf "%s \"", $$1; \
+ d=substr($$0,RSTART+RLENGTH,length($$0));\
+ while ( d != "\")") { \
+ match(d,"[^;]*"); \
+ dep=substr(d,RSTART,RLENGTH); \
+ d=substr(d,RLENGTH+2,length(d));\
+ if (dep ~ "^${BUILDLINK_DIR}") { \
+ "ls -l " dep | getline ls_out;\
+ match(ls_out,"-> "); \
+ if (RSTART > 0) { \
+ dep=substr(ls_out,RSTART+RLENGTH,length(ls_out)); \
+ } \
+ } \
+ printf "%s;",dep; \
+ } \
+ print d; \
+ } \
+ }' $$file > $$file.override; \
+ ${MV} -f $$file.override $$file
+
+
+.PHONY: cmake-dependencies-rewrite
+cmake-dependencies-rewrite:
+ @${STEP_MSG} "Rewrite cmake Dependencies files"
+.if defined(CMAKE_DEPENDENCIES_REWRITE) && !empty(CMAKE_DEPENDENCIES_REWRITE)
+ ${_PKG_SILENT}${_PKG_DEBUG}set -e; \
+ cd ${WRKSRC}; \
+ for file in ${CMAKE_DEPENDENCIES_REWRITE}; do \
+ ${TEST} -f "$$file" || continue; \
+ ${_SCRIPT.${.TARGET}}; \
+ done
+.endif
--- /dev/null 2007-12-05 01:58:36.000000000 +1300
+++ mk/cmake-Modules/Platform/UnixPaths.cmake 2007-12-05 02:00:48.000000000 +1300
@@ -0,0 +1,14 @@
+SET(CMAKE_SYSTEM_INCLUDE_PATH ${CMAKE_SYSTEM_INCLUDE_PATH}
+ # Standard
+ $ENV{BUILDLINK_DIR}/include /include /usr/include
+
+ )
+
+SET(CMAKE_SYSTEM_LIBRARY_PATH ${CMAKE_SYSTEM_LIBRARY_PATH}
+ # Standard
+ $ENV{BUILDLINK_DIR}/lib /lib /usr/lib
+ )
+
+SET(CMAKE_SYSTEM_PROGRAM_PATH ${CMAKE_SYSTEM_PROGRAM_PATH}
+ /bin /usr/bin /usr/local/bin /usr/pkg/bin /sbin
+ )
--Boundary-00=_sCVVH2TnnN3DvXA--