cmake_minimum_required(VERSION 3.10)
project(ogre-base)
include(ExternalProject)
include(ProcessorCount)

set(CUSTOM_OPTS -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk -DBUILD_SHARED_LIBS=ON)
set(CUSTOM_OPTS_STATIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk-static -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk-static -DBUILD_SHARED_LIBS=OFF)

ProcessorCount(numCores)

find_program (MAKE_EXECUTABLE make DOC make REQUIRED)
find_package (PkgConfig)
pkg_check_modules(GFX_LIBS REQUIRED wayland-client wayland-protocols x11)

set(CPU ${CMAKE_SYSTEM_PROCESSOR})

set(BLENDER_DIST ${CMAKE_SOURCE_DIR}/prebuilts/Blender-3.6-unknown-linux-${CPU}.tar.xz)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/blender-bin/bin/blender
		COMMAND [ -f ${BLENDER_DIST} ] || ./build-blender.sh
		COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/blender-bin
		COMMAND tar xf ${BLENDER_DIST} -C ${CMAKE_BINARY_DIR}/blender-bin
		COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/blender-bin/bin
		COMMAND ln -sf ../Blender-3.6-unknown-linux-${CPU}/blender ${CMAKE_BINARY_DIR}/blender-bin/bin/blender
)

add_custom_target(blender DEPENDS ${CMAKE_BINARY_DIR}/blender-bin/bin/blender)

ExternalProject_Add(zlib-nominizip
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib
	CMAKE_ARGS -DZLIB_BUILD_STATIC=ON -DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_MINIZIP=OFF -DMINIZIP_BUILD_SHARED=OFF -DMINIZIP_BUILD_STATIC=OFF -DMINIZIP_ENABLE_BZIP2=OFF ${CUSTOM_OPTS} -DBUILD_SHARED_LIBS=OFF
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
)

ExternalProject_Add(zlib
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib
	CMAKE_ARGS -DZLIB_BUILD_STATIC=ON -DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_BUILD_SHARED=OFF -DMINIZIP_BUILD_STATIC=OFF -DMINIZIP_ENABLE_BZIP2=OFF ${CUSTOM_OPTS} -DBUILD_SHARED_LIBS=OFF
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
	DEPENDS zlib-nominizip
)

ExternalProject_Add(zlib-static-nominizip
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib
	CMAKE_ARGS -DZLIB_BUILD_STATIC=ON -DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_MINIZIP=OFF -DMINIZIP_BUILD_SHARED=OFF -DMINIZIP_BUILD_STATIC=ON -DMINIZIP_ENABLE_BZIP2=OFF ${CUSTOM_OPTS_STATIC}
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
)

ExternalProject_Add(zlib-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib
	CMAKE_ARGS -DZLIB_BUILD_STATIC=ON -DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_BUILD_SHARED=OFF -DMINIZIP_BUILD_STATIC=ON -DMINIZIP_ENABLE_BZIP2=OFF ${CUSTOM_OPTS_STATIC}
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
	DEPENDS zlib-static-nominizip
)

ExternalProject_Add(jpeg-turbo
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libjpeg-turbo
	CMAKE_ARGS -DENABLE_SHARED=FALSE -DENABLE_STATIC=TRUE
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
		${CUSTOM_OPTS}
)

ExternalProject_Add(jpeg-turbo-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libjpeg-turbo
	CMAKE_ARGS -DENABLE_SHARED=FALSE -DENABLE_STATIC=TRUE
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
		${CUSTOM_OPTS_STATIC}
)

ExternalProject_Add(libpng
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libpng
	CMAKE_ARGS -DPNG_SHARED=OFF
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
       		${CUSTOM_OPTS}
	DEPENDS zlib
)

ExternalProject_Add(libpng-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libpng
	CMAKE_ARGS -DPNG_SHARED=OFF
		-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
		${CUSTOM_OPTS_STATIC}
	DEPENDS zlib-static
)

