Compile on Windows with Visual Studio 2017

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on Windows with Visual Studio 2017

Post by sgrogan »

zbigg wrote: Tue Mar 06, 2018 6:33 am Ive included MSVC2015 VC14 toolset while installing MSVC2017.
OK, I got a successful build using these tools. I will write up a procedure. I will try later today but if not I have more time tomorrow.
"fight the good fight"
User avatar
zbigg
Posts: 136
Joined: Tue Dec 19, 2017 1:11 pm

Re: Compile on Windows with Visual Studio 2017

Post by zbigg »

sgrogan wrote: Tue Mar 06, 2018 6:55 pm
zbigg wrote: Tue Mar 06, 2018 6:33 am Ive included MSVC2015 VC14 toolset while installing MSVC2017.
OK, I got a successful build using these tools. I will write up a procedure. I will try later today but if not I have more time tomorrow.
Fine, thats a progress. Waiting unpatiently 8-)
cheers,
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on Windows with Visual Studio 2017

Post by sgrogan »

zbigg wrote: Wed Mar 07, 2018 8:13 am Fine, thats a progress. Waiting unpatiently 8-)
I am using the conda python 3.6 version installed as a single user at the default path.

Open an Anaconda prompt and enter the following commands;

Code: Select all

conda config --add channels conda-forge
conda config --add channels freecad
conda config --add channels cad
conda create -n freecad freecad
activate freecad
conda install -c conda-forge swig
conda install -c conda-forge eigen 
Close the Anaconda prompt.

Create a .bat file from the following;

Code: Select all

set ENV_PREFIX=%userprofile%\Miniconda3\envs\freecad
set LIBRARY_PREFIX=%ENV_PREFIX%\Library
cmake -G "Visual Studio 15 2017 Win64" -T v140 ^
      -DBUILD_QT5=TRUE ^
      -DCMAKE_BUILD_TYPE=Release ^
      -DFREECAD_LIBPACK_USE=FALSE ^
      -DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX% ^
      -DCMAKE_INCLUDE_PATH=%LIBRARY_PREFIX%/include ^
      -DCMAKE_LIBRARY_PATH=%LIBRARY_PREFIX%/lib ^
      -DCMAKE_INSTALL_PREFIX=%ENV_PREFIX%\Library ^
      -DBUILD_FEM_NETGEN=FALSE ^
      -DNETGENDATA=%LIBRARY_PREFIX%/include ^
      -DNETGEN_INCLUDE_DIR=%LIBRARY_PREFIX%/include/netgen ^
      -DNGLIB_INCLUDE_DIR=%LIBRARY_PREFIX%/include/nglib ^
      -DOCC_INCLUDE_DIR=%LIBRARY_PREFIX%/include/opencascade ^
      -DOCC_LIBRARY_DIR=%LIBRARY_PREFIX%/lib ^
      -DOCC_LIBRARIES=%LIBRARY_PREFIX%/lib CACHE ^
      -DFREECAD_USE_OCC_VARIANT="Official Version" ^
      -DOCC_OCAF_LIBRARIES=%LIBRARY_PREFIX%/lib ^
      -DSWIG_EXECUTABLE=%LIBRARY_PREFIX%/bin/swig ^
      -DPYTHON_EXECUTABLE=%ENV_PREFIX%\python.exe ^
      -DBUILD_REVERSEENGINEERING=NO ^
      C:\Users\Chris\GitHub\FreeCAD
You will need to change the hard coded path (last line of script) to the absolute path to your FreeCAD source directory.
Place this .bat file in your equivalent of %ENV_PREFIX%\Library
Open a Command Prompt in your equivalent of %ENV_PREFIX%\Library
Run the .bat by double click.
Close the command window,
There should be FreeCAD_trunk.sln in your equivalent %ENV_PREFIX%\Library
Right click on the file and Open with > Microsoft Visual Studio 2017
Make sure you are set to Release x64 in the menu bar
Build > Build Solution
Right click on the "INSTALL (Visual Studio 2015)" project in Solution Explorer tab > Project Only > Build Only INSTALL
Close the Visual Studio 2017 IDE.
Open an Anaconda Prompt and enter the following commands

Code: Select all

