CompileOnWindows - Reducing Disk Footprint/fr

Techniques pour réduire l'espace disque nécessaire à l'installation de FreeCAD sous Windows. Ceci peut être utile à ceux qui sont limités par l'espace disque (par exemple, à cause d'un SSD) et à ceux qui veulent éviter d'installer complètement Visual Studio.

Il est recommandé de savoir, en pratique, comment Compiler sous Windows avec Qt Creator avant d'essayer ceci.

Configurer le compilateur MSVC2013 sans installer Visual Studio
Conditions requises :
 * un autre ordinateur où Visual Studio complet est/peut être installé (en théorie, cela peut être réalisé en décompressant les installateurs VS, mais il n'y a pas d'instructions à ce sujet ici)

Lancer le compilateur
0. Pour obtenir les fichiers du compilateur, allez sur un autre ordinateur et localisez le compilateur utilisé. Exemple de chemin d'accès au compilateur : drive:\path\to\visual\studio\VC\bin.

1. Copiez les binaires du compilateur et les bibliothèques standard sur un autre ordinateur. C'est-à-dire, copiez les dossiers suivants dans C:\Qt\msvc12rip :
 * drive:\path\to\visual\studio\VC\bin
 * drive:\path\to\visual\studio\VC\lib
 * drive:\path\to\visual\studio\VC\include

2. Installez Windows SDK. Pour ceux qui ne le savent pas, c'est un ensemble d'en-têtes, de librairies et d'outils pour compiler des programmes Windows. Notez l'endroit où il est installé. Exemple de chemin : C:\Program Files (x86)\Windows Kits\8.1

3. Installez CMake et Qt creator (juste le creator, c'est à dire l'environnement, pas le Qt lui-même, pour gagner de la place).

4. Configurer un compilateur personnalisé dans Qt Creator. Lisez la suite pour savoir comment.

32-bit
Configurer le compilateur pour 32 bits est assez simple.

4.1. Configurer le compilateur sous l'onglet Compilateurs dans les paramètres : Ajouter un compilateur personnalisé :
 * nom = msvcrip (le nom n'a pas d'importance, c'est vous qui décidez)
 * Chemin du compilateur : C:\Qt\msvc12rip\VC\bin\cl.exe
 * Chemin d'accès au programme : C:\Qt\msvc12\V\C\bin\nmake.exe
 * ABI : x86-windows-msvc2013-pe-32bit
 * Chemins d'en-tête : rien
 * Analyseur d'erreurs : MSVC

4.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)

Note the path to git.exe in PATH. It is optional, but if not specified, the version info will be incomplete in FreeCAD's About.
 * 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 is a little bit more tricky than 32-bit compiler. The main problem was that there is no nmake executable in C:\Qt\msvc12rip\VC\bin\x86_amd64, and nmake keeps using the 32-bit compiler. To counter the problem, create a special folder "C:\Qt\msvc12rip\VC\bin\x86_amd64_sa", where mnake and 64-bit cl are combined. Read on for step-by-step instructions.

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

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

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

4.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

4.5. Under kits tab, add 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.4)
 * Environment: (correct the paths to your setup) (compared to 32-bit, amd64/x64 has appeared or has replaced x86 in several places)

Note the path to git.exe in PATH. It is optional, but if not specified, the version info will be incomplete in FreeCAD's About.
 * Debugger: (optional) set to 64-bit (x64)
 * Qt version: None

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

All the rest is identical to the normal way one would compile FreeCAD.

testing compiler and building FreeCAD
requirements:
 * FreeCAD source code (see Compile on Windows)
 * Correct libpack, extracted. ("correct" means that it has to match the compiler and bit-ness) (see Compile on Windows)

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. The build output should help you identify, what's going wrong. Here is a small list of typical errors:
 * 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 (msvcp120d.dll, msvcr120d.dll) must be present somewhere reacheable through PATH (system-wide, this time).

You can obtain these dlls from the other computer that has the Visual Studio you ripped the compiler off. Alternatively, these dlls can be extracted from visual studio installer directly, which is very easy:
 * 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  (<- or x86, if you are building 32-bit)
 * D:\packages\vc_librarycore86\cab3.cab/F_REDIST_DLL_APPLOCAL_msvcr120d_x64
 * extract the files, and name them "msvcp120d.dll", "msvcr120d.dll"
 * copy the files to libpack folder, into bin

Éviter de copier tous les fichiers libpack pour lancer FreeCAD
exigences:
 * Windows Vista et versions ultérieures
 * Système de fichiers NTFS (? Peut-être pas ...)

The idea is very simple: instead of copying files - make links. On Windows, symbolic links are available for the purpose. A link makes the linked file appear to be where the link is, but the file is actually stored somewhere else. Links can be made using batch command mklink.

Since there are way too many files to make links manually, a batch script should be used. Here is an example of such a script:

links_libpack.bat: First for loop creates links to files, the second loop - links to folders.

You'll have to modify the path to libpack to match yours. Use absolute paths. Then, feed FreeCAD build folder path (full path!) to the script as an argument.

This batch must be run with administrator privileges (or, you can set to allow users use mklink in local security policy settings in Windows). The batch may fail, if there are spaces in paths (it may work, but it is untested). Tip: create a shortcut to links_libpack.bat, set it up to run as admin (in shortcut properties), and drag the build folder onto the shortcut.