User:DeepSOIC

CompileOnWindows - reducing disk footprint

Techniques to reduce disk space required for building FreeCAD on windows

setting up MSVC2013 compiler without installing Visual Studio
This is a short story of how I managed to set up FreeCAD compilation on Windows8.1 with MSVC2013 compiler without actually installing the huge visual studio express.

getting the compiler
First, I used another computer to install the full visual studio, in order to get the compiler files. I found the compiler under drive:\path\to\visual\studio\VC\bin

Copied the compiler binaries and standard libraries to another computer. I copied the following folders to C:\Qt\msvc12rip
 * drive:\path\to\visual\studio\VC\bin
 * drive:\path\to\visual\studio\VC\lib
 * drive:\path\to\visual\studio\VC\include

Then I installed Windows SDK (google for it). For those who don't know, it is a set of headers, libs and tools to compile Windows programs. By default, it installed itself to

Then I installed CMake and Qt creator (just the creator, i.e. the environment, not the actual Qt, to save space).

Next was the trickiest part - to set up the compiler in Qt Creator.

32-bit
Setting the compiler for 32 bit is quite straightforward. 1. Set up the compiler under Compilers tab in settings: Add a custom compiler:
 * name = msvcrip (the name doesn't matter, it is up to you)
 * Compiler path: C:\Qt\msvc12rip\VC\bin\cl.exe
 * Make path: C:\Qt\msvc12rip\VC\bin\nmake.exe
 * ABI: x86-windows-msvc2013-pe-32bit
 * header paths - nothing
 * error parser: MSVC

2. Under kits tab, I added a kit, and set it up like this:
 * name: FreeCAD32 (again, up to you)
 * Device type: Desktop
 * Device: Local PC
 * Compiler: msvcrip (or whatever you named it in step 1)
 * Environment: (correct the paths to your setup)


 * Debugger: (optional) set to 32-bit (x86)
 * Qt version: None

The environment part of the settings took me the most trouble to configure

64-bit
This was quite a bit more tricky to figure out how to do. The main problem was that there is no nmake executable in C:\Qt\msvc12rip\VC\bin\'x86_amd64', and nmake kept using the 32-bit compiler. To counter the problem, I created a special folder "C:\Qt\msvc12rip\VC\bin\'x86_amd64_sa'", where I just combined the contents of folders C:\Qt\msvc12rip\VC\bin and C:\Qt\msvc12rip\VC\bin\x86_amd64. So, the instruction looks like this:

1. in C:\Qt\msvc12rip\VC\bin, create a folder named 'x86_amd64_sa' (sa stands for Stand-Alone, use whatever name you like).

2. copy contents of folder C:\Qt\msvc12rip\VC\bin into x86_amd64_sa folder (now you have a 32-bit compiler there)

3. copy contents of folder x86_amd64 into x86_amd64_sa, replacing some files in the process. Now you have a 64bit compiler with nmake there.

4. Set up the compiler under Compilers tab in settings: Add a custom compiler:
 * name = msvcrip64 (the name doesn't matter, it is up to you)
 * Compiler path: C:\Qt\msvc12rip\VC\bin\x86_amd64_sa\cl.exe
 * Make path: C:\Qt\msvc12rip\VC\bin\x86_amd64_sa\nmake.exe
 * ABI: x86-windows-msvc2013-pe-64bit
 * header paths - nothing
 * error parser: MSVC

5. Under kits tab, I added a kit, and set it up like this:
 * name: FreeCAD64 (again, up to you)
 * Device type: Desktop
 * Device: Local PC
 * Compiler: msvcrip64 (or whatever you named it in step 4)
 * Environment: (correct the paths to your setup; compared to 32-bit, amd64/x64 has appeared or has replaced x86 in several places)


 * Debugger: (optional) set to 64-bit (x64)
 * Qt version: None

I have also set up another kit+compiler pair for using jom instead of nmake, to enable multicore build. The configuration was identical to 64-bit with nmake, except for that in path to Make in compiler tab, I set it to C:\Qt\Qt542\Tools\QtCreator\bin\jom.exe (you should be able to find jom under where your Qt creator is installed).

testing compiler and building FreeCAD
All the rest is identical to the normal way one would compile FreeCAD:

Open FreeCAD (CMakeLists.txt) with Qt creator, and it will invite you to run cmake. Run it. CMake will build a test program, to see if the compiler works. If the compiler doesn't work, it will show an error telling exactly that, and listing the build output. This should help you identify, what's going wrong. Typical errors I got:
 * Can't open Kernel32.lib - something's wrong with LIB or LIBPATH environment variables (note: they set under kits tab in Qt, not in windows!)
 * can't resolve external symbol - something's wring with LIB or LIBPATH (they probably point to .lib-s of wrong bit-ness)
 * manifest-related error: PATH does not point to a location where a resource compiler (rc.exe) of right bit-ness is located.
 * can't locate include - the include location list should contain path to standard headers (C:\Qt\msvc12rip\VC\include on my machine)

To run FreeCAD built with type "Debug", debug versions of MSVC2013 redistributable libraries must be present somewhere reacheable through PATH (system-wide, this time).

These dlls can be extracted from visual studio installer:
 * mount the downloaded .iso image as a disk (drive D: on my system)
 * locate the files:
 * D:\packages\vc_librarycore86\cab3.cab/F_REDIST_DLL_APPLOCAL_msvcp120d_x64
 * D:\packages\vc_librarycore86\cab3.cab/F_REDIST_DLL_APPLOCAL_msvcr120d_x64
 * extract the files, and name them "msvcp120d_x64.dll", "msvcr120d_x64.dll"
 * copy the files to FreeCAD build folder, into bin.

avoiding copying any libpack files to launch FreeCAD
The idea is very simple: instead of copying files - make links. On Windows, there are symbolic links to files. They appear to be where the link is, but actually reside somewhere else. To make them, one should use batch command mklink.

I have come up with a batch script to automate the process of making links for each libpack's binary to FreeCAD build folder:

You'll have to modify the path to libpack to match yours. Then, feed FreeCAD build folder path (full path!) to the script as an argument. Note: the batch may fail, if there are spaces in paths (it may work, but it is untested).