ExternalProject_Add(freetype
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freetype
	CMAKE_ARGS ${CUSTOM_OPTS}
	-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DBUILD_SHARED_LIBS=FALSE -DFT_DISABLE_ZLIB=TRUE
	-DFT_DISABLE_BZIP2=TRUE -DFT_DISABLE_PNG=TRUE -DFT_DISABLE_HARFBUZZ=TRUE -DFT_DISABLE_BROTLI=TRUE
	-DCMAKE_DISABLE_FIND_PACKAGE_PNG=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE
	-DCMAKE_DISABLE_FIND_PACKAGE_BZip2=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_BrotliDec=TRUE
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5
	DEPENDS zlib libpng jpeg-turbo
)

ExternalProject_Add(freetype-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freetype
	CMAKE_ARGS ${CUSTOM_OPTS_STATIC}
	-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DBUILD_SHARED_LIBS=FALSE -DFT_DISABLE_ZLIB=TRUE
	-DFT_DISABLE_BZIP2=TRUE -DFT_DISABLE_PNG=TRUE -DFT_DISABLE_HARFBUZZ=TRUE -DFT_DISABLE_BROTLI=TRUE
	-DCMAKE_DISABLE_FIND_PACKAGE_PNG=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE
	-DCMAKE_DISABLE_FIND_PACKAGE_BZip2=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_BrotliDec=TRUE
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5
	DEPENDS zlib-static libpng-static jpeg-turbo-static
)

ExternalProject_Add(pugixml
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pugixml
	CMAKE_ARGS ${CUSTOM_OPTS} -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DBUILD_SHARED_LIBS=FALSE
)

ExternalProject_Add(pugixml-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pugixml
	CMAKE_ARGS ${CUSTOM_OPTS_STATIC} -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DBUILD_SHARED_LIBS=FALSE
)

set(FFMPEG_CONFIG_OPTS
	--disable-shared --enable-static --disable-programs --disable-gcrypt --disable-gpl --disable-nonfree
	--disable-libopus --disable-libpulse --disable-alsa
)
ExternalProject_Add(ffmpeg
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg
	CONFIGURE_COMMAND env PKG_CONFIG_PATH=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk/lib/pkgconfig
	"<SOURCE_DIR>/configure" --prefix=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk ${FFMPEG_CONFIG_OPTS}
	BUILD_COMMAND "${MAKE_EXECUTABLE}" -j${numCores} all
	INSTALL_COMMAND "${MAKE_EXECUTABLE}" -j${numCores} all
	DEPENDS libpng jpeg-turbo
)

ExternalProject_Add(ffmpeg-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg
	CONFIGURE_COMMAND env PKG_CONFIG_PATH=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk-static/lib/pkgconfig
	"<SOURCE_DIR>/configure" --prefix=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk-static ${FFMPEG_CONFIG_OPTS}
	BUILD_COMMAND "${MAKE_EXECUTABLE}" -j${numCores} all
	INSTALL_COMMAND "${MAKE_EXECUTABLE}" -j${numCores} all
	DEPENDS libpng-static jpeg-turbo-static
)

ExternalProject_Add(assimp
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assimp
	CMAKE_ARGS -DASSIMP_BUILD_ZLIB=ON -DBUILD_SHARED_LIBS=OFF ${CUSTOM_OPTS}
	DEPENDS zlib jpeg-turbo pugixml
)

ExternalProject_Add(assimp-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assimp
	CMAKE_ARGS -DASSIMP_BUILD_ZLIB=ON -DBUILD_SHARED_LIBS=OFF ${CUSTOM_OPTS_STATIC}
	DEPENDS zlib-static jpeg-turbo-static pugixml-static
)

set(SDL_COMMON_OPTIONS
	-DSDL_SHARED=OFF -DSDL_STATIC=ON -DSDL_STATIC_PIC=ON -DSDL_X11=ON
	-DSDL_X11_SHARED=OFF -DSDL_X11_XCURSOR=ON -DSDL_X11_XDBE=ON
	-DSDL_X11_XINPUT=ON -DSDL_X11_XRANDR=ON -DSDL_X11_XSCRNSAVER=ON -DSDL_X11_XSHAPE=ON -DSDL_WAYLAND=OFF
	-DSDL_WAYLAND_SHARED=OFF -DSDL_WAYLAND_LIBDECOR=OFF -DSDL_WAYLAND_LIBDECOR_SHARED=OFF -DSDL_KMSDRM=OFF -DSDL_KMSDRM_SHARED=OFF -DSDL_OPENGL=ON
	-DSDL_OPENGLES=ON -DSDL_VULKAN=ON -DSDL_ALSA=OFF -DSDL_ALSA_SHARED=OFF -DSDL_PIPEWIRE=ON -DSDL_PIPEWIRE_SHARED=OFF
	-DSDL_PULSEAUDIO=OFF -DSDL_PULSEAUDIO_SHARED=OFF -DSDL_RPATH=OFF -DSDL_HIDAPI=ON -DSDL_HIDAPI_JOYSTICK=ON
)

