diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dae0b6..1e5b763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # CMakeList.txt : CMake project for OpenSHC -cmake_minimum_required (VERSION 3.20) +cmake_minimum_required (VERSION 3.21) # NOTE: POST_BUILD does not run if the target is unchanged, so a config switch will not trigger them again, so clean + build if issues happen function(target_file_copy_if_different TARGET FILE DEST) diff --git a/CMakePresets.json b/CMakePresets.json index 22cd0ed..0052602 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,12 +2,12 @@ "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 19, + "minor": 21, "patch": 0 }, "configurePresets": [ { - "name": "nmake-base", + "name": "configure-base", "hidden": true, "generator": "NMake Makefiles", "binaryDir": "${sourceDir}/build-${presetName}", @@ -41,7 +41,7 @@ }, { "name": "Debug", - "inherits": "nmake-base", + "inherits": "configure-base", "description": "VS2005 NMake (Debug) x86", "cacheVariables": { "CMAKE_BUILD_TYPE": "${presetName}" @@ -49,11 +49,39 @@ }, { "name": "RelWithDebInfo", - "inherits": "nmake-base", + "inherits": "configure-base", "description": "VS2005 NMake (RelWithDebInfo) x86", "cacheVariables": { "CMAKE_BUILD_TYPE": "${presetName}" } } + ], + "buildPresets": [ + { + "name": "build-base", + "hidden": true, + "environment": { + "VSINSTALLDIR": "${sourceDir}/MSVC1400", + "VCINSTALLDIR": "${sourceDir}/MSVC1400/VC", + "FrameworkDir": "C:/WINDOWS/Microsoft.NET/Framework", + "FrameworkVersion": "v2.0.50727", + "FrameworkSDKDir": "${sourceDir}/MSVC1400/SDK/v2.0", + "DevEnvDir": "${sourceDir}/MSVC1400/Common7/IDE", + "PATH": "${sourceDir}/MSVC1400/Common7/IDE;${sourceDir}/MSVC1400/VC/bin;${sourceDir}/MSVC1400/Common7/Tools;${sourceDir}/MSVC1400/Common7/Tools/Bin;${sourceDir}/MSVC1400/VC/PlatformSDK/Bin;C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727", + "INCLUDE": "${sourceDir}/MSVC1400/VC/include;${sourceDir}/MSVC1400/VC/PlatformSDK/Include", + "LIB": "${sourceDir}/MSVC1400/VC/lib;${sourceDir}/MSVC1400/VC/PlatformSDK/Lib", + "LIBPATH": "C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727" + } + }, + { + "name": "Debug", + "inherits": "build-base", + "configurePreset": "Debug" + }, + { + "name": "RelWithDebInfo", + "inherits": "build-base", + "configurePreset": "RelWithDebInfo" + } ] } diff --git a/README.md b/README.md index 06d6853..ab11847 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,11 @@ Additionally, it configures format-on-save and a debug target for the UCP3. If the scripts are preferred, the following triggers a build using the scripts: 1. Open a terminal. If the Visual Studio CMake version is used, it needs to be the CMD developer command prompt. 2. Navigate to this project folder -3. Invoke vsvars32-portable.bat from the MSVC1400 in the developer command prompt session. Check with `where cl.exe` to see if it was successful: cl.exe and link.exe are supposed to be executed from your MSVC1400 folder. `where cmake` should point to your CMake installation. -4. Execute build.bat: +3. Execute build.bat: ```sh build.bat RelWithDebInfo ``` -5. Compare a function byte by byte to check compilation: +4. Compare a function byte by byte to check compilation: ```sh reccmp-reccmp --target STRONGHOLDCRUSADER --verbose 0x401000 ``` diff --git a/build.bat b/build.bat index 2311a6c..ec7c650 100644 --- a/build.bat +++ b/build.bat @@ -1,70 +1,17 @@ @echo off setlocal EnableDelayedExpansion -:: --- Validate task parameter (clean, build, rebuild) --- +:: --- Validate preset parameter (required) --- if "%~1"=="" ( - echo [ERROR] Task not specified. - echo Usage: %~nx0 [clean^|build^|rebuild] [BuildType] + echo [ERROR] Preset not specified. + echo Usage: %~nx0 ^ [Target] + echo ^ : Required. The CMake configure/build preset to use. + echo [Target] : Optional. The specific target to build. If omitted, the default target will be built. exit /b 1 ) -set "TASK=%~1" - -if /I not "%TASK%"=="clean" if /I not "%TASK%"=="build" if /I not "%TASK%"=="rebuild" ( - echo [ERROR] Invalid task: "%TASK%" - echo Valid tasks are: clean, build, rebuild - exit /b 1 -) - -:: --- Validate build type parameter (must be only letters) --- -if "%~2"=="" ( - echo [ERROR] Build type not specified. - echo Usage: %~nx0 [clean^|build^|rebuild] [BuildType] - exit /b 1 -) - -:: --- Validate that is is at least all letters, also need to use "." hack due to piping issue with *$ in findstr (. consumes \r) --- -echo %~2 | findstr /R "^[a-zA-Z][a-zA-Z]*.$" >nul -if errorlevel 1 ( - echo [ERROR] Invalid build type: "%~2" - echo It must only contain letters ^(e.g., Debug, Release^). - exit /b 1 -) - -:: --- Set build directory --- -set "BUILD_DIR=build-%~2" - -:: --- Clean build directory if task is clean or rebuild --- -if /I not "%TASK%"=="build" ( - if exist "%BUILD_DIR%" ( - echo Cleaning build directory "%BUILD_DIR%"... - rmdir /S /Q "%BUILD_DIR%" - if errorlevel 1 ( - echo [ERROR] Failed to clean build directory "%BUILD_DIR%". - exit /b 1 - ) - echo Clean completed successfully. - ) else ( - echo Build directory "%BUILD_DIR%" does not exist. Nothing to clean. - ) -) - -:: --- If task is clean only, exit after cleaning --- -if /I "%TASK%"=="clean" ( - exit /b 0 -) - -:: --- Check and load old environment into context --- -set "VSVARS=MSVC1400\vsvars32-portable.bat" -if not exist "%VSVARS%" ( - echo [ERROR] Could not find environment setup script: %VSVARS% - exit /b 1 -) -call "%VSVARS%" -if errorlevel 1 ( - echo [ERROR] Failed to execute: %VSVARS% - exit /b 2 -) +set "PRESET=%~1" +set "TARGET=%~2" :: --- Check for cmake --- where cmake >nul 2>nul @@ -74,7 +21,9 @@ if errorlevel 1 ( echo [ERROR] 'vswhere' not found, cannot locate 'cmake'. exit /b 1 ) - FOR /F "tokens=* USEBACKQ" %%g IN (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath -requires Microsoft.VisualStudio.Component.VC.CMake.Project`) do (SET "CMAKE=%%g\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin") + FOR /F "tokens=* USEBACKQ" %%g IN (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath -requires Microsoft.VisualStudio.Component.VC.CMake.Project`) do ( + SET "CMAKE=%%g\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin" + ) echo [INFO] Detected: "!CMAKE!" if not exist "!CMAKE!" ( echo [ERROR] 'cmake' is not found in PATH and not found using vswhere. @@ -83,13 +32,6 @@ if errorlevel 1 ( set "PATH=!CMAKE!;%PATH%" ) -:: --- Check for nmake --- -where nmake >nul 2>nul -if errorlevel 1 ( - echo [ERROR] 'nmake' is not found in PATH. - exit /b 1 -) - :: --- Kill mspdbsrv.exe if it's running --- tasklist | find /I "mspdbsrv.exe" >nul if not errorlevel 1 ( @@ -97,33 +39,32 @@ if not errorlevel 1 ( taskkill /f /t /im mspdbsrv.exe >nul if errorlevel 1 ( echo [WARNING] Failed to stop mspdbsrv.exe, continuing... - ) -) - -:: --- Create build directory --- -if not exist "%BUILD_DIR%" ( - mkdir "%BUILD_DIR%" >nul 2>&1 - if errorlevel 1 ( - echo [ERROR] Failed to create build directory "%BUILD_DIR%". - exit /b 1 ) ) -:: --- Run cmake and nmake --- -pushd "%BUILD_DIR%" -cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%~2 +:: --- Run cmake configure using preset --- +echo [INFO] Configuring with preset "%PRESET%"... +cmake --preset "%PRESET%" if errorlevel 1 ( - echo [ERROR] cmake failed. - popd + echo [ERROR] CMake configure failed for preset "%PRESET%". exit /b 1 ) -nmake -if errorlevel 1 ( - echo [ERROR] nmake build failed. - popd - exit /b 1 +:: --- Run cmake build using preset --- +if "%TARGET%"=="" ( + echo [INFO] Building preset "%PRESET%" with default target... + cmake --build --preset "%PRESET%" + if errorlevel 1 ( + echo [ERROR] CMake build failed for preset "%PRESET%". + exit /b 1 + ) + echo Build completed successfully for preset "%PRESET%". +) else ( + echo [INFO] Building preset "%PRESET%" with target "%TARGET%"... + cmake --build --preset "%PRESET%" --target "%TARGET%" + if errorlevel 1 ( + echo [ERROR] CMake build failed for preset "%PRESET%" target "%TARGET%". + exit /b 1 + ) + echo Build completed successfully for preset "%PRESET%" target "%TARGET%". ) - -popd -echo Build completed successfully for "%~2" configuration. diff --git a/create-include-lists.cmake b/create-include-lists.cmake index 38c96eb..8d5792d 100644 --- a/create-include-lists.cmake +++ b/create-include-lists.cmake @@ -5,7 +5,7 @@ # Usage: cmake -P generate_file_list.cmake # ====================================================================== -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) function(generate_file_list SOURCE_ROOT PATTERNS_LIST OUTPUT_FILE) set(ALL_ENTRIES "")