SUMMARY="A cross-platform build system"
DESCRIPTION="CMake is a family of tools designed to build, test and package \
software. It is used to control the software compilation process using \
simple platform and compiler independent configuration files. CMake generates \
native makefiles and workspaces that can be used in the compiler environment \
of your choice."
HOMEPAGE="https://cmake.org/"
COPYRIGHT="2002-2021 Kitware, Inc., Insight Consortium"
LICENSE="CMake"
REVISION="1"
SOURCE_URI="https://cmake.org/files/v3.22/cmake-$portVersion.tar.gz"
CHECKSUM_SHA256="3c1c478b9650b107d452c5bd545c72e2fad4e37c09b89a1984b9a2f46df6aced"
SOURCE_DIR="cmake-$portVersion"
PATCHES="cmake-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?x86 ?arm"
SECONDARY_ARCHITECTURES="x86"

portVersionCompat="$portVersion compat >= ${portVersion%%.*}"

PROVIDES="
	cmake$secondaryArchSuffix = $portVersionCompat
	cmd:ccmake = $portVersionCompat
	cmd:cmake = $portVersionCompat
	cmd:cpack = $portVersionCompat
	cmd:ctest = $portVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:librhash$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	lib:libuv$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

SUMMARY_gui="$SUMMARY (gui)"
DESCRIPTION_gui="$DESCRIPTION (gui)"

PROVIDES_gui="
	cmake${secondaryArchSuffix}_gui = $portVersion
	cmd:cmake_gui = $portVersionCompat
	"
REQUIRES_gui="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:librhash$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	lib:libuv$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:librhash$secondaryArchSuffix
	devel:libuv$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

defineDebugInfoPackage cmake$secondaryArchSuffix \
	$prefix/bin/ccmake \
	$prefix/bin/cmake \
	$prefix/bin/cpack \
	$prefix/bin/ctest \
	"$(getPackagePrefix gui)/bin"/cmake-gui

BUILD()
{
	# not an autotools configure
	./configure --prefix=$prefix \
		--datadir=/$relativeDataDir/cmake \
		--docdir=/$relativeDocDir \
		--mandir=/$relativeManDir \
		--no-system-libs \
		--system-curl \
		--system-librhash \
		--system-libuv \
		--qt-gui \
		--parallel=${jobArgs#-j}

	make $jobArgs
}

INSTALL()
{
	make install

	# No way to tell this to configure...
	rm -rf $dataDir/{emacs,vim}

	# GUI
	packageEntries "gui" \
		$prefix/bin/cmake-gui
}

TEST()
{
#x86_64
#97% tests passed, 19 tests failed out of 621
#          6 - kwsys.testSystemTools (Failed)
#         27 - FindPackageTest (Failed)
#         59 - ExportImport (Failed)
#         67 - StagingPrefix (Failed)
#         82 - Module.ExternalData (Failed)
#        143 - InstallMode-COPY (Failed)
#        144 - InstallMode-REL_SYMLINK (Failed)
#        145 - InstallMode-REL_SYMLINK_OR_COPY (Failed)
#        146 - InstallMode-ABS_SYMLINK (Failed)
#        147 - InstallMode-ABS_SYMLINK_OR_COPY (Failed)
#        148 - InstallMode-SYMLINK (Failed)
#        149 - InstallMode-SYMLINK_OR_COPY (Failed)
#        253 - CTestTestTimeout (Failed)
#        283 - CMakeLib.testUVProcessChain (Failed)
#        401 - RunCMake.find_dependency (Failed)
#        444 - RunCMake.file (Failed)
#        482 - RunCMake.no_install_prefix (Failed)
#        510 - RunCMake.CommandLine (Failed)
#        545 - RunCMake.PrecompileHeaders (Failed)

	cp bin/ctest Bootstrap.cmk/
	make test VERBOSE=1
}
