[OpenSCAD] Compiling for Windows

Jamie_K vector76 at gmail.com
Thu Jun 23 06:00:07 EDT 2016


First I'd like to say buttim's comment about the cmake version dependency was
spot on.  Later versions of cmake (not exactly sure but guessing cmake 3.3.0
and later) will fail on the version of cgal (4.5) pulled by the openscad
fork of mxe (https://github.com/openscad/mxe).

Unfortunately it appears my Fedora 23 cannot downgrade cmake low enough for
it to work with cgal 4.5.  It might have been possible to get an older cmake
by going outside the package manager to install the older cmake, but that's
beyond what I have patience for, so I'm basically stuck with the newer,
incompatible cmake.

Ultimately I was able to build two ways:
1. By using the latest mxe and fixing a dynamic vs. static bug in it
2. By fixing cgal 4.5 to be compatible with cmake 3.4.3


For the first method, pointing to the latest mxe was fairly simple:
1. Get all the openscad stuff
git clone https://github.com/openscad/openscad.git
2. modify scripts/mingw-x-build-dependencies.sh to point to mxe/mxe.git
instead of openscad/mxe.git by modifying line 69 to be:
git clone git://github.com/mxe/mxe.git $MXEDIR
and also remove "git checkout openscad-snapshot-build", to get master
instead of branch
3. within release-common.sh, change references 'i686-pc-mingw32-makensis' to
'i686-w64-mingw32.static-makensis' instead, since that's the name of the
makensis binary (lines 136 and 144)
4. There is apparently a bug in the latest mxe, where it will always build
shared libraries for cgal regardless of whether static or dynamic is
requested.  I believe this update introduced the problem:
https://github.com/mxe/mxe/commit/9f0dbfafc60b725dc09c85059b5b58c3298e3319
This update removed "-DBUILD_SHARED_LIBS=OFF" and added
"-DCGAL_BUILD_SHARED_LIBS=$(CMAKE_SHARED_BOOL)"
but it seems that cgal makefiles don't much care about the value of
CGAL_BUILD_SHARED_LIBS and when BUILD_SHARED_LIBS is unspecified, it
defaults to dynamic.
I submitted an issue https://github.com/mxe/mxe/issues/1402
And as a workaround, I modified the ~/openscad_deps/mxe-w64/src/cgal.mk,
changing back to '-DBUILD_SHARED_LIBS=FALSE'
5. The static and dynamic libraries can't both be present, so if you've
accidentally built the dynamic ones libCGAL.dll.a, libCGAL_Core.dll.a,
libCGAL_ImageIO.dll.a, and libCGAL_Qt4.dll.a, these must be removed or else
the final linking of the .exe will fail.  They reside in
~/openscad_deps/mxe-w64/usr/i686-w64-mingw32.static/lib/  Remove the
".dll.a" versions and leave the ".a" versions.
6. Then building openscad works, via ./scripts/release-common.sh mingw32


Now, to fix cgal 4.5 so that it doesn't fail with newer cmake...  this was a
challenge.
First I observed that it generated two log files, one here, which seemed
useless:
~/openscad_deps/mxe/tmp-cgal-i686-w64-mingw32.static/CGAL-4.5/CMakeFiles/CMakeOutput.log
and another one here, which was more informative:
~/openscad_deps/mxe/log/cgal_i686-w64-mingw32.static

The latter gave this as the error:

> -- Sources for CGAL component library 'CGAL_Qt4/CMakeLists.txt' detected
> CMake Error at src/CMakeLists.txt:81 (add_subdirectory):
>   add_subdirectory given source
>  
> "/home/vector/openscad_deps/mxe/tmp-cgal-i686-w64-mingw32.static/CGAL-4.5/src/CGAL_Qt4/CMakeLists.txt"
>   which is not an existing directory.

Apparently it was choking from being given a file (.../CMakeLists.txt) when
it was expecting a directory.  After a LOT of digging I found the place
where the string was generated, coinciding with a commit on the CGAL source
tree with a promising comment:
https://github.com/CGAL/cgal/commit/61e61220eb43ea8c3d4a6ebd84d44b0510d8533d
This seemed like a 'smoking gun' for the string being messed up due to a
cmake version dependence.
To fix it, I modified the CGAL package, at
~/openscad_deps/mxe/CGAL-4.5.tar.xz.  I opened the archive and essentially
applied the patch, replacing "string(REPLACE ...)" with
"get_filename_component(...)" as shown in the commit.  The proper way to do
this would be to insert a patch into the mxe/src, but I don't know the
details of how to do that.
I then recompiled cgal (from mxe directory, "make
build-only-cgal_i686-w64-mingw32.static"), using build-only to prevent
checksum failure and re-download from wiping my changes to CGAL-4.5.tar.xz.

Finally, I was ready to try compiling openscad itself:
./scripts/release-common.sh mingw32
This went without a hitch, and the resulting .exe worked.

-Jamie



--
View this message in context: http://forum.openscad.org/Compiling-for-Windows-tp17766p17801.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list