ExternalProject_Add(SDL
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDL
	CMAKE_ARGS
		${SDL_COMMON_OPTIONS}
		${CUSTOM_OPTS}
	DEPENDS libpng jpeg-turbo
)

ExternalProject_Add(SDL-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDL
	CMAKE_ARGS
		${SDL_COMMON_OPTIONS}
		${CUSTOM_OPTS_STATIC}
	DEPENDS libpng-static jpeg-turbo-static
)

ExternalProject_Add(SPIRV-Headers
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers
	CMAKE_ARGS ${CUSTOM_OPTS}
)

ExternalProject_Add(SPIRV-Tools
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Tools
	CMAKE_ARGS ${CUSTOM_OPTS} -DBUILD_SHARED_LIBS=OFF -DSPIRV_TOOLS_BUILD_STATIC=ON -DSPIRV_WERROR=OFF
		-DSPIRV_TOOLS_LIBRARY_TYPE=STATIC
		-DSPIRV-Headers_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk
	DEPENDS SPIRV-Headers
)

ExternalProject_Add(SPIRV-Headers-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers
	CMAKE_ARGS ${CUSTOM_OPTS_STATIC}
)

ExternalProject_Add(SPIRV-Tools-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Tools
	CMAKE_ARGS ${CUSTOM_OPTS} -DBUILD_SHARED_LIBS=OFF -DSPIRV_TOOLS_BUILD_STATIC=ON -DSPIRV_WERROR=OFF
		-DSPIRV_TOOLS_LIBRARY_TYPE=STATIC
		-DSPIRV-Headers_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/ogre-sdk-static
	DEPENDS SPIRV-Headers-static
)


ExternalProject_Add(glslang
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glslang
	CMAKE_ARGS ${CUSTOM_OPTS} -DBUILD_SHARED_LIBS=OFF -DENABLE_HLSL=TRUE -DENABLE_SPIRV=TRUE
	DEPENDS SPIRV-Tools
)

ExternalProject_Add(glslang-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glslang
	CMAKE_ARGS ${CUSTOM_OPTS_STATIC} -DBUILD_SHARED_LIBS=OFF -DENABLE_HLSL=TRUE -DENABLE_SPIRV=TRUE
	DEPENDS SPIRV-Tools-static
)

#ExternalProject_Add(SPIRV-Tools
#	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Tools
#	CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DSPIRV_TOOLS_BUILD_STATIC=ON -DSPIRV_TOOLS_LIBRARY_TYPE=STATIC ${CUSTOM_OPTS}
#)

