From 6d29937abb9afc9c0f0624078f2cce9d680c6563 Mon Sep 17 00:00:00 2001 From: uniflare Date: Sun, 5 Jun 2022 13:57:21 +0200 Subject: [PATCH] !R (Build) Refactored build system and tooling - Changed binary output names to match names required for the Arma mod package - Added convenience batch files for build all debug and release variants - Added Linux 32bit - Added VS 2022 support - now required for Build_All script - Added Visual Studio CMake build configurations and presets - Moved all build tools to Tools sub-folder - Moved mod package output to build folder - Moved build intermediates to build folder - Moved from Ninja to Ninja Multi-Config generator to simplify build configurations - Moved binary output to bin folder in root - Moved generator implementation to a single generator file that takes arguments --- Build_All.bat | 58 -------- CMakeLists.txt | 27 +++- CMakePresets.json | 148 +++++++++++++++----- Clean_All.bat | 30 ---- Tools/Build_All_Debug.bat | 2 + Tools/Build_All_Release.bat | 2 + buildArmaMod.ps1 => Tools/Build_ArmaMod.ps1 | 30 ++-- Tools/Clean_All.bat | 39 ++++++ Tools/Generate_Linux_x64.bat | 7 + Tools/Generate_Linux_x86.bat | 7 + Tools/Generate_VS2019_x64.bat | 7 + Tools/Generate_VS2019_x86.bat | 7 + Tools/Generate_VS2022_x64.bat | 7 + Tools/Generate_VS2022_x86.bat | 7 + Tools/Util/Build_All.bat | 71 ++++++++++ Tools/Util/FindCMake.bat | 31 ++++ Tools/Util/GenerateProject.bat | 106 ++++++++++++++ VS2019_x64.bat | 34 ----- VS2019_x86.bat | 34 ----- 19 files changed, 448 insertions(+), 206 deletions(-) delete mode 100644 Build_All.bat delete mode 100644 Clean_All.bat create mode 100644 Tools/Build_All_Debug.bat create mode 100644 Tools/Build_All_Release.bat rename buildArmaMod.ps1 => Tools/Build_ArmaMod.ps1 (79%) create mode 100644 Tools/Clean_All.bat create mode 100644 Tools/Generate_Linux_x64.bat create mode 100644 Tools/Generate_Linux_x86.bat create mode 100644 Tools/Generate_VS2019_x64.bat create mode 100644 Tools/Generate_VS2019_x86.bat create mode 100644 Tools/Generate_VS2022_x64.bat create mode 100644 Tools/Generate_VS2022_x86.bat create mode 100644 Tools/Util/Build_All.bat create mode 100644 Tools/Util/FindCMake.bat create mode 100644 Tools/Util/GenerateProject.bat delete mode 100644 VS2019_x64.bat delete mode 100644 VS2019_x86.bat diff --git a/Build_All.bat b/Build_All.bat deleted file mode 100644 index 4abc581..0000000 --- a/Build_All.bat +++ /dev/null @@ -1,58 +0,0 @@ -@ECHO OFF -SETLOCAL ENABLEDELAYEDEXPANSION - -CALL "./Clean_All.bat" - -REM Build is where we will generate project files and compile the program into. -IF NOT EXIST Build_Win32/ ( - MKDIR Build_Win32 -) -IF NOT EXIST Build_Win64/ ( - MKDIR Build_Win64 -) -IF NOT EXIST Build_Linux/ ( - MKDIR Build_Linux -) - -REM First we check if we have cmake installed at path. -WHERE cmake -IF %ERRORLEVEL% NEQ 0 ( - REM If there is no cmake at path, we will search for cmake installed alongside visual studio. - GOTO CMAKE_FROM_VS_INSTALL -) ELSE ( - GOTO CMAKE_LITERAL -) - -:CMAKE_FROM_VS_INSTALL -for /f "usebackq tokens=*" %%i in (`call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( - set InstallDir=%%i -) -SET cmake="%InstallDir%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -GOTO RUN_CMAKE - -:CMAKE_LITERAL -REM We found cmake, so we can just run the command as is. -SET cmake=cmake - -REM fallthrough intentionally to running cmake. -:RUN_CMAKE - -%cmake% -G "Visual Studio 16 2019" -A Win32 -B "Build_Win32" -%cmake% -G "Visual Studio 16 2019" -A x64 -B "Build_Win64" -wsl cmake -G "Ninja" -B "Build_Linux" - -IF "%~1"=="-debug" ( - echo Building - debug - %cmake% --build "Build_Win32" --config Debug - %cmake% --build "Build_Win64" --config Debug - - wsl cmake --build "Build_Linux" --config Debug - Powershell -executionpolicy remotesigned -File ./buildArmaMod.ps1 "-debug" -) ELSE ( - echo Building - release - %cmake% --build "Build_Win32" --config Release - %cmake% --build "Build_Win64" --config Release - - wsl cmake --build "Build_Linux" --config Release - Powershell -executionpolicy remotesigned -File ./buildArmaMod.ps1 -) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a76bac8..45a774d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required (VERSION 3.15) set(CMAKE_SUPPRESS_REGENERATION true) - - +set(CMAKE_CONFIGURATION_TYPES Debug Release) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +set(Is64Bit ON CACHE BOOL "Used via cmake commandline during project generation to determine 64 or 32bit.") -project ("FileXT") +project (FileXT) include_directories(${PROJECT_SOURCE_DIR}/FileXT) file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/FileXT/*.cpp ${PROJECT_SOURCE_DIR}/FileXT/*.h) @@ -18,6 +18,27 @@ target_precompile_headers(FileXT FileXT/pch.h ) +if (${Is64Bit}) + set(output_name "filext_x64") +else() + set(output_name "filext") + + if (UNIX) + target_link_options(FileXT PUBLIC "-m32") + target_compile_options(FileXT PUBLIC "-m32") + endif() +endif() + +set_target_properties(FileXT + PROPERTIES + PREFIX "" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/bin/$" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/bin/$" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/bin/$" +) + +set_target_properties(FileXT PROPERTIES OUTPUT_NAME ${output_name}) + set_property(TARGET FileXT PROPERTY CXX_STANDARD 17) add_subdirectory(FileXTTest) diff --git a/CMakePresets.json b/CMakePresets.json index cf72825..4fb00a7 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,35 +1,117 @@ { - "version": 2, - "configurePresets": [ - { - "name": "linux-debug", - "displayName": "Linux Debug", - "description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/Build_Linux", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/Build_Linux/install" - }, - "vendor": { - "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Linux" ] }, - "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } - } - }, - { - "name": "linux-release", - "displayName": "Linux Release", - "description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/Build_Linux/", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/Build_Linux/install/${presetName}" - }, - "vendor": { - "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Linux" ] }, - "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } - } - } - ] + "version": 2, + "configurePresets": [ + { + "name": "x64-linux", + "displayName": "x64 Linux", + "description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/${presetName}", + "Is64Bit": "TRUE" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Linux" ] }, + "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } + } + }, + { + "name": "x86-linux", + "displayName": "x86 Linux", + "description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/${presetName}", + "Is64Bit": "FALSE" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Linux" ] }, + "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } + } + }, + { + "name": "x86-windows", + "displayName": "x86 Windows", + "description": "Standard Windows 32-bit target.", + "generator": "Visual Studio 17 2022", + "architecture": "Win32", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/${presetName}", + "Is64Bit": "FALSE" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] }, + "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } + } + }, + { + "name": "x64-windows", + "displayName": "x64 Windows", + "description": "Standard Windows 64-bit target.", + "generator": "Visual Studio 17 2022", + "architecture": "x64", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/${presetName}", + "Is64Bit": "TRUE" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] }, + "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } + } + } + ], + "buildPresets": [ + { + "name": "x64-linux-debug", + "displayName": "Debug", + "configurePreset": "x64-linux", + "configuration": "Debug" + }, + { + "name": "x64-linux-release", + "displayName": "Release", + "configurePreset": "x64-linux", + "configuration": "Release" + }, + { + "name": "x86-linux-debug", + "displayName": "Debug", + "configurePreset": "x86-linux", + "configuration": "Debug" + }, + { + "name": "x86-linux-release", + "displayName": "Release", + "configurePreset": "x86-linux", + "configuration": "Release" + }, + { + "name": "x64-windows-debug", + "displayName": "Debug", + "configurePreset": "x64-windows", + "configuration": "Debug" + }, + { + "name": "x64-windows-release", + "displayName": "Release", + "configurePreset": "x64-windows", + "configuration": "Release" + }, + { + "name": "x86-windows-debug", + "displayName": "Debug", + "configurePreset": "x86-windows", + "configuration": "Debug" + }, + { + "name": "x86-windows-release", + "displayName": "Release", + "configurePreset": "x86-windows", + "configuration": "Release" + } + ] } \ No newline at end of file diff --git a/Clean_All.bat b/Clean_All.bat deleted file mode 100644 index 23170db..0000000 --- a/Clean_All.bat +++ /dev/null @@ -1,30 +0,0 @@ -@ECHO OFF -ECHO Clean All - -REM delete files individually as to not delete any save files (if we are using this directory for mods locally) -IF EXIST ".\_build\@filext\filext_x64.dll" ( DEL ".\_build\@filext\filext_x64.dll" ) -IF EXIST ".\_build\@filext\filext.dll" ( DEL ".\_build\@filext\filext.dll" ) -IF EXIST ".\_build\@filext\filext_x64.so" ( DEL ".\_build\@filext\filext_x64.so" ) -IF EXIST ".\_build\@filext\filext_x64.pdb" ( DEL ".\_build\@filext\filext_x64.pdb" ) -IF EXIST ".\_build\@filext\filext.pdb" ( DEL ".\_build\@filext\filext.pdb" ) -IF EXIST ".\_build\@filext\mod.cpp" ( DEL ".\_build\@filext\mod.cpp" ) - -IF EXIST ".\_build\@filext\addons" ( - RD /s /q ".\_build\@filext\addons" -) - -IF EXIST "./Build" ( - RD /s /q "Build" -) - -IF EXIST "./Build_Linux" ( - RD /s /q "Build_Linux" -) - -IF EXIST "./Build_Win32" ( - RD /s /q "Build_Win32" -) - -IF EXIST "./Build_Win64" ( - RD /s /q "Build_Win64" -) diff --git a/Tools/Build_All_Debug.bat b/Tools/Build_All_Debug.bat new file mode 100644 index 0000000..e4ec4e2 --- /dev/null +++ b/Tools/Build_All_Debug.bat @@ -0,0 +1,2 @@ +@ECHO OFF +CALL ./Util/Build_All.bat -debug \ No newline at end of file diff --git a/Tools/Build_All_Release.bat b/Tools/Build_All_Release.bat new file mode 100644 index 0000000..c2d2a99 --- /dev/null +++ b/Tools/Build_All_Release.bat @@ -0,0 +1,2 @@ +@ECHO OFF +CALL ./Util/Build_All.bat \ No newline at end of file diff --git a/buildArmaMod.ps1 b/Tools/Build_ArmaMod.ps1 similarity index 79% rename from buildArmaMod.ps1 rename to Tools/Build_ArmaMod.ps1 index 0526ee7..470eb5d 100644 --- a/buildArmaMod.ps1 +++ b/Tools/Build_ArmaMod.ps1 @@ -58,30 +58,32 @@ function Get-Arma3ToolsPath() ################################################################################################### -Push-Location +Push-Location .. "Ensure directories.." -New-Item "_build/@filext" -ItemType Directory -Force -New-Item "_build/@filext/storage" -ItemType Directory -Force +New-Item "build/@filext" -ItemType Directory -Force +New-Item "build/@filext/storage" -ItemType Directory -Force "Copy extra files.." -Copy-Item "Arma mod/mod.cpp" "_build/@filext" +Copy-Item "Arma mod/mod.cpp" "build/@filext" if($debug) { Write-Host "Copy DLLs... (debug)" - Copy-Item "Build_Win64/Debug/filext.dll" "_build/@filext/filext_x64.dll" - Copy-Item "Build_Win32/Debug/filext.dll" "_build/@filext/filext.dll" - Copy-Item "Build_Linux/libFileXT.so" "_build/@filext/filext_x64.so" + Copy-Item "bin/Debug/filext.dll" "build/@filext/filext_x64.dll" + Copy-Item "bin/Debug/filext.dll" "build/@filext/filext.dll" + Copy-Item "bin/Debug/filext_x64.so" "build/@filext/filext_x64.so" + Copy-Item "bin/Debug/filext.so" "build/@filext/filext.so" - Copy-Item "Build_Win64/Debug/filext.pdb" "_build/@filext/filext_x64.pdb" - Copy-Item "Build_Win32/Debug/filext.pdb" "_build/@filext/filext.pdb" + Copy-Item "bin/Debug/filext.pdb" "build/@filext/filext_x64.pdb" + Copy-Item "bin/Debug/filext.pdb" "build/@filext/filext.pdb" } else { Write-Host "Copy DLLs... (release)" - Copy-Item "Build_Win64/Release/filext.dll" "_build/@filext/filext_x64.dll" - Copy-Item "Build_Win32/Release/filext.dll" "_build/@filext/filext.dll" - Copy-Item "Build_Linux/libFileXT.so" "_build/@filext/filext_x64.so" + Copy-Item "bin/Release/filext_x64.dll" "build/@filext/filext_x64.dll" + Copy-Item "bin/Release/filext.dll" "build/@filext/filext.dll" + Copy-Item "bin/Release/filext_x64.so" "build/@filext/filext_x64.so" + Copy-Item "bin/Release/filext.so" "build/@filext/filext.so" } "Build pbos..." @@ -90,9 +92,9 @@ else { # Specific Arma 3 Tools [string]$addonBuilderPath = "$arma3ToolsPath/AddonBuilder/AddonBuilder.exe" -[string]$thisLoc = $PSScriptRoot.Replace("\", "/") +[string]$thisLoc = Get-Location [string]$addonPath = "$thisLoc/Arma mod/addons/filext" -[string]$builtPath = "$thisLoc/_build/@filext/addons" +[string]$builtPath = "$thisLoc/build/@filext/addons" [string[]]$addonBuilderArgs=@( "`"$addonPath`"", diff --git a/Tools/Clean_All.bat b/Tools/Clean_All.bat new file mode 100644 index 0000000..df2c1c8 --- /dev/null +++ b/Tools/Clean_All.bat @@ -0,0 +1,39 @@ +@ECHO OFF +ECHO Clean All + +PUSHD .. + +REM delete files individually as to not delete any save files (if we are using this directory for mods locally) +IF EXIST ".\build\@filext\filext.dll" ( DEL ".\build\@filext\filext.dll" ) +IF EXIST ".\build\@filext\filext_x64.dll" ( DEL ".\build\@filext\filext_x64.dll" ) +IF EXIST ".\build\@filext\filext.so" ( DEL ".\build\@filext\filext.so" ) +IF EXIST ".\build\@filext\filext_x64.so" ( DEL ".\build\@filext\filext_x64.so" ) +IF EXIST ".\build\@filext\filext_x64.pdb" ( DEL ".\build\@filext\filext_x64.pdb" ) +IF EXIST ".\build\@filext\filext.pdb" ( DEL ".\build\@filext\filext.pdb" ) +IF EXIST ".\build\@filext\mod.cpp" ( DEL ".\build\@filext\mod.cpp" ) + +IF EXIST ".\bin" ( + RD /s /q ".\bin" +) + +IF EXIST ".\build\@filext\addons" ( + RD /s /q ".\build\@filext\addons" +) + +IF EXIST ".\build\x86-linux" ( + wsl rm -r build/x86-linux +) + +IF EXIST ".\build\x64-linux" ( + wsl rm -r build/x64-linux +) + +IF EXIST ".\build\x86-windows" ( + RD /s /q "build\x86-windows" +) + +IF EXIST ".\build\x64-windows" ( + RD /s /q "build\x64-windows" +) + +POPD \ No newline at end of file diff --git a/Tools/Generate_Linux_x64.bat b/Tools/Generate_Linux_x64.bat new file mode 100644 index 0000000..722171a --- /dev/null +++ b/Tools/Generate_Linux_x64.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +PUSHD .. +SET src=%CD% +POPD + +CALL .\Util\GenerateProject.bat -src="%src%" -build-dir="x64-linux" -generator="Ninja Multi-Config" -wsl -options="-DIs64Bit:BOOL=TRUE" \ No newline at end of file diff --git a/Tools/Generate_Linux_x86.bat b/Tools/Generate_Linux_x86.bat new file mode 100644 index 0000000..1d4e177 --- /dev/null +++ b/Tools/Generate_Linux_x86.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +PUSHD .. +SET src=%CD% +POPD + +CALL .\Util\GenerateProject.bat -src="%src%" -build-dir="x86-linux" -generator="Ninja Multi-Config" -wsl -options="-DIs64Bit:BOOL=FALSE" \ No newline at end of file diff --git a/Tools/Generate_VS2019_x64.bat b/Tools/Generate_VS2019_x64.bat new file mode 100644 index 0000000..c9df615 --- /dev/null +++ b/Tools/Generate_VS2019_x64.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +PUSHD .. +SET src=%CD% +POPD + +CALL .\Util\GenerateProject.bat -src="%src%" -build-dir="x64-windows" -generator="Visual Studio 16 2019" -opengui -options="-A x64 -DIs64Bit:BOOL=TRUE" \ No newline at end of file diff --git a/Tools/Generate_VS2019_x86.bat b/Tools/Generate_VS2019_x86.bat new file mode 100644 index 0000000..8adcd08 --- /dev/null +++ b/Tools/Generate_VS2019_x86.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +PUSHD .. +SET src=%CD% +POPD + +CALL .\Util\GenerateProject.bat -src="%src%" -build-dir="x86-windows" -generator="Visual Studio 16 2019" -opengui -options="-A Win32 -DIs64Bit:BOOL=FALSE" \ No newline at end of file diff --git a/Tools/Generate_VS2022_x64.bat b/Tools/Generate_VS2022_x64.bat new file mode 100644 index 0000000..74547fc --- /dev/null +++ b/Tools/Generate_VS2022_x64.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +PUSHD .. +SET src=%CD% +POPD + +CALL .\Util\GenerateProject.bat -src="%src%" -build-dir="x64-windows" -generator="Visual Studio 17 2022" -opengui -options="-A x64 -DIs64Bit:BOOL=TRUE" \ No newline at end of file diff --git a/Tools/Generate_VS2022_x86.bat b/Tools/Generate_VS2022_x86.bat new file mode 100644 index 0000000..a3c89f2 --- /dev/null +++ b/Tools/Generate_VS2022_x86.bat @@ -0,0 +1,7 @@ +@ECHO OFF + +PUSHD .. +SET src=%CD% +POPD + +CALL .\Util\GenerateProject.bat -src="%src%" -build-dir="x86-windows" -generator="Visual Studio 17 2022" -opengui -options="-A Win32 -DIs64Bit:BOOL=FALSE" \ No newline at end of file diff --git a/Tools/Util/Build_All.bat b/Tools/Util/Build_All.bat new file mode 100644 index 0000000..a255de3 --- /dev/null +++ b/Tools/Util/Build_All.bat @@ -0,0 +1,71 @@ +@ECHO OFF +SETLOCAL ENABLEDELAYEDEXPANSION + +PUSHD .. + +CALL "./Tools/Clean_All.bat" + +REM build... is where we will generate project files and compile the program into. +IF NOT EXIST build/ ( + MKDIR build +) + +CALL :FIND_WSL +CALL .\Tools\Util\FindCMake.bat +CALL :RUN_CMAKE %* + +POPD +GOTO :EOF + +:RUN_CMAKE +IF "%have_wsl%"=="0" ( + ECHO Warning: Not building Linux binaries. Please install WSL sub-system with GCC/G++ packages. +) + +IF "%~1"=="-debug" ( + echo Building - debug + + CALL .\Tools\Util\GenerateProject.bat -build-dir="x64-windows" -generator="Visual Studio 17 2022" -options="-A x64 -DIs64Bit:BOOL=ON" + CALL .\Tools\Util\GenerateProject.bat -build-dir="x86-windows" -generator="Visual Studio 17 2022" -options="-A Win32 -DIs64Bit:BOOL=OFF" + %cmake% --build "build/x64-windows" --config=Debug + %cmake% --build "build/x86-windows" --config=Debug + + IF "%have_wsl%"=="1" ( + CALL .\Tools\Util\GenerateProject.bat -build-dir="x64-linux" -generator="Ninja Multi-Config" -wsl -options="-DIs64Bit:BOOL=TRUE" + CALL .\Tools\Util\GenerateProject.bat -build-dir="x86-linux" -generator="Ninja Multi-Config" -wsl -options="-DIs64Bit:BOOL=FALSE" + wsl cmake --build "build/x64-linux" --config=Debug + wsl cmake --build "build/x86-linux" --config=Debug + ) + + PUSHD Tools + Powershell -executionpolicy remotesigned -File .\Build_ArmaMod.ps1 "-debug" + POPD +) ELSE ( + echo Building - release + + CALL .\Tools\Util\GenerateProject.bat -build-dir="x64-windows" -generator="Visual Studio 17 2022" -options="-A x64 -DIs64Bit:BOOL=ON" + CALL .\Tools\Util\GenerateProject.bat -build-dir="x86-windows" -generator="Visual Studio 17 2022" -options="-A Win32 -DIs64Bit:BOOL=OFF" + %cmake% --build "build/x64-windows" --config=Release + %cmake% --build "build/x86-windows" --config=Release + + IF "%have_wsl%"=="1" ( + CALL .\Tools\Util\GenerateProject.bat -build-dir="x64-linux" -generator="Ninja Multi-Config" -wsl -options="-DIs64Bit:BOOL=TRUE" + CALL .\Tools\Util\GenerateProject.bat -build-dir="x86-linux" -generator="Ninja Multi-Config" -wsl -options="-DIs64Bit:BOOL=FALSE" + wsl cmake --build "build/x64-linux" --config=Release + wsl cmake --build "build/x86-linux" --config=Release + ) + + PUSHD Tools + Powershell -executionpolicy remotesigned -File .\Build_ArmaMod.ps1 + POPD +) +GOTO :EOF + +:FIND_WSL +WHERE /Q wsl +IF %ERRORLEVEL% NEQ 0 ( + SET have_wsl=0 +) ELSE ( + SET have_wsl=1 +) +GOTO :EOF \ No newline at end of file diff --git a/Tools/Util/FindCMake.bat b/Tools/Util/FindCMake.bat new file mode 100644 index 0000000..0b03547 --- /dev/null +++ b/Tools/Util/FindCMake.bat @@ -0,0 +1,31 @@ +@ECHO OFF +SETLOCAL ENABLEDELAYEDEXPANSION + +SET cmake_=cmake +SET cmakegui_=cmake-gui + +REM First we check if we have cmake installed at path. +WHERE /Q cmake +IF %ERRORLEVEL% NEQ 0 ( + SET cmake_= +) + +WHERE /Q cmake-gui +IF %ERRORLEVEL% NEQ 0 ( + SET cmakegui_= +) + +REM If there is no cmake at path, we will search for cmake installed alongside visual studio. +IF "%cmake_%" == "" ( + FOR /f "usebackq tokens=*" %%i IN (`call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( + SET cmake_="%%i\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" + ) +) + +( + ENDLOCAL + set "cmake=%cmake_%" + set "cmakegui=%cmakegui_%" +) + +exit /b \ No newline at end of file diff --git a/Tools/Util/GenerateProject.bat b/Tools/Util/GenerateProject.bat new file mode 100644 index 0000000..65e81af --- /dev/null +++ b/Tools/Util/GenerateProject.bat @@ -0,0 +1,106 @@ +@ECHO OFF +SETLOCAL ENABLEDELAYEDEXPANSION + +set "options=-src:".\" -build-dir:"" -generator:"" -options:"" -opengui: -wsl:" +CALL :PARSE_ARG_LIST %* + +PUSHD !-src! +IF NOT EXIST ".\Tools\Util\GenerateProject.bat" ( + ECHO Incorrect -src parameter supplied. -src should be set to the source root. + exit /b 1 +) + +CALL :ENSURE_BUILD_DIR %build-dir% +CALL :FIND_CMAKE +CALL :RUN_CMAKE + +POPD + +GOTO :EOF + +REM =========================== +REM ======== Functions ======== +REM =========================== + +:ENSURE_BUILD_DIR +IF NOT EXIST build/ ( + MKDIR build +) +IF NOT EXIST "build/!-build-dir!/" ( + MKDIR "build/!-build-dir!" +) +GOTO :EOF + +:FIND_CMAKE +IF "!-wsl!" == "1" ( + SET cmake=wsl cmake + SET cmakegui= +) ELSE ( + ECHO %CD% + CALL .\Tools\Util\FindCMake.bat +) + +GOTO :EOF + +:RUN_CMAKE +PUSHD "build/!-build-dir!" + +%cmake% ../.. -G "!-generator!" !-options! + +POPD + +IF "!-opengui!" == "1" IF "!-wsl!" == "" ( + REM Run CMake GUI so user can select options + IF NOT "%cmakegui%" == "" ( + START %cmakegui% -S "." -B "build/!-build-dir!" + ) +) +GOTO :EOF + +:PARSE_ARG_LIST args +for %%O in (%options%) do for /f "tokens=1,* delims=:" %%A in ("%%O") do set "%%A=%%~B" + +:loop +if not "%~1"=="" ( + set "test=!options:*%~1:=! " + if "!test!"=="!options! " ( + echo Error: Invalid option %~1 + ) else if "!test:~0,1!"==" " ( + set "%~1=1" + ) else ( + setlocal disableDelayedExpansion + set "val=%~2" + call :escapeVal + setlocal enableDelayedExpansion + for /f delims^=^ eol^= %%A in ("!val!") do endlocal&endlocal&set "%~1=%%A" ! + shift /1 + ) + shift /1 + goto :loop +) +goto :endArgs +:escapeVal +set "val=%val:^=^^%" +set "val=%val:!=^!%" +exit /b +:endArgs + +set - +GOTO :EOF + + + + + + + + + + + + + + + + + diff --git a/VS2019_x64.bat b/VS2019_x64.bat deleted file mode 100644 index 6dd48aa..0000000 --- a/VS2019_x64.bat +++ /dev/null @@ -1,34 +0,0 @@ -@ECHO OFF -SETLOCAL ENABLEDELAYEDEXPANSION - -REM Build is where we will generate project files and compile the program into. -IF NOT EXIST Build_Win64/ ( - MKDIR Build_Win64 -) - -REM First we check if we have cmake installed at path. -WHERE cmake -IF %ERRORLEVEL% NEQ 0 ( - REM If there is no cmake at path, we will search for cmake installed alongside visual studio. - GOTO CMAKE_FROM_VS_INSTALL -) ELSE ( - GOTO CMAKE_LITERAL -) - -:CMAKE_FROM_VS_INSTALL -for /f "usebackq tokens=*" %%i in (`call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( - set InstallDir=%%i -) -SET cmake="%InstallDir%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -GOTO RUN_CMAKE - -:CMAKE_LITERAL -REM We found cmake, so we can just run the command as is. -SET cmake=cmake - -REM fallthrough intentionally to running cmake. -:RUN_CMAKE - -PUSHD Build_Win64 -%cmake% .. -G "Visual Studio 16 2019" -A x64 -POPD \ No newline at end of file diff --git a/VS2019_x86.bat b/VS2019_x86.bat deleted file mode 100644 index 6239bf4..0000000 --- a/VS2019_x86.bat +++ /dev/null @@ -1,34 +0,0 @@ -@ECHO OFF -SETLOCAL ENABLEDELAYEDEXPANSION - -REM Build is where we will generate project files and compile the program into. -IF NOT EXIST Build_Win32/ ( - MKDIR Build_Win32 -) - -REM First we check if we have cmake installed at path. -WHERE cmake -IF %ERRORLEVEL% NEQ 0 ( - REM If there is no cmake at path, we will search for cmake installed alongside visual studio. - GOTO CMAKE_FROM_VS_INSTALL -) ELSE ( - GOTO CMAKE_LITERAL -) - -:CMAKE_FROM_VS_INSTALL -for /f "usebackq tokens=*" %%i in (`call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( - set InstallDir=%%i -) -SET cmake="%InstallDir%\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -GOTO RUN_CMAKE - -:CMAKE_LITERAL -REM We found cmake, so we can just run the command as is. -SET cmake=cmake - -REM fallthrough intentionally to running cmake. -:RUN_CMAKE - -PUSHD Build_Win32 -%cmake% .. -G "Visual Studio 16 2019" -A Win32 -POPD \ No newline at end of file