diff --git a/Scripts/.gitignore b/Scripts/.gitignore new file mode 100644 index 0000000..d5c5094 --- /dev/null +++ b/Scripts/.gitignore @@ -0,0 +1,3 @@ +# Disable output +win_build.bat +linux_build.sh diff --git a/Scripts/gen_build_script.py b/Scripts/gen_build_script.py new file mode 100644 index 0000000..21f506d --- /dev/null +++ b/Scripts/gen_build_script.py @@ -0,0 +1,67 @@ +import os +import argparse +import jinja2 + +def get_root_directory() -> str: + return os.path.dirname(os.path.dirname(__file__)) + +class ScriptSettings: + m_BuildDoc: bool + + def __init__(self, build_doc: bool): + self.m_BuildDoc = build_doc + +class TemplateRender: + m_Loader: jinja2.BaseLoader + m_Environment: jinja2.Environment + + m_WinTemplate: jinja2.Template + m_LinuxTemplate: jinja2.Template + + m_Settings: ScriptSettings + + def __init__(self, settings: ScriptSettings) -> None: + self.m_Loader = jinja2.FileSystemLoader(self.__get_dir()) + self.m_Environment = jinja2.Environment(loader=self.m_Loader) + + self.m_WinTemplate = self.m_Environment.get_template('win_build.template.bat') + self.m_LinuxTemplate = self.m_Environment.get_template('linux_build.template.sh') + + self.m_Settings = settings + + def __get_dir(self) -> str: + return os.path.dirname(__file__) + + def __render(self, template: jinja2.Template, dest_file: str, is_win: bool) -> None: + with open(os.path.join(self.__get_dir(), dest_file), 'w', encoding='utf-8') as f: + f.write(template.render( + repo_root_dir = os.path.dirname(self.__get_dir()), + build_doc = self.m_Settings.m_BuildDoc + )) + + def render_win_script(self) -> None: + self.__render(self.m_WinTemplate, 'win_build.bat', True) + + def render_linux_script(self) -> None: + self.__render(self.m_LinuxTemplate, 'linux_build.sh', False) + +if __name__ == '__main__': + # parse argument + parser = argparse.ArgumentParser( + prog='LibCmo Windows Build Script', + description='LibCmo Windows Build Script' + ) + parser.add_argument( + '-d', '--build-doc', + action='store_true', dest='build_doc', + help='Build LibCmo without documentation.' + ) + args = parser.parse_args() + + # build settings + settings = ScriptSettings(args.build_doc) + # build template render and render result + render = TemplateRender(settings) + render.render_win_script() + render.render_linux_script() + \ No newline at end of file diff --git a/Scripts/linux_build.template.sh b/Scripts/linux_build.template.sh new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/win_build.bat b/Scripts/win_build.bat deleted file mode 100644 index 042e1ab..0000000 --- a/Scripts/win_build.bat +++ /dev/null @@ -1,38 +0,0 @@ -@ECHO OFF -:: Check environment -SET README_PATH=%CD%\README.md -IF EXIST %README_PATH% ( - REM DO NOTHING -) ELSE ( - ECHO Error: You must run this script at the root folder of this project! - EXIT /b -) - -:: Create main binary directory -MKDIR bin -CD bin -:: Create build and install folder -MKDIR build -MKDIR install - -:: Check build doc switch -IF NOT "%1"=="NODOC" ( - SET BUILD_DOC_SWITCH=ON -) ELSE ( - SET BUILD_DOC_SWITCH=OFF -) - -:: Build project -CD build -cmake -G "Visual Studio 16 2019" -A x64 -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_DOC=%BUILD_DOC_SWITCH% -DSTB_IMAGE_PATH="D:\CppLib\stb" -DYYCC_PATH="J:\YYCCommonplace\bin\cpp20\install\x64_Debug" -DZLIB_HEADER_PATH="D:\zlib" -DZLIB_BINARY_PATH="D:\zlib\contrib\vstudio\vc14\x64\ZlibDllRelease" ../.. -pause -cmake --build . --config Release -IF NOT "%1"=="NODOC" ( - cmake --build . --target NeMoDocuments -) -cmake --install . --prefix=../install --config Release -CD .. - -:: Exit to original path -CD .. -ECHO Windows CMake Build Done diff --git a/Scripts/win_build.py b/Scripts/win_build.py deleted file mode 100644 index 04e0f1e..0000000 --- a/Scripts/win_build.py +++ /dev/null @@ -1,48 +0,0 @@ -import subprocess -import os -import shutil -import argparse - -def get_root_directory() -> str: - return os.path.dirname(os.path.dirname(__file__)) - -def execute_cmd(prog: str, args: tuple[str, ...], cwd: str) -> None: - # find program first - found_prog = shutil.which(prog) - if found_prog is None: - raise RuntimeError(f'Fail to find program {prog}') - # run command - subprocess.run( - list((found_prog, ) + args), # program + arguments - stdin=subprocess.PIPE, # redirect - stdout=subprocess.PIPE, # redirect - stderr=subprocess.STDOUT, # stderr use the same output with stdout - cwd=cwd, # work directory - shell=True, # enable shell feature - check=True, # if program failed, raise exception and exit - ) - -def build(no_doc: bool) -> None: - # create directory - root_dir: str = get_root_directory() - os.makedirs(os.path.join(root_dir, 'Bin', 'build')) - os.makedirs(os.path.join(root_dir, 'Bin', 'install')) - - # build project - args = [ - '' - ] - -if __name__ == '__main__': - # parse argument - parser = argparse.ArgumentParser( - prog='LibCmo Windows Build Script', - description='LibCmo Windows Build Script' - ) - parser.add_argument( - '-d', '--no-doc', - action='store_true', dest='no_doc', - help='Build LibCmo without documentation.' - ) - args = parser.parse_args() - build(args.no_doc) diff --git a/Scripts/win_build.template.bat b/Scripts/win_build.template.bat new file mode 100644 index 0000000..5112afb --- /dev/null +++ b/Scripts/win_build.template.bat @@ -0,0 +1,24 @@ +@ECHO OFF +:: Navigate to root directory +CD /d {{ repo_root_dir }} + +:: Create main binary directory +MKDIR bin +CD bin +:: Create build and install folder +MKDIR build +MKDIR install + +:: Build project +CD build +cmake -A x64 -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BMAP=ON {{ '-DNEMO_BUILD_DOC=ON' if build_doc }} -DSTB_IMAGE_PATH="D:\CppLib\stb" -DYYCC_PATH="J:\YYCCommonplace\bin\cpp20\install\x64_Release" -DZLIB_HEADER_PATH="D:\zlib" -DZLIB_BINARY_PATH="D:\zlib\contrib\vstudio\vc14\x64\ZlibDllRelease" ../.. +cmake --build . --config RelWithDebInfo +{% if build_doc %} +cmake --build . --target NeMoDocuments +{% endif %} +cmake --install . --prefix=../install --config RelWithDebInfo +CD .. + +:: Exit to original path +CD .. +ECHO Windows CMake Build Done