set(OGRE_COMMON_OPTIONS
		-DOGRE_BUILD_RENDERSYSTEM_D3D9=FALSE
		-DOGRE_BUILD_RENDERSYSTEM_D3D11=FALSE
		-DOGRE_BUILD_RENDERSYSTEM_GL3PLUS=TRUE
		-DOGRE_BUILD_RENDERSYSTEM_GL=TRUE
		-DOGRE_BUILD_RENDERSYSTEM_GLES2=TRUE
		-DOGRE_BUILD_RENDERSYSTEM_METAL=FALSE
		-DOGRE_BUILD_RENDERSYSTEM_VULKAN=FALSE
		-DOGRE_BUILD_PLUGIN_GLSLANG=TRUE
		-DOGRE_BUILD_COMPONENT_OVERLAY=TRUE
		-DOGRE_BUILD_PLUGIN_DOT_SCENE=TRUE
		-DOGRE_GLSUPPORT_USE_EGL:BOOL=FALSE
		-DOGRE_INSTALL_DEPENDENCIES:BOOL=TRUE
#		-DASSIMP_BUILD_ASSIMP_TOOLS=OFF
#		-DOGRE_CONFIG_THREADS=3
#		-DOGRE_CONFIG_THREAD_PROVIDER="std"
)
ExternalProject_Add(bullet3
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bullet3
	CMAKE_ARGS
	${CUSTOM_OPTS}
        -DBUILD_SHARED_LIBS=OFF
        -DINSTALL_LIBS=ON
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON
        -DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON
        -DBUILD_PYBULLET=OFF
        -DUSE_DOUBLE_PRECISION=OFF
        -DBUILD_CPU_DEMOS=OFF
        -DBUILD_BULLET2_DEMOS=OFF
        -DBUILD_EXTRAS=OFF
        -DBUILD_EGL=OFF
        -DBUILD_ENET=OFF
        -DBUILD_UNIT_TESTS=OFF
        -DCMAKE_RELWITHDEBINFO_POSTFIX= # fixes FindBullet on MSVC
        -DBUILD_CLSOCKET=OFF
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5
)

ExternalProject_Add(bullet3-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bullet3
	CMAKE_ARGS
	${CUSTOM_OPTS_STATIC}
        -DBUILD_SHARED_LIBS=OFF
        -DINSTALL_LIBS=ON
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON
        -DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON
        -DBUILD_PYBULLET=OFF
        -DUSE_DOUBLE_PRECISION=OFF
        -DBUILD_CPU_DEMOS=OFF
        -DBUILD_BULLET2_DEMOS=OFF
        -DBUILD_EXTRAS=OFF
        -DBUILD_EGL=OFF
        -DBUILD_ENET=OFF
        -DBUILD_UNIT_TESTS=OFF
        -DCMAKE_RELWITHDEBINFO_POSTFIX= # fixes FindBullet on MSVC
        -DBUILD_CLSOCKET=OFF
        -DCMAKE_POLICY_VERSION_MINIMUM=3.5
)

add_custom_target(core-deps DEPENDS zlib SDL jpeg-turbo libpng ffmpeg pugixml bullet3 freetype)
add_custom_target(core-deps-static DEPENDS zlib-static SDL-static jpeg-turbo-static libpng-static ffmpeg-static pugixml bullet3-static freetype-static)

ExternalProject_Add(ogre
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre
	CMAKE_ARGS
		${OGRE_COMMON_OPTIONS}
		-DASSIMP_BUILD_ASSIMP_TOOLS=ON
		-DOGRE_STATIC=FALSE
		${CUSTOM_OPTS} -DCMAKE_BUILD_TYPE=Debug
	DEPENDS core-deps freetype assimp glslang
)

ExternalProject_Add(ogre-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre
	CMAKE_ARGS
		${OGRE_COMMON_OPTIONS}
		-DASSIMP_BUILD_ASSIMP_TOOLS=ON
		-DOGRE_STATIC=TRUE
		${CUSTOM_OPTS_STATIC} -DCMAKE_BUILD_TYPE=Debug
	PATCH_COMMAND ${CMAKE_COMMAND} -E make_directory Dependencies/include/bullet
	DEPENDS core-deps-static freetype-static assimp-static glslang-static zlib-static
)

ExternalProject_Add(ogre-procedural
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-procedural
	CMAKE_ARGS -DOgreProcedural_BUILD_DOCS:BOOL=FALSE
		-DOgreProcedural_STATIC=FALSE -DOgreProcedural_BUILD_SAMPLES=TRUE
		${CUSTOM_OPTS} -DCMAKE_BUILD_TYPE=Debug
	DEPENDS ogre
)

ExternalProject_Add(ogre-procedural-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-procedural
	CMAKE_ARGS -DOgreProcedural_BUILD_DOCS:BOOL=FALSE
		-DOgreProcedural_STATIC=TRUE -DOgreProcedural_BUILD_SAMPLES=TRUE
		${CUSTOM_OPTS_STATIC} -DCMAKE_BUILD_TYPE=Release
	DEPENDS ogre-static
)

