@ -3,7 +3,7 @@
(import
"OgreInitialize.cake"
&comptime-only "Macros.cake")
&comptime-only "Macros.cake" "BuildTools.cake" )
(c-import "<stdio.h>"
;; Ogre dependencies
@ -163,17 +163,144 @@
;;
;; Building
;;
(defun-comptime build-ogre-on-failure (failure-message (* (const char)))
(Logf "error: Ogre build: %s\n
Note that you can also build Ogre manually. This can be useful if you are porting to a new platform
and do not want to try to automate it yet.\n
The build step will automatically detect your build, as long as it is installed to
Dependencies/ogre-next/build/[Debug | Release].\n
See https://github.com/OGRECave/ogre-next#dependencies for dependencies and
https://github.com/OGRECave/ogre-next/tree/master/Scripts/BuildScripts/output for build scripts.\n"
failure-message))
(defun-comptime build-ogre (manager (& ModuleManager) module (* Module) &return bool)
(comptime-cond
('Windows
(comptime-error "Ogre build needs to be ported to Windows.
See https://github.com/OGRECave/ogre-next/tree/master/Scripts/BuildScripts/output"))
('Unix
;; Already built?
;; We could enhance this by checking for modifications, but that's pretty rare
(when (and (fileExists "Dependencies/ogre-next/build/Debug/lib/libOgreMain_d.so")
(fileExists "Dependencies/ogre-next/build/Release/lib/libOgreMain.so"))
(return true))
(Log "Ogre: Building via CMake and Make\n")
(var ogre-dependencies-dir-output (* (const char))
"Dependencies/ogre-next-deps/build/ogredeps")
(unless (fileExists ogre-dependencies-dir-output) ;; Build dependencies
(var ogre-dependencies-dir (* (const char)) "Dependencies/ogre-next-deps/build")
(makeDirectory ogre-dependencies-dir)
(run-process-sequential-or
("cmake"
"-G" "Ninja" ".."
:in-directory ogre-dependencies-dir)
(build-ogre-on-failure "failed at Ogre dependencies. This tool requires CMake.")
(return false))
(run-process-sequential-or
("ninja"
:in-directory ogre-dependencies-dir)
(build-ogre-on-failure "failed at Ogre dependencies Ninja build. This tool requires Ninja.")
(return false))
(run-process-sequential-or
("ninja" "install"
:in-directory ogre-dependencies-dir)
(build-ogre-on-failure "failed at Ogre dependencies Ninja install. This tool requires Ninja.")
(return false))
(unless (fileExists ogre-dependencies-dir-output)
(Logf "error: Expected Ogre dependencies to be in %s, but didn't find them\n"
ogre-dependencies-dir-output)
(return false)))
(unless (fileExists "Dependencies/ogre-next/Dependencies")
;; TODO: Add soft link to Dependencies
(Logf "Please run the following commands, then re-run the current command
(this manual step will eventually go away):\n
cd Dependencies/ogre-next\n
ln -s %s Dependencies\n" ogre-dependencies-dir-output)
(return false))
(var ogre-working-dir (* (const char)) "Dependencies/ogre-next/build")
(makeDirectory ogre-working-dir)
(var ogre-debug-output-dir ([] MAX_PATH_LENGTH char) (array 0))
(var ogre-release-output-dir ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer ogre-debug-output-dir "%s/Debug" ogre-working-dir)
(PrintfBuffer ogre-release-output-dir "%s/Release" ogre-working-dir)
(makeDirectory ogre-debug-output-dir)
(makeDirectory ogre-release-output-dir)
(scope ;; Debug
(run-process-sequential-or
("cmake"
"-D" "OGRE_USE_BOOST=0"
"-D" "OGRE_CONFIG_THREAD_PROVIDER=0"
"-D" "OGRE_CONFIG_THREADS=0"
"-D" "OGRE_BUILD_COMPONENT_SCENE_FORMAT=1"
"-D" "OGRE_BUILD_SAMPLES2=1"
"-D" "OGRE_BUILD_TESTS=1"
;; NOTE: You must not use quotes for this command. It needs to be
;; in one argument. This is because the shell interprets quotes a
;; certain way, which exec() does not
"-D" "CMAKE_BUILD_TYPE=Debug"
"-G" "Ninja"
"../.."
:in-directory ogre-debug-output-dir)
(build-ogre-on-failure "failed at Ogre cmake. This tool requires CMake.")
(return false))
(run-process-sequential-or
("ninja" "--verbose"
:in-directory ogre-debug-output-dir)
(build-ogre-on-failure "failed at Ogre ninja. This tool requires Ninja.")
(return false)))
;; TODO TURN BACK INTO scope
(scope ;; Release
(run-process-sequential-or
("cmake"
"-D" "OGRE_USE_BOOST=0"
"-D" "OGRE_CONFIG_THREAD_PROVIDER=0"
"-D" "OGRE_CONFIG_THREADS=0"
"-D" "OGRE_BUILD_COMPONENT_SCENE_FORMAT=1"
"-D" "OGRE_BUILD_SAMPLES2=1"
"-D" "OGRE_BUILD_TESTS=1"
"-D" "OGRE_DEBUG_MODE=0"
"-D" "CMAKE_BUILD_TYPE=Release"
"-G" "Ninja"
"../.."
:in-directory ogre-release-output-dir)
(build-ogre-on-failure "failed at Ogre cmake. This tool requires CMake.")
(return false))
(run-process-sequential-or
("ninja"
:in-directory ogre-release-output-dir)
(build-ogre-on-failure "failed at Ogre ninja. This tool requires Ninja.")
(return false)))
;; One final to check to ensure everything's good to go
(unless (and (fileExists "Dependencies/ogre-next/build/Debug/lib/libOgreMain_d.so")
(fileExists "Dependencies/ogre-next/build/Release/lib/libOgreMain.so"))
(build-ogre-on-failure
"Ogre build sequence completed, but files are not where expected. Is there an issue
with the configuration?\nFiles are expected in Dependencies/ogre-next/build")
(return false)))
(true
(comptime-error "need to define platform, e.g. (comptime-define-symbol 'Unix)")))
(Log "Ogre: Successfully built\n")
(return true))
(use-ogre-build-options)
(add-compile-time-hook-module pre-build build-ogre )
;; TODO: Automatically build Ogre if it isn't built yet
;; TODO: Copy necessary files (Hlms materials etc.) so self-test/user exes can run
;; (defun-comptime ogre-pre-build-hook (&return bool)
;; (unless (fileExists "Dependencies/ogre-next/build/Debug/lib")
;; (printf "error: Ogre is not built yet. Please run ./BuildDependencies_Debug.sh\n")
;; (return false))
;; (return true))
;; (add-compile-time-hook-module pre-build ogre-pre-build-hook)
(use-ogre-build-options)
(defun-comptime ogre-link-hook (manager (& ModuleManager)
linkCommand (& ProcessCommand)