activate freecad
freecad
Give me good news with "About FreeCAD" info :o
Last edited by sgrogan on Fri Mar 09, 2018 9:29 pm, edited 2 times in total.
"fight the good fight"
User avatar
zbigg
Posts: 136
Joined: Tue Dec 19, 2017 1:11 pm

Re: Compile on Windows with Visual Studio 2017

Post by zbigg »

haha,it would be too easy :)

1. Eigen3 needed - copied into env by hand.
2. Sth was totally f &^%$ up with swig. Had to correct 'by hand' (in bat you declared version 3.0.8 while present is 3.0.12 but nevertheless there was no folder share etc etc where it should be/.
But...

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13375 (Git)
Build type: Release
Branch: master
Hash: 2bfea410fce1434fec0f853b032549aa2cd3c47e
Python version: 3.6.4
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Polish/Poland (pl_PL)

Btw: Had nth against cmake -G "Visual Studio 15 2017 Win64" -T v141 ^
Noticeably faster then official builds )).

Would you mind helping to organize the built output how it should be? I mean like official ones.;
I went with all the conda through shell from within msvc2017, that may cause problems, I'll try to recreate everything excatly as You wrote w/Miniconda.
cheers,
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on Windows with Visual Studio 2017

Post by sgrogan »

zbigg wrote: Thu Mar 08, 2018 11:05 am 1. Eigen3 needed - copied into env by hand.
For me installing the package after activating freecad environment worked.
zbigg wrote: Thu Mar 08, 2018 11:05 am 2. Sth was totally f &^%$ up with swig. Had to correct 'by hand' (in bat you declared version 3.0.8 while present is 3.0.12 but nevertheless there was no folder share etc etc where it should be/.
This bogus path is not even needed. I removed it from my previous post. This may have worked for me because I installed swig after activating the freecad environment. Other wise the packages are installed in the base environment, I think. Tait's probably why you hand to correct by hand.
zbigg wrote: Thu Mar 08, 2018 11:05 am Btw: Had nth against cmake -G "Visual Studio 15 2017 Win64" -T v141 ^
Noticeably faster then official builds )).
You mean you built with the v141 toolset? For me I still get the internal compiler error from above. It would be great if it was just something locally for me, provided I can find the problem.
zbigg wrote: Thu Mar 08, 2018 11:05 am Would you mind helping to organize the built output how it should be? I mean like official ones.;
I went with all the conda through shell from within msvc2017, that may cause problems, I'll try to recreate everything excatly as You wrote w/Miniconda.
I'm not sure what you mean. Setting the CMAKE_INSTALL_PREFIX and running the INSTALL project is VS copies all the file to the correct location. For now this only works in the Conda freecad environment. I will work on a procedure to strip the necessary stuff out to make the build portable and independent from Conda.

And glad to see you have a working build. You can switch to the Test framework WB and run Self-test from the toolbar. I get a "Path-Utils" error that I think is PY2/PY3 porting issue. Other than that all other tests pass.

HUGE thanks to @looo :D
"fight the good fight"
User avatar
zbigg
Posts: 136
Joined: Tue Dec 19, 2017 1:11 pm

Re: Compile on Windows with Visual Studio 2017

Post by zbigg »

Yes, 1st time I succeeded to build. Only once ))
There are some notes however-may be subjective so correct me if needed.
1. Ive built from Powershell terminal from within Anaconda/Python addon from within MSVC2017.
2. Trying from Anaconda's or cmd shell gives me errors and/or I cant repeat the result so far. /eg. Python not found, even though path defined/
3. Yes. cmake indicated configured environment as v.19 etc toolset
4.I'll set custom prefixes for cmake
5. I expect to obtain repeatable results, then we can make a toast ;)
6. Needed to add in your batch:
-DSWIG_EXECUTABLE=%ENV_PREFIX%/Scripts/swig.exe ^
-DDOXYGEN_EXECUTABLE=%ENV_PREFIX%/Scripts/doxygen.exe ^
Still dont know why/if/how DOT component should be added...;
7. Unclear to me double declaration? :
-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
-DCMAKE_INSTALL_PREFIX=%ENV_PREFIX%\Library\
8. Ok, I can repeat the result now but get 'missing Python' error...,would you advice cmake entry to include all target libs, incl.Python module in install dir ?
cheers,
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on Windows with Visual Studio 2017

Post by sgrogan »