ExternalProject_Add(ogre-pagedgeometry
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-pagedgeometry
	CMAKE_ARGS
		${CUSTOM_OPTS}
	DEPENDS ogre
)

ExternalProject_Add(ogre-pagedgeometry-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-pagedgeometry
	CMAKE_ARGS
	${CUSTOM_OPTS_STATIC}
	DEPENDS ogre-static
)

ExternalProject_Add(ogrewater
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogrewater
	CMAKE_ARGS
		${CUSTOM_OPTS}
	INSTALL_COMMAND ""
	DEPENDS core-deps ogre
)

ExternalProject_Add(ogrewater-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogrewater
	CMAKE_ARGS
		${CUSTOM_OPTS_STATIC}
	INSTALL_COMMAND ""
	DEPENDS core-deps-static ogre-static
)

ExternalProject_Add(flecs
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flecs
	CMAKE_ARGS -DFLECS_STATIC=ON -DFLECS_SHARED=OFF -DFLECS_PIC=ON -DFLECS_TESTS=OFF
	${CUSTOM_OPTS}
)

ExternalProject_Add(flecs-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flecs
	CMAKE_ARGS -DFLECS_STATIC=ON -DFLECS_SHARED=OFF -DFLECS_PIC=ON -DFLECS_TESTS=OFF
	${CUSTOM_OPTS_STATIC}
)

ExternalProject_Add(jolt
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jolt/Build
	CMAKE_ARGS
	${CUSTOM_OPTS} -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DCPP_RTTI_ENABLED=ON -DDEBUG_RENDERER_IN_DISTRIBUTION=ON
	-DJPH_USE_DX12=OFF -DJPH_USE_DXC=OFF -DJPH_USE_VK=OFF -DJPH_USE_MTL=OFF -DJPH_USE_CPU_COMPUTE=OFF -DDOUBLE_PRECISION=ON
)

ExternalProject_Add(jolt-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jolt/Build
	CMAKE_ARGS
	${CUSTOM_OPTS_STATIC} -DCMAKE_BUILD_TYPE=Debug -DCPP_RTTI_ENABLED=ON -DDEBUG_RENDERER_IN_DISTRIBUTION=ON
	-DJPH_USE_DX12=OFF -DJPH_USE_DXC=OFF -DJPH_USE_VK=OFF -DJPH_USE_MTL=OFF -DJPH_USE_CPU_COMPUTE=OFF -DDOUBLE_PRECISION=ON
)

ExternalProject_Add(json
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/json
	CMAKE_ARGS
	${CUSTOM_OPTS} -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF
)

ExternalProject_Add(json-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/json
	CMAKE_ARGS
	${CUSTOM_OPTS_STATIC} -DCMAKE_BUILD_TYPE=Debug
)

ExternalProject_Add(nanoflann
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/nanoflann
	CMAKE_ARGS
	${CUSTOM_OPTS} -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF
)

ExternalProject_Add(nanoflann-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/nanoflann
	CMAKE_ARGS
	${CUSTOM_OPTS_STATIC} -DCMAKE_BUILD_TYPE=Debug
)

ExternalProject_Add(world2
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-projects/world2
	CMAKE_ARGS ${CUSTOM_OPTS} -DBLENDER=${CMAKE_CURRENT_BINARY_DIR}/blender-bin/bin/blender
	DEPENDS ogre ogre-procedural ogre-pagedgeometry flecs blender json nanoflann
)

ExternalProject_Add(world2-static
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-projects/world2
	CMAKE_ARGS ${CUSTOM_OPTS_STATIC} -DBLENDER=${CMAKE_CURRENT_BINARY_DIR}/blender-bin/bin/blender
	DEPENDS ogre-static ogre-procedural-static ogre-pagedgeometry-static flecs-static json-static nanoflann-static blender
)

ExternalProject_Add(jolt-demo
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ogre-projects/jolt-physics
	CMAKE_ARGS ${CUSTOM_OPTS_STATIC} -DBLENDER=${CMAKE_CURRENT_BINARY_DIR}/blender-bin/bin/blender -DCMAKE_BUILD_TYPE=Debug
	DEPENDS jolt-static ogre-static ogre-procedural-static ogre-pagedgeometry-static flecs-static blender
)


