diff --git a/README.md b/README.md index 5971672c77..42c444def6 100644 --- a/README.md +++ b/README.md @@ -34,16 +34,16 @@ the cmake/ folder. The preferred way to fetch and build this project's dependencies is to use the build scripts in win/ folder. See [win/readme.md] for more information. Instructions in a nutshell -(assuming Visual Studio x64 environment variables set): +(**assuming Visual Studio 2015 x64 environment variables set**): > git clone https://github.com/IfcOpenShell/IfcOpenShell.git > cd oce\win - > build-deps.cmd (defaults to using VS 2015 x64 RelWithDebInfo build) - > run-cmake.bat (defaults to using VS 2015 x64) + > build-deps.cmd (defaults to RelWithDebInfo build) + > run-cmake.bat > ..\build-vs2015-x64\IfcOpenShell.sln -You can now build the solution using the RelWithDebInfo configuration (freshly created solution by CMake defaults to Debug). -Build the INSTALL project to deploy the headers and binaries into a single location if wanted/needed. +You can now build the solution using the `RelWithDebInfo` configuration (freshly created solution by CMake defaults to `Debug`). +Build the `INSTALL` project to deploy the headers and binaries into a single location if wanted/needed. Alternatively, the old Visual Studio solution and project files requiring manual work can be found from the win/sln folder. diff --git a/win/readme.md b/win/readme.md index 0b7e8a3d9e..aa232dd260 100644 --- a/win/readme.md +++ b/win/readme.md @@ -14,19 +14,21 @@ the requirements for a successful execution. The script allows a few user-config which are listed in the usage instructions. Either edit the script file or set these values before running the script. -`build-deps.cmd` expects a CMake generator as `%1` and a build configuration type as `%2`. If the parameters -are not provided, the default values are used (`"Visual Studio 14 2015 Win64"` and `RelWithDebInfo` respectively). -A build type (`Build/Rebuild/Clean`) can be provided as `%3`, if wanted (defaults to `Build`). See `vs-cfg.cmd` -if you want to change the defaults. The batch file will create `deps\` and `deps-vs--installed\` +`build-deps.cmd` expects a CMake generator as `%1` and a build configuration type (`RelWithDebInfo/Release/MinSizeRel/Debug`, +defaults to `RelWithDebInfo`) as `%2`. If the generator is not provided, the generator is deduced from the Visual Studio +environment variables. A build type (`Build/Rebuild/Clean`, defaults to `Build`) can be provided as `%3`. See `vs-cfg.cmd` +if you wish to change the defaults. The batch file will create `deps\` and `deps-vs--installed\` directories to the project root. Debug and release builds of the depedencies can co-exist by simply running `build-deps.cmd Debug` and `build-deps.cmd `. -After the dependencies are build, execute `run-cmake.bat`. The batch file expects always a CMake generator as -`%1` (if not provided, the same default value as above is used), and the rest of possible parameters are passed as is. +After the dependencies are build, execute `run-cmake.bat`. The batch file expects always a CMake generator as `%1` +(if not provided, the same default value as above is used), and the rest of possible parameters are passed as is. +**If you wish to use any library from a custom location, modify the paths in `run-cmake.bat` accordingly**. The batch +script will create a folder of form `build-vs-\` which will contain the solution and project +files for Visual Studio. -The batch script will create a folder of form `build-vs-\` which will contain the solution and project files for Visual Studio. -**If you wish to use any library from a custom location, modify the paths in run-cmake.bat -accordingly**. +Note that building IfcOpenShell as 64-bit is recommended as many of real life IFC files has been observed to take +easily more than 2 GBs of RAM while converting. After this, one can build the project using the `IfcOpenShell.sln` file in the build folder. Build the `INSTALL` project if wanted. The project will be installed to `installed-vs-\` folder in the project's root diff --git a/win/run-cmake.bat b/win/run-cmake.bat index 3ee00e731a..e689ea28ab 100644 --- a/win/run-cmake.bat +++ b/win/run-cmake.bat @@ -26,6 +26,7 @@ set PROJECT_NAME=IfcOpenShell setlocal EnableDelayedExpansion :: TODO Getting warning print in vs-cfg.cmd for missing build type although this script doesn't need it specified call vs-cfg.cmd %1 +IF NOT %ERRORLEVEL%==0 GOTO :Error :: Read Python related variables from BuildDepsCache.txt for /f "delims== tokens=1,2" %%G in (BuildDepsCache-%TARGET_ARCH%.txt) do set %%G=%%H @@ -103,7 +104,7 @@ goto :Finish :Error echo. -cecho {0C}An error occurred! Aborting!" +call %~dp0\utils\cecho.cmd 0 12 "An error occurred! Aborting!" goto :Finish :Finish diff --git a/win/vs-cfg.cmd b/win/vs-cfg.cmd index bcc6f6b996..3f8294699f 100644 --- a/win/vs-cfg.cmd +++ b/win/vs-cfg.cmd @@ -19,6 +19,8 @@ :: This script initializes various Visual Studio -related environment variables needed for building :: This batch file expects CMake generator as %1 and build configuration type as %2. +:: If %1 is not provided, it is deduced from the VisualStudioVersion environment variable and from the location of cl.exe. + :: NOTE This batch file expects the generator string to be CMake 3.0.0 and newer format, i.e. :: "Visual Studio 10 2010" instead of "Visual Studio 10". However, one can use this batch file :: also with CMake 2 as the generator will be converted into the older format if necessary. @@ -33,29 +35,43 @@ set GENERATOR=%1 :: F.ex. "vs2013-32" and/or "vc14-64" :: Supported Visual Studio versions: -set GENERATORS[0]="Visual Studio 14 2015" -set GENERATORS[1]="Visual Studio 14 2015 Win64" -set GENERATORS[2]="Visual Studio 12 2013" -set GENERATORS[3]="Visual Studio 12 2013 Win64" -set GENERATORS[4]="Visual Studio 11 2012" -set GENERATORS[5]="Visual Studio 11 2012 Win64" -set GENERATORS[6]="Visual Studio 10 2010" -set GENERATORS[7]="Visual Studio 10 2010 Win64" -set GENERATORS[8]="Visual Studio 9 2008" -set GENERATORS[9]="Visual Studio 9 2008 Win64" -set GENERATOR_DEFAULT=%GENERATORS[1]% +set GENERATORS[0]="Visual Studio 9 2008 Win64" +set GENERATORS[1]="Visual Studio 9 2008" +set GENERATORS[2]="Visual Studio 10 2010 Win64" +set GENERATORS[3]="Visual Studio 10 2010" +set GENERATORS[4]="Visual Studio 11 2012 Win64" +set GENERATORS[5]="Visual Studio 11 2012" +set GENERATORS[6]="Visual Studio 12 2013 Win64" +set GENERATORS[7]="Visual Studio 12 2013" +set GENERATORS[8]="Visual Studio 14 2015 Win64" +set GENERATORS[9]="Visual Studio 14 2015" +set LAST_GENERATOR_IDX=9 -IF "!GENERATOR!"=="" ( - set GENERATOR=%GENERATOR_DEFAULT% - call utils\cecho.cmd 0 14 "%~nx0: Warning: Generator not passed - using the default '`"%GENERATOR_DEFAULT%`'`t +REM Deduce desired architecture from the location of cl.exe +where cl.exe | findstr /r /c:"amd64" >nul +set START=%ERRORLEVEL% +set STEP=2 + +IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" ( + set VC_VER=%VisualStudioVersion:.0=% + FOR /l %%i in (%START%,%STEP%,%LAST_GENERATOR_IDX%) DO ( + REM http://stackoverflow.com/a/8758579 + REM NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012" + echo(!GENERATORS[%%i]! | findstr /r /c:" !VC_VER!" >nul && ( + set GENERATOR=!GENERATORS[%%i]! + call utils\cecho.cmd black cyan "Generator not passed, but VisualStudioVersion=%VisualStudioVersion% environment variable detected:" + call utils\cecho.cmd black cyan "using '`"!GENERATOR!`'" as the generator." + GOTO :GeneratorValid + ) + ) ) -FOR /l %%i in (0,1,9) DO ( +FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid ) call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'". Cannot proceed, aborting!" echo Supported CMake generator strings: -FOR /l %%i in (0,1,9) DO ( +FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( echo !GENERATORS[%%i]! ) exit /b 1