zbigg wrote: Fri Mar 09, 2018 3:15 pm 6. Needed to add in your batch:
-DSWIG_EXECUTABLE=%ENV_PREFIX%/Scripts/swig.exe ^
-DDOXYGEN_EXECUTABLE=%ENV_PREFIX%/Scripts/doxygen.exe ^
Still dont know why/if/how DOT component should be added...;
I think you are using the base environment swig. I installed swig (it's probably a duplicate copy) into the freecad environment. is why I used an Anaconda prompt and and installed swig AFTER activating the FreeCAD environment
doxygen builds the source documentation, not necessary for a release build (and not required for the elusive debug build). CMake only throws an warning that can be safely ignored.
What do you set ENV_PREFIX= to?
zbigg wrote: Fri Mar 09, 2018 3:15 pm 7. Unclear to me double declaration? :
-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
-DCMAKE_INSTALL_PREFIX=%ENV_PREFIX%\Library\
Yes, I am using -DCMAKE_INSTALL_PREFIX=%ENV_PREFIX%\Library\ I edited my previous post to delete the duplicate. Using -DCMAKE_INSTALL_PREFIX=%ENV_PREFIX%\Library\ overwrites the FreeCAD specific stuff installed by conda.
zbigg wrote: Fri Mar 09, 2018 3:15 pm 8. Ok, I can repeat the result now but get 'missing Python' error...,would you advice cmake entry to include all target libs, incl.Python module in install dir ?
I am working on a solution to this. This is why I have to run FreeCAD from an Anaconda prompt after activating freecad in the prompt. Maybe it's as simple as installing python directly in the freecad environment, like I did with swig and eigen? (I'll try)
"fight the good fight"
User avatar
zbigg
Posts: 136
Joined: Tue Dec 19, 2017 1:11 pm

Re: Compile on Windows with Visual Studio 2017

Post by zbigg »

Ok.
As to ENV_PREFIX: set ENV_PREFIX=D:\conda\envs\freecad
You had it in your User's profile, system C disk,mine is SDD so I want to save as much space moving all possible to next HDDs.;

That would be great to create consistent and correct runtime enviro.
Btw.-maybe a stupid statement-but I cant have FC running even after copying lacking files from www 'daily' build folder.
Running from conda's env, as per your suggestion, starts FC but gives errors: eg. C++ exeption or module 'Freecad' has no attribute <WorkbenchName>.
Unfortunately starting Self-tests causes only START button to become greyed out and nth happens...
Update: Ran 2nd time both simpler tests passed but extended one gives errors: No module named 'PathUtils'
Failure: testActivate (Workbench.WorkbenchTestCase)


OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13381 (Git)
Build type: Release
Branch: master
Hash: d95656d812f56da945f0624d8d4c70412ae17460
Python version: 3.6.4
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Polish/Poland (pl_PL)

Well yes, its FASTER ))
cheers,
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on Windows with Visual Studio 2017

Post by sgrogan »

zbigg wrote: Fri Mar 09, 2018 10:02 pm Update: Ran 2nd time both simpler tests passed but extended one gives errors: No module named 'PathUtils'
Failure: testActivate (Workbench.WorkbenchTestCase)
This is a real error, this portion of the code passes for PY2 and fails for PY3 (even on my ubuntu PY3 build, no conda)
zbigg wrote: Fri Mar 09, 2018 10:02 pm That would be great to create consistent and correct runtime enviro.
This is the goal. We are consistent with the "environment" we are using to build. My goal, as a first step, is to copy the necessary stuff out of the conda environment. This will simultaneously reduce the package size and make it portable like the Win "daily" release builds. Second step is to copy the dependencies out of the environment and create a Libpack, with the same gains. The backbone will remain Conda, but it will only be a concern for package managers. See here:https://forum.freecadweb.org/viewtopic. ... 02#p219061, and feel free to express what you think is desirable, from a windows point of view.
"fight the good fight"
User avatar
zbigg
Posts: 136
Joined: Tue Dec 19, 2017 1:11 pm

Re: Compile on Windows with Visual Studio 2017

Post by zbigg »

The latter goal is a challenge. So far building/Luxrender, Mypaint etc/ I tried with cmake-gui, step by step finding and building needed deps.
Do you know any tool could do it for us? Or are we left with Gentoo Linux scenario :lol: ?
cheers,
Post Reply