PORTNAME=	CWR-CE
DISTVERSIONPREFIX=	v
DISTVERSION=	3.05
CATEGORIES=	games

PATCH_SITES=	https://github.com/ocochard/CWR-CE/commit/
PATCHFILES=	819889acd2a91ef3188ff0048d277a864d52e080.patch?full_index=1:-p1 \
		54029908b53910562a775c031d50cc4bece2c1ad.patch?full_index=1:-p1 \
		b1ea6c5ba523b77effac22ed0178a00489474547.patch?full_index=1:-p1 \
		f56c2f855351362da6fbce7f5b76c291d559ee99.patch?full_index=1:-p1 \
		e54f89ae874c9302f85e06987fda9a8175f87b95.patch?full_index=1:-p1 \
		447813a76bed39cfea481c4c57cae7160bb3054d.patch?full_index=1:-p1 \
		e4eec8ccc7cc1ed75c6b8384b61835ccf374a0e5.patch?full_index=1:-p1 \
		cb90c885e2e417f7718b9209f1e60f518242546c.patch?full_index=1:-p1 \
		cfcccc9076a291f43aefeb82ad9cd6dae301b65a.patch?full_index=1:-p1 \
		d60c53212eb46b0a29d018699c16643c48ec43e4.patch?full_index=1:-p1 \
		2956080fb1da4f43951aba39ca74957e13800a26.patch?full_index=1:-p1 \
		c79fff864ad5ed32f43822a53a41491ab648dc0e.patch?full_index=1:-p1 \
		c60c1c84c25d4329fc1742c4036c7f53c6f15b32.patch?full_index=1:-p1 \
		f3038e4c5e0713fb62dfc5dba612abea0148ba56.patch?full_index=1:-p1 \
		3bf1c626c5188117c14394c0ff9a0ca5f2baa020.patch?full_index=1:-p1 \
		eba00f0c26a5c722361806e8532e29d5899bd5cb.patch?full_index=1:-p1

MAINTAINER=	olivier@FreeBSD.org
COMMENT=	Arma: Cold War Assault - Remastered Community Edition
WWW=		https://github.com/ofpisnotdead-com/CWR-CE

ONLY_FOR_ARCHS=	aarch64 amd64 armv7 i386 powerpc64le
ONLY_FOR_ARCHS_REASON=	requires SSE intrinsics, light porting work for other architectures

LICENSE=	GPLv3+
LICENSE_FILE=	${WRKSRC}/LICENSE

BUILD_DEPENDS=	stb>0:devel/stb \
		${LOCALBASE}/include/CLI/CLI.hpp:devel/cli11 \
		${LOCALBASE}/include/vulkan/vulkan.h:graphics/vulkan-headers \
		${LOCALBASE}/lib/cmake/Catch2/Catch2Config.cmake:devel/catch2 \
		${LOCALBASE}/lib/cmake/glslang/glslang-config.cmake:graphics/glslang
LIB_DEPENDS=	libcjson.so:devel/libcjson \
		libcurl.so:ftp/curl \
		libenkiTS.so:devel/enkits \
		libfmt.so:devel/libfmt \
		libfreetype.so:print/freetype2 \
		libimgui.so:x11-toolkits/imgui \
		libmimalloc.so:devel/mimalloc \
		libogg.so:audio/libogg \
		libopenal.so:audio/openal-soft \
		libopus.so:audio/opus \
		libSDL3.so:devel/sdl3 \
		libvulkan.so:graphics/vulkan-loader \
		libspdlog.so:devel/spdlog \
		libvorbis.so:audio/libvorbis \
		libzstd.so:archivers/zstd

USES=		cmake compiler:c++20-lang dos2unix gl localbase pkgconfig

DOS2UNIX_REGEX=	.*\.(c|h|cpp|hpp)
USE_GITHUB=	yes
GH_ACCOUNT=	ofpisnotdead-com
GH_PROJECT=	CWR-CE
GH_TAGNAME=	0667ada4d4d3fa57efc2d8168f8cf9fec34b17f4
USE_GL=		gl

SUB_FILES=	pkg-message

# Disable vcpkg toolchain wiring — find_package(... CONFIG REQUIRED) picks up
# system libraries from ${LOCALBASE}/lib/cmake instead.
CMAKE_ARGS=	-DVCPKG_MANIFEST_MODE=OFF \
		-DCMAKE_DISABLE_FIND_PACKAGE_VCPKG=ON

CMAKE_OFF=	CMAKE_COMPILE_WARNING_AS_ERROR POSEIDON_BUILD_FUZZERS
# https://github.com/llvm/llvm-project/issues/69524
CMAKE_ON=	POSEIDON_DISABLE_PCH
CXXFLAGS_powerpc64le=	-DNO_WARN_X86_INTRINSICS
LDFLAGS+=	-Wl,--as-needed # imgui links its GLFW and GLUT backends PUBLIC

PLIST_FILES=	bin/PoseidonGame \
		bin/PoseidonGameDemo \
		bin/PoseidonServer \
		bin/PoseidonStudio \
		bin/PoseidonTetris \
		bin/PoseidonTools \
		bin/cwr-ce \
		bin/install-cwr-data

# PoseidonStudioTests needs the Dear ImGui Test Engine, off in x11-toolkits/imgui
post-patch:
	@${REINPLACE_CMD} -e '/add_subdirectory(tests\/unit\/apps\/Studio)/d' \
		${WRKSRC}/CMakeLists.txt

do-install:
	${INSTALL_PROGRAM} \
		${BUILD_WRKSRC}/apps/cwr/Game/PoseidonGame \
		${BUILD_WRKSRC}/apps/cwr/GameDemo/PoseidonGameDemo \
		${BUILD_WRKSRC}/apps/cwr/Server/PoseidonServer \
		${BUILD_WRKSRC}/apps/tools/Studio/PoseidonStudio \
		${BUILD_WRKSRC}/apps/tetris/Tetris/PoseidonTetris \
		${BUILD_WRKSRC}/apps/tools/Tools/PoseidonTools \
		${STAGEDIR}${PREFIX}/bin
	${INSTALL_SCRIPT} ${FILESDIR}/install-cwr-data.sh \
		${STAGEDIR}${PREFIX}/bin/install-cwr-data
	${INSTALL_SCRIPT} ${FILESDIR}/cwr-ce.sh \
		${STAGEDIR}${PREFIX}/bin/cwr-ce

.include <bsd.port.pre.mk>

.if ${ARCH} == aarch64 || ${ARCH:Marmv?}
BUILD_DEPENDS+=	${LOCALBASE}/include/sse2neon.h:devel/sse2neon
.endif

.include <bsd.port.post.mk>
