Difference between revisions of "Compiling from Source"
(117 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | These [http://texgen.sourceforge.net/documents/HowToBuildTexGen.pdf slides] give a walkthrough of how to compile TexGen and its modules. If you are unfamiliar with building software such as this they may be easier to follow than the instructions below. | ||
+ | |||
In order to compile TexGen and '''all''' of its modules, the following software is required: | In order to compile TexGen and '''all''' of its modules, the following software is required: | ||
Line 21: | Line 23: | ||
A graphical representation of the modules and their dependencies can also be found in the [http://texgen.sourceforge.net/api/ TexGen API]. | A graphical representation of the modules and their dependencies can also be found in the [http://texgen.sourceforge.net/api/ TexGen API]. | ||
− | If you want to get the source code from | + | If you want to get the source code from GitHub you will need to install [https://git-scm.com/downloads Git] by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be useful to the rest of the community please send a pull request and they will be incorporated into TexGen following review. |
Alternatively the stable source code can be downloaded as a [http://sourceforge.net/project/showfiles.php?group_id=181000 tarball]. Download the latest file release named ''texgen-3.x.x.tar.gz''. | Alternatively the stable source code can be downloaded as a [http://sourceforge.net/project/showfiles.php?group_id=181000 tarball]. Download the latest file release named ''texgen-3.x.x.tar.gz''. | ||
− | == Windows compile == | + | == Windows (Microsoft Visual Studio C++, recommended method) == |
− | === Microsoft Visual Studio C++ === | + | |
− | + | [http://texgen.sourceforge.net/documents/HowToBuildTexGen.pdf Presentation giving a walkthrough for building TexGen from source] (Python 3 builds only) | |
+ | |||
+ | === Prerequisites === | ||
+ | It is assumed that Microsoft Visual Studio is already installed. If it isn't and you plan to use it, then install it. It may be possible to use the free [http://www.microsoft.com/express/ Visual Studio Express]; if anyone tries this and finds out one way or the other, please post the information either here or in the [http://texgen.sourceforge.net/phpBB2/index.php forum]. Brief instructions on how to install the various 3rd party libraries under windows are given below. Note that you do not need to install all of these in order to perform the minimal build. Only CMake is absolutely required. | ||
+ | |||
+ | TexGen versions 3.11.0 onwards have been built with VS2017. All of the libraries used can be built with this version of Visual Studio. | ||
+ | |||
+ | ==== CMake ==== | ||
+ | |||
+ | [http://www.cmake.org/HTML/Download.html Download CMake] and install, selecting 'Add CMake to the system PATH for all users' (select current user if this is not permissible on your system). | ||
+ | |||
+ | ==== Git ==== | ||
+ | |||
+ | [https://git-scm.com/downloads Download Git] and install it. | ||
+ | |||
+ | ==== SWIG ==== | ||
+ | |||
+ | [http://www.swig.org/ Download] the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-4.0.2). The current version of TexGen is built with version 4.0.2 | ||
+ | |||
+ | ==== Python ==== | ||
+ | |||
+ | [http://www.python.org/ Download Python] and install. Note that TexGen version 3.13 is built with Python 3.9. Versions prior to that were built with Python 2.7. | ||
+ | |||
+ | For a Release build the include files and python39.lib provided with the standard installation can be used. | ||
+ | |||
+ | For a Debug build it is necessary to build a debug version of Python. Download the latest [https://www.python.org/downloads/source/ source release] and follow the instructions in the README for building for your environment. For Visual Studio use the VS solution in the PCBuild folder. Version 3.13 was built with Python 3.9.9. | ||
+ | Note that for newer VS versions it is necessary to apply this [https://github.com/python-cmake-buildsystem/python-cmake-buildsystem/issues/161 patch] in order for the build to be successful. | ||
+ | |||
+ | ==== OpenCascade ==== | ||
+ | |||
+ | [https://dev.opencascade.org/release Download OpenCascade] and install; this extracts the files to a directory. If the installation doesn't start automatically, run the 'install.bat' file located the directory where the files where extracted (read 'readme.htm' file in the same directory for more information). Choose 'complete installation' and tick the box to set the environment variables. The current version of TexGen is built with OpenCascade version 7.0.0. | ||
+ | |||
+ | ==== VTK ==== | ||
+ | |||
+ | [https://github.com/louisepb/VTK-6.3 Download] version 6.3.0 of the source files and extract them. Instructions for building VTK using CMake are given on the [https://vtk.org/Wiki/VTK/Configure_and_Build VTK webpage] The following CMake settings should be set: | ||
+ | |||
+ | BUILD_EXAMPLES OFF | ||
+ | BUILD_SHARED_LIBS OFF | ||
+ | VTK_USE_MPEG2_ENCODER OFF | ||
+ | VTK_USE_PARALLEL OFF | ||
+ | VTK_USE_RENDERING ON | ||
+ | VTK_WRAP_JAVA OFF | ||
+ | VTK_WRAP_PYTHON OFF | ||
+ | VTK_WRAP_TCL OFF | ||
+ | |||
+ | (Version 6.3 is no longer available on the VTK webpage so the link above makes this available until TexGen has been modified to work with more recent VTK versions). | ||
+ | You may be able to get things working with different settings, however these are the settings I use and are known to work. | ||
+ | |||
+ | ==== wxWidgets ==== | ||
+ | |||
+ | [http://www.wxwidgets.org/downloads/ Download] and install the windows version 3.2.5 of wxWidgets (wxMSW). It is then necessary to compile wxWidgets from source. Detailed instructions on how to do this can be found in 'install.txt' located in the 'docs\msw' subfolder. The main steps are to open 'wx_vcN.sln' with MS Visual Studio (where N is the appropriate version) located in the 'build\msw' subfolder and compile both Release and Debug configurations (The configuration can be selected from the drop down box on the main toolbar in Visual Studio. Universal and DLL versions need not be compiled). | ||
+ | |||
+ | ==== CppUnit ==== | ||
+ | To build the test module download [https://www.freedesktop.org/wiki/Software/cppunit/ cppunit] | ||
+ | |||
+ | The VS solution is in the Examples folder. When this is run, accept the option to upgrade to your version of VS and then build. The resulting cppunit.lib file can then be found in the /lib folder. | ||
+ | |||
+ | === Checkout TexGen source code from GitHub === | ||
+ | * Create a directory where you would like to store the TexGen source code in Windows Explorer. | ||
+ | * Open a Git Bash shell within that folder. | ||
+ | * Type | ||
+ | git clone https://github.com/louisepb/TexGen.git | ||
+ | A new TexGen folder will have been created which contains a downloaded copy of the TexGen repository. | ||
+ | |||
+ | === Configuring the build system with CMake === | ||
+ | Run CMake from its shortcut on the Start menu. There are some general instructions on using CMake on the [https://cmake.org/cmake-tutorial/ CMake website] which are worth reading. You will need to fill in the source code location, this should point to where you checked out out the latest TexGen GitHub code or where you extracted the source code from the zip file. Also set where to place the binary files once they are compiled, this can be the same as the source directory, a subdirectory within the source directory or any other location. | ||
+ | |||
+ | Once that is entered click 'Configure' and choose the Visual Studio version which you have installed and click ok. You will initially get a number of error messages such as: | ||
+ | |||
+ | CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK) | ||
+ | CMake Error: Error in configuration process, project files may be invalid. (click OK) | ||
+ | |||
+ | This is normal, in order to get rid of the errors you will need to tell CMake where the various libraries you have installed can be found. This is done in the Cache Values sections. | ||
+ | |||
+ | It is recommended to begin with a minimal build, this is achieved by setting the cache values as follows: | ||
+ | |||
+ | BUILD_CASCADE_EXPORT OFF | ||
+ | BUILD_DOCUMENTATION OFF | ||
+ | BUILD_EXAMPLES OFF | ||
+ | BUILD_GUI OFF | ||
+ | BUILD_PYTHON_INTERFACE OFF | ||
+ | BUILD_RENDERER OFF | ||
+ | BUILD_SHARED ON | ||
+ | BUILD_UNIT_TESTS OFF | ||
+ | |||
+ | Once these are set press configure again and you shouldn't have any more errors/warnings. Press 'OK' to generate the MSVC solution and project files. Configuring the various optional modules is explained in [[#Configuring optional modules]]. | ||
+ | |||
+ | === Configuring optional modules === | ||
+ | |||
+ | Once the minimal build is working you may want to switch on the optional modules. To do this open up CMake again and switch the modules you want to ON in the Cache Values then click Configure. You will most likely see some errors telling you it is unable to automatically find certain directories. You will need to specify these manually. An explanation of the different locations is listed below: | ||
+ | |||
+ | '''PYTHON_SITEPACKAGES_DIR''' - This should be the folder where the TexGen python modules will be placed. Usually located in 'C:\Python27\Lib\site-packages', but this will depend on the version of Python installed and where you decided to install it. | ||
+ | |||
+ | '''SWIG_DIR''' - This is the location where you extracted the SWIG executable. e.g. 'C:\Program Files\swigwin-2.0.10'. | ||
+ | |||
+ | '''SWIG_EXECUTABLE''' - Same as root directory followed by 'swig.exe' | ||
+ | |||
+ | '''wxWidgets_ROOT_DIR''' - Location where you install wxWidgets. e.g. 'C:/wxWidgets-3.2.5'. | ||
+ | |||
+ | '''wxWidgets_LIB_DIR''' - Location where the wxWidgets libraries were compiled to, should be the same as the root directory followed by 'lib/vc_lib' or 'lib/vc_x64_lib' for 64-bit builds. | ||
+ | |||
+ | '''WX''' - CMake may not automatically pick up the location of all libraries in which case these may need to be input manually. The image below shows the CMake GUI part way through specifying the library locations | ||
+ | [[Image:wxWidgetsCMake.png]] | ||
+ | |||
+ | '''OPENCASCADE_INCLUDE_DIR''' - Location where the OpenCascade header files are located. e.g. 'C:/OpenCASCADE7.0.0/inc'. | ||
+ | |||
+ | '''OPENCASCADE_LIBRARY_DIR''' - Location where the OpenCascade libraries are located. e.g. 'C:/OpenCASCADE7.0.0/win64/vc14/lib'. | ||
+ | |||
+ | '''OPENCASCADE_DEBUG_LIBRARY_DIR''' - Location where the OpenCascade debug libraries are located. e.g. 'C:/OpenCASCADE7.0.0/win64/vc14/libd'. | ||
+ | |||
+ | '''VTK_DIR''' - Location of the VTK binary directory (note: not the source directory). | ||
+ | |||
+ | '''CPPUNIT_LIBRARY''' - Location where the cppunit library file is located. e.g. 'C:/cppunit-1.15.1/lib/cppunit.lib' | ||
+ | |||
+ | After setting the directories manually, click on configure again. You may need to go through several iterations of changing parameters then pressing configure. Once you have finished changing parameters and have successfully pressed configure without error messages you can press the OK button to generate the build. Note: you can always come back to this at a later time to make changes. | ||
+ | |||
+ | === Compiling === | ||
+ | |||
+ | Find 'TexGen.sln' which should be located in the directory where you told CMake to output the binary files to and open it with Microsoft Visual Studio. | ||
+ | |||
+ | Set the configuration to 'Release'. | ||
+ | |||
+ | If building the Graphical User Interface with Visual Studio 2008 or later open the properties page for the TexGenGUI project. Select Configuration Properties -> Manifest Tool -> Input and Output and change the Embed Manifest option to 'No'. | ||
+ | |||
+ | Build the solution. Hopefully the project will have been compiled without errors. | ||
+ | |||
+ | If you want to compile and execute the Graphical User Interface you will need to install it, you will not be able to execute it directly from the build directory. This is done by right click on the 'INSTALL' project in the Solution Explorer and selecting Build. This will copy the Python modules into the Python site-packages directory so that they can be imported into scripts, and it will copy the executable along with other necessary files into 'C:\Program Files\TexGen\' by default (this can be changed with the CMAKE_INSTALL_PREFIX cache value in CMake). TexGenGUI.exe should then be run from the installed location, if you attempt to run it directly from where it was compiled you will get some errors on launch. | ||
+ | |||
+ | === Building the documentation === | ||
+ | |||
+ | To build the documentation, [http://www.doxygen.nl/download.html Doxygen] and [https://graphviz.gitlab.io/download/ Graphviz] are required. Open a command prompt in the 'Docs' subdirectory of the source code and run 'doxygen'. If the doxygen directory is not in your path, you must add it, or give the full path on the command line. | ||
+ | |||
+ | === Integrating TexGen with ABAQUS === | ||
+ | |||
+ | If you are using ABAQUS and wish to use TexGen Python scripting from within the ABAQUS/CAE environment, there are a few extra steps to perform. This is because ABAQUS comes packaged with its own version of Python, so any modules added to your standalone python installation will not be accessible by ABAQUS. You must compile the TexGen Python modules with the same version of Python as ABAQUS uses. The following table shows which version of Python is used in specific ABAQUS versions: | ||
+ | |||
+ | {| class="wikitable" style="text-align:center" border="1" | ||
+ | ! ABAQUS Version !! Python Version | ||
+ | |- | ||
+ | | 6.6-1 || 2.3.3 | ||
+ | |- | ||
+ | | 6.7-1 || 2.4.3 | ||
+ | |- | ||
+ | | 6.10-2 || 2.6.2 | ||
+ | | | ||
+ | |- | ||
+ | | 6.14-1 || 2.7.3 | ||
+ | |} | ||
+ | |||
+ | If your version of ABAQUS is not listed in the table above you can type 'abaqus python -V' to check what version of Python is used (then please edit this page to update the table). You can obtain specific versions of Python from https://www.python.org/downloads/source/ . | ||
+ | |||
+ | Additionally you will need to place the TexGen python modules inside ABAQUS' version of python. There are a few ways to accomplish this, the easiest is perhaps to set the CMake cache variable 'PYTHON_SITEPACKAGES_DIR' point to the ABAQUS' python directory, e.g.: | ||
+ | |||
+ | PYTHON_SITEPACKAGES_DIR C:\Abaqus\6.14-1\Python\Lib\ | ||
+ | |||
+ | Then when you build the INSTALL project in MSVC++ it will automatically copy the TexGen python modules to the ABAQUS' Python. Alternatively you can simply copy the files manually or modify Python's search path to include the TexGen python modules, e.g. In python: | ||
+ | |||
+ | import sys | ||
+ | sys.path.append('C:/Python27/Lib/site-packages/') | ||
+ | |||
+ | There may also be a need to modify the file [source code location]/Installer/texgen.nsi. The original version, lines 1-3 are: | ||
+ | |||
+ | !define VERSION "3.3.0" | ||
+ | !define PYTHONDLL python25.dll | ||
+ | !define PYTHONVER "2.5" | ||
+ | |||
+ | while on Jon's version they are: | ||
+ | |||
+ | !define VERSION "3.3.0" | ||
+ | !define PYTHONDLL python24.dll | ||
+ | !define PYTHONVER "2.4" | ||
+ | |||
+ | === Troubleshooting === | ||
+ | |||
+ | '''Q:''' I get the following error when compiling: | ||
+ | fatal error LNK1104: cannot open file 'python25_d.lib' | ||
+ | |||
+ | '''A:''' The windows installation of Python doesn't come with the debug library ('python25_d.lib', the _d part means debug). You should be able to compile in release mode however. If you really want to compile in debug mode you will need to compile Python from source and link to that. Or you can try to link to the release library 'python25.lib' instead, easiest way to do that is to copy 'python25.lib' to 'python25_d.lib' but this may cause problems during linking or execution. | ||
+ | |||
+ | '''Q:''' I get the following error when compiling: | ||
+ | fatal error C1083: Cannot open include file: 'wx/wxprec.h': No such file or directory | ||
+ | |||
+ | '''A:''' Make sure that you have compiled wxWidgets and that the wxWidgets_XXX cache variables are set correctly in CMake. | ||
+ | |||
+ | '''Q:''' I do not have a 'libd' folder in 'ros/win32' for OpenCASCADE. | ||
+ | |||
+ | '''A:''' If you do not compile OpenCASCADE yourself then this folder does not exist. However it can be ignored if you are only interested in building the release version of TexGen. If you really want to compile the debug version please refer to the OpenCASCADE documentation. | ||
+ | |||
+ | '''Q:''' Why do I get the error message: "The parameter is incorrect." when launching TexGenGUI.exe? | ||
+ | |||
+ | '''A:''' In the TexGenGUI Property Pages select Configuration Properties -> Manifest Tool -> Input and Output and change the Embed Manifest option to 'No'. | ||
+ | |||
+ | '''Q:''' I am getting error messages at the stage of building GUI:[ 86%] Building CXX object GUI/CMakeFiles/TexGenGUI.dir/PrecompiledHeaders.cpp.o | ||
+ | In file included from /usr/include/python2.4/pyconfig.h:6, | ||
+ | from /usr/include/python2.4/Python.h:8, | ||
+ | from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.h:30, | ||
+ | from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.cpp:20: | ||
+ | /usr/include/python2.4/pyconfig-64.h:823:1: warning: "_FILE_OFFSET_BITS" redefined | ||
+ | <command line>:1:1: warning: this is the location of the previous definition | ||
+ | In file included from /data/include/wx-2.8/wx/wx.h:15, | ||
+ | from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.h:54, | ||
+ | from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.cpp:20: | ||
+ | /data/include/wx-2.8/wx/defs.h:42:13: error: #error "No Target! You should use wx-config program for compilation flags!" | ||
+ | In file included from /data/include/wx-2.8/wx/cmndata.h:17, | ||
+ | from /data/include/wx-2.8/wx/wx.h:65, | ||
+ | from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.h:54, | ||
+ | from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.cpp:20: | ||
+ | /data/include/wx-2.8/wx/encinfo.h:64:6: error: #error "Unsupported toolkit" | ||
+ | |||
+ | and lots of othe warnings and error messages afterwards. | ||
+ | |||
+ | The location of wx-config is correct in cmake; wxWidgets installation appears to have been successful; the system is Red Hat Linux 64-bit | ||
+ | |||
+ | == Windows (Cygwin and gcc, alternate method) == | ||
+ | A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at [http://www.cygwin.com www.cygwin.com]. | ||
+ | This can exist peacefully next to the native windows version. | ||
+ | Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/<username>/. | ||
+ | |||
+ | === Download cygwin and install packages === | ||
+ | Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. | ||
+ | For the mesh generator and python interface to work we currently need VTK and swig. | ||
− | == Unix | + | This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh). |
+ | mkdir progs | ||
+ | cd progs | ||
+ | SWIG=swig-1.3.31 | ||
+ | wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz | ||
+ | tar xzvf $SWIG.tar.gz | ||
+ | cd $SWIG | ||
+ | ./configure | ||
+ | make | ||
+ | make install | ||
+ | |||
+ | This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install. | ||
+ | VTK=vtk-6.3.0 | ||
+ | wget -nc https://vtk.org/download/ | ||
+ | tar xzvf $VTK.tar.gz | ||
+ | mkdir vtkbin | ||
+ | cd vtkbin | ||
+ | ccmake ../VTK | ||
+ | make | ||
+ | make install | ||
+ | |||
+ | === Install TexGen from source === | ||
+ | Now we can proceed to install texgen, as an example we'll work in ~/temp/texgen | ||
+ | cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen | ||
+ | svn checkout svn//svn.code.sf.net/p/texgen/code/TexGen/trunk/ TexGen | ||
+ | cd .. ; mkdir tbin; cd tbin | ||
+ | ccmake ../texgen | ||
+ | make | ||
+ | make install | ||
+ | |||
+ | This should result in a working texgen install in ~/temp/texgen/tbin. | ||
+ | |||
+ | == Unix == | ||
=== Notes === | === Notes === | ||
If you are installing to a system where you don't have root access (i.e. this computer does not belong to you) you won't be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc... | If you are installing to a system where you don't have root access (i.e. this computer does not belong to you) you won't be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc... | ||
Line 35: | Line 289: | ||
In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software. | In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software. | ||
− | === Get TexGen from | + | === Get TexGen from GitHub repository === |
− | ==== Install | + | ==== Install Git ==== |
− | [ | + | [https://git-scm.com/downloads Download Git] and unpack. |
− | |||
− | |||
− | |||
− | |||
− | + | ==== Clone TexGen ==== | |
− | |||
− | |||
− | |||
− | ==== | ||
Open a shell in folder you wish to place TexGen (e.g. ~/): | Open a shell in folder you wish to place TexGen (e.g. ~/): | ||
− | + | git clone https://github.com/louisepb/TexGen.git | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Compile source === | === Compile source === | ||
Line 111: | Line 346: | ||
Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this: | Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this: | ||
− | PYTHON_INCLUDE_PATH: ~/include/python2. | + | PYTHON_INCLUDE_PATH: ~/include/python2.7 |
− | PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2. | + | PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.7.a |
− | PYTHON_SITEPACKAGES_DIR: ~/lib/python2. | + | PYTHON_SITEPACKAGES_DIR: ~/lib/python2.7/site-packages |
− | SWIG_DIR: ~/bin | + | SWIG_DIR: ~/bin |
− | SWIG_EXECUTABLE: ~/bin/swig | + | SWIG_EXECUTABLE: ~/bin/swig |
Once that is done press 'c' again. You may need perform this process over several iterations. When everything is set correctly press 'g' to generate the makefiles. | Once that is done press 'c' again. You may need perform this process over several iterations. When everything is set correctly press 'g' to generate the makefiles. | ||
Line 124: | Line 359: | ||
Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing: | Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing: | ||
− | + | python | |
Then from within Python type: | Then from within Python type: |
Latest revision as of 14:40, 5 July 2024
These slides give a walkthrough of how to compile TexGen and its modules. If you are unfamiliar with building software such as this they may be easier to follow than the instructions below.
In order to compile TexGen and all of its modules, the following software is required:
The following programs are needed to build TexGen:
The following libraries are needed to link to TexGen:
However to perform a minimum build of TexGen with none of the additional modules you only require CMake and a C++ compiler. It is recommended to begin with a minimum build, once that is working try adding modules one at a time. A list of modules along with dependencies is shown below:
- Python interface: Python, SWIG
- Renderer: VTK
- Export: OpenCascade
- GUI: wxWidgets, Renderer, Python interface
- Unit tests: CPPUnit
A graphical representation of the modules and their dependencies can also be found in the TexGen API.
If you want to get the source code from GitHub you will need to install Git by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be useful to the rest of the community please send a pull request and they will be incorporated into TexGen following review.
Alternatively the stable source code can be downloaded as a tarball. Download the latest file release named texgen-3.x.x.tar.gz.
Windows (Microsoft Visual Studio C++, recommended method)
Presentation giving a walkthrough for building TexGen from source (Python 3 builds only)
Prerequisites
It is assumed that Microsoft Visual Studio is already installed. If it isn't and you plan to use it, then install it. It may be possible to use the free Visual Studio Express; if anyone tries this and finds out one way or the other, please post the information either here or in the forum. Brief instructions on how to install the various 3rd party libraries under windows are given below. Note that you do not need to install all of these in order to perform the minimal build. Only CMake is absolutely required.
TexGen versions 3.11.0 onwards have been built with VS2017. All of the libraries used can be built with this version of Visual Studio.
CMake
Download CMake and install, selecting 'Add CMake to the system PATH for all users' (select current user if this is not permissible on your system).
Git
Download Git and install it.
SWIG
Download the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-4.0.2). The current version of TexGen is built with version 4.0.2
Python
Download Python and install. Note that TexGen version 3.13 is built with Python 3.9. Versions prior to that were built with Python 2.7.
For a Release build the include files and python39.lib provided with the standard installation can be used.
For a Debug build it is necessary to build a debug version of Python. Download the latest source release and follow the instructions in the README for building for your environment. For Visual Studio use the VS solution in the PCBuild folder. Version 3.13 was built with Python 3.9.9. Note that for newer VS versions it is necessary to apply this patch in order for the build to be successful.
OpenCascade
Download OpenCascade and install; this extracts the files to a directory. If the installation doesn't start automatically, run the 'install.bat' file located the directory where the files where extracted (read 'readme.htm' file in the same directory for more information). Choose 'complete installation' and tick the box to set the environment variables. The current version of TexGen is built with OpenCascade version 7.0.0.
VTK
Download version 6.3.0 of the source files and extract them. Instructions for building VTK using CMake are given on the VTK webpage The following CMake settings should be set:
BUILD_EXAMPLES OFF BUILD_SHARED_LIBS OFF VTK_USE_MPEG2_ENCODER OFF VTK_USE_PARALLEL OFF VTK_USE_RENDERING ON VTK_WRAP_JAVA OFF VTK_WRAP_PYTHON OFF VTK_WRAP_TCL OFF
(Version 6.3 is no longer available on the VTK webpage so the link above makes this available until TexGen has been modified to work with more recent VTK versions). You may be able to get things working with different settings, however these are the settings I use and are known to work.
wxWidgets
Download and install the windows version 3.2.5 of wxWidgets (wxMSW). It is then necessary to compile wxWidgets from source. Detailed instructions on how to do this can be found in 'install.txt' located in the 'docs\msw' subfolder. The main steps are to open 'wx_vcN.sln' with MS Visual Studio (where N is the appropriate version) located in the 'build\msw' subfolder and compile both Release and Debug configurations (The configuration can be selected from the drop down box on the main toolbar in Visual Studio. Universal and DLL versions need not be compiled).
CppUnit
To build the test module download cppunit
The VS solution is in the Examples folder. When this is run, accept the option to upgrade to your version of VS and then build. The resulting cppunit.lib file can then be found in the /lib folder.
Checkout TexGen source code from GitHub
- Create a directory where you would like to store the TexGen source code in Windows Explorer.
- Open a Git Bash shell within that folder.
- Type
git clone https://github.com/louisepb/TexGen.git
A new TexGen folder will have been created which contains a downloaded copy of the TexGen repository.
Configuring the build system with CMake
Run CMake from its shortcut on the Start menu. There are some general instructions on using CMake on the CMake website which are worth reading. You will need to fill in the source code location, this should point to where you checked out out the latest TexGen GitHub code or where you extracted the source code from the zip file. Also set where to place the binary files once they are compiled, this can be the same as the source directory, a subdirectory within the source directory or any other location.
Once that is entered click 'Configure' and choose the Visual Studio version which you have installed and click ok. You will initially get a number of error messages such as:
CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK) CMake Error: Error in configuration process, project files may be invalid. (click OK)
This is normal, in order to get rid of the errors you will need to tell CMake where the various libraries you have installed can be found. This is done in the Cache Values sections.
It is recommended to begin with a minimal build, this is achieved by setting the cache values as follows:
BUILD_CASCADE_EXPORT OFF BUILD_DOCUMENTATION OFF BUILD_EXAMPLES OFF BUILD_GUI OFF BUILD_PYTHON_INTERFACE OFF BUILD_RENDERER OFF BUILD_SHARED ON BUILD_UNIT_TESTS OFF
Once these are set press configure again and you shouldn't have any more errors/warnings. Press 'OK' to generate the MSVC solution and project files. Configuring the various optional modules is explained in #Configuring optional modules.
Configuring optional modules
Once the minimal build is working you may want to switch on the optional modules. To do this open up CMake again and switch the modules you want to ON in the Cache Values then click Configure. You will most likely see some errors telling you it is unable to automatically find certain directories. You will need to specify these manually. An explanation of the different locations is listed below:
PYTHON_SITEPACKAGES_DIR - This should be the folder where the TexGen python modules will be placed. Usually located in 'C:\Python27\Lib\site-packages', but this will depend on the version of Python installed and where you decided to install it.
SWIG_DIR - This is the location where you extracted the SWIG executable. e.g. 'C:\Program Files\swigwin-2.0.10'.
SWIG_EXECUTABLE - Same as root directory followed by 'swig.exe'
wxWidgets_ROOT_DIR - Location where you install wxWidgets. e.g. 'C:/wxWidgets-3.2.5'.
wxWidgets_LIB_DIR - Location where the wxWidgets libraries were compiled to, should be the same as the root directory followed by 'lib/vc_lib' or 'lib/vc_x64_lib' for 64-bit builds.
WX - CMake may not automatically pick up the location of all libraries in which case these may need to be input manually. The image below shows the CMake GUI part way through specifying the library locations
OPENCASCADE_INCLUDE_DIR - Location where the OpenCascade header files are located. e.g. 'C:/OpenCASCADE7.0.0/inc'.
OPENCASCADE_LIBRARY_DIR - Location where the OpenCascade libraries are located. e.g. 'C:/OpenCASCADE7.0.0/win64/vc14/lib'.
OPENCASCADE_DEBUG_LIBRARY_DIR - Location where the OpenCascade debug libraries are located. e.g. 'C:/OpenCASCADE7.0.0/win64/vc14/libd'.
VTK_DIR - Location of the VTK binary directory (note: not the source directory).
CPPUNIT_LIBRARY - Location where the cppunit library file is located. e.g. 'C:/cppunit-1.15.1/lib/cppunit.lib'
After setting the directories manually, click on configure again. You may need to go through several iterations of changing parameters then pressing configure. Once you have finished changing parameters and have successfully pressed configure without error messages you can press the OK button to generate the build. Note: you can always come back to this at a later time to make changes.
Compiling
Find 'TexGen.sln' which should be located in the directory where you told CMake to output the binary files to and open it with Microsoft Visual Studio.
Set the configuration to 'Release'.
If building the Graphical User Interface with Visual Studio 2008 or later open the properties page for the TexGenGUI project. Select Configuration Properties -> Manifest Tool -> Input and Output and change the Embed Manifest option to 'No'.
Build the solution. Hopefully the project will have been compiled without errors.
If you want to compile and execute the Graphical User Interface you will need to install it, you will not be able to execute it directly from the build directory. This is done by right click on the 'INSTALL' project in the Solution Explorer and selecting Build. This will copy the Python modules into the Python site-packages directory so that they can be imported into scripts, and it will copy the executable along with other necessary files into 'C:\Program Files\TexGen\' by default (this can be changed with the CMAKE_INSTALL_PREFIX cache value in CMake). TexGenGUI.exe should then be run from the installed location, if you attempt to run it directly from where it was compiled you will get some errors on launch.
Building the documentation
To build the documentation, Doxygen and Graphviz are required. Open a command prompt in the 'Docs' subdirectory of the source code and run 'doxygen'. If the doxygen directory is not in your path, you must add it, or give the full path on the command line.
Integrating TexGen with ABAQUS
If you are using ABAQUS and wish to use TexGen Python scripting from within the ABAQUS/CAE environment, there are a few extra steps to perform. This is because ABAQUS comes packaged with its own version of Python, so any modules added to your standalone python installation will not be accessible by ABAQUS. You must compile the TexGen Python modules with the same version of Python as ABAQUS uses. The following table shows which version of Python is used in specific ABAQUS versions:
ABAQUS Version | Python Version | |
---|---|---|
6.6-1 | 2.3.3 | |
6.7-1 | 2.4.3 | |
6.10-2 | 2.6.2 | |
6.14-1 | 2.7.3 |
If your version of ABAQUS is not listed in the table above you can type 'abaqus python -V' to check what version of Python is used (then please edit this page to update the table). You can obtain specific versions of Python from https://www.python.org/downloads/source/ .
Additionally you will need to place the TexGen python modules inside ABAQUS' version of python. There are a few ways to accomplish this, the easiest is perhaps to set the CMake cache variable 'PYTHON_SITEPACKAGES_DIR' point to the ABAQUS' python directory, e.g.:
PYTHON_SITEPACKAGES_DIR C:\Abaqus\6.14-1\Python\Lib\
Then when you build the INSTALL project in MSVC++ it will automatically copy the TexGen python modules to the ABAQUS' Python. Alternatively you can simply copy the files manually or modify Python's search path to include the TexGen python modules, e.g. In python:
import sys sys.path.append('C:/Python27/Lib/site-packages/')
There may also be a need to modify the file [source code location]/Installer/texgen.nsi. The original version, lines 1-3 are:
!define VERSION "3.3.0" !define PYTHONDLL python25.dll !define PYTHONVER "2.5"
while on Jon's version they are:
!define VERSION "3.3.0" !define PYTHONDLL python24.dll !define PYTHONVER "2.4"
Troubleshooting
Q: I get the following error when compiling:
fatal error LNK1104: cannot open file 'python25_d.lib'
A: The windows installation of Python doesn't come with the debug library ('python25_d.lib', the _d part means debug). You should be able to compile in release mode however. If you really want to compile in debug mode you will need to compile Python from source and link to that. Or you can try to link to the release library 'python25.lib' instead, easiest way to do that is to copy 'python25.lib' to 'python25_d.lib' but this may cause problems during linking or execution.
Q: I get the following error when compiling:
fatal error C1083: Cannot open include file: 'wx/wxprec.h': No such file or directory
A: Make sure that you have compiled wxWidgets and that the wxWidgets_XXX cache variables are set correctly in CMake.
Q: I do not have a 'libd' folder in 'ros/win32' for OpenCASCADE.
A: If you do not compile OpenCASCADE yourself then this folder does not exist. However it can be ignored if you are only interested in building the release version of TexGen. If you really want to compile the debug version please refer to the OpenCASCADE documentation.
Q: Why do I get the error message: "The parameter is incorrect." when launching TexGenGUI.exe?
A: In the TexGenGUI Property Pages select Configuration Properties -> Manifest Tool -> Input and Output and change the Embed Manifest option to 'No'.
Q: I am getting error messages at the stage of building GUI:[ 86%] Building CXX object GUI/CMakeFiles/TexGenGUI.dir/PrecompiledHeaders.cpp.o In file included from /usr/include/python2.4/pyconfig.h:6,
from /usr/include/python2.4/Python.h:8, from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.h:30, from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.cpp:20:
/usr/include/python2.4/pyconfig-64.h:823:1: warning: "_FILE_OFFSET_BITS" redefined <command line>:1:1: warning: this is the location of the previous definition In file included from /data/include/wx-2.8/wx/wx.h:15,
from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.h:54, from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.cpp:20:
/data/include/wx-2.8/wx/defs.h:42:13: error: #error "No Target! You should use wx-config program for compilation flags!" In file included from /data/include/wx-2.8/wx/cmndata.h:17,
from /data/include/wx-2.8/wx/wx.h:65, from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.h:54, from /data/Archive/TexGen/texgen-3.3.0/GUI/PrecompiledHeaders.cpp:20:
/data/include/wx-2.8/wx/encinfo.h:64:6: error: #error "Unsupported toolkit"
and lots of othe warnings and error messages afterwards.
The location of wx-config is correct in cmake; wxWidgets installation appears to have been successful; the system is Red Hat Linux 64-bit
Windows (Cygwin and gcc, alternate method)
A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at www.cygwin.com. This can exist peacefully next to the native windows version. Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/<username>/.
Download cygwin and install packages
Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. For the mesh generator and python interface to work we currently need VTK and swig.
This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh).
mkdir progs cd progs SWIG=swig-1.3.31 wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz tar xzvf $SWIG.tar.gz cd $SWIG ./configure make make install
This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install.
VTK=vtk-6.3.0 wget -nc https://vtk.org/download/ tar xzvf $VTK.tar.gz mkdir vtkbin cd vtkbin ccmake ../VTK make make install
Install TexGen from source
Now we can proceed to install texgen, as an example we'll work in ~/temp/texgen
cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen svn checkout svn//svn.code.sf.net/p/texgen/code/TexGen/trunk/ TexGen cd .. ; mkdir tbin; cd tbin ccmake ../texgen make make install
This should result in a working texgen install in ~/temp/texgen/tbin.
Unix
Notes
If you are installing to a system where you don't have root access (i.e. this computer does not belong to you) you won't be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc...
In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software.
Get TexGen from GitHub repository
Install Git
Download Git and unpack.
Clone TexGen
Open a shell in folder you wish to place TexGen (e.g. ~/):
git clone https://github.com/louisepb/TexGen.git
Compile source
Install CMake
Download CMake and unpack. Open a shell in extracted folder and type:
./configure --prefix=$HOME make make install
Compile TexGen core
Open a shell in the folder with the TexGen source code (e.g. ~/TexGen):
mkdir bin cd bin ccmake ../
Press 'c' to configure. When a warning pops up telling you it can't find such and such a file press 'e' to close it. You will now need to specify which components of TexGen to build and where their dependencies can be found. Use the up and down arrows to move the caret and press enter to modify options. Do this to set BUILD_GUI, BUILD_PYTHON_INTERFACE and BUILD_RENDERER to OFF. You are basically telling CMake not to attempt to build these components, which means that you won't need to have installed their dependencies.
Similarly to the --prefix=$HOME parameter to the configure script, you can tell CMake to install TexGen to your home directory by changing CMAKE_INSTALL_PREFIX to ~/. Note that it won't actually install anything until you get type make install.
Now press 'c' again to update the changes.
Hopefully now that all the additional modules have been switched off no errors will be shown. Press 'g' to generate the makefiles and exit. At the shell type:
make make install
Note that at this point you have only built and installed the TexGen Core library which doesn't actually do anything on its own. If you plan to incorporate TexGen into your own C++ program then this is enough, however if you would like to interface with TexGen from a Python script or Graphical User Interface then follow the steps below.
Compiling optional modules
Python interface
Download Python and unpack. Open a shell in the extracted folder and type:
./configure --prefix=$HOME make make install
Download SWIG and unpack. Open a shell in the extracted folder and type:
./configure --prefix=$HOME make make install
Open a shell in the folder where you called ccmake from for the first time (e.g. ~/TexGen/bin):
ccmake ../
Use the up and down arrows to reach BUILD_PYTHON_INTERFACE and press Enter to set it to ON. Then press 'c' to configure. You will probably get a warning saying you need to specify the location of SWIG and/or Python, press 'e' to close it.
Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this:
PYTHON_INCLUDE_PATH: ~/include/python2.7 PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.7.a PYTHON_SITEPACKAGES_DIR: ~/lib/python2.7/site-packages SWIG_DIR: ~/bin SWIG_EXECUTABLE: ~/bin/swig
Once that is done press 'c' again. You may need perform this process over several iterations. When everything is set correctly press 'g' to generate the makefiles.
At the shell type:
make make install
Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing:
python
Then from within Python type:
from TexGen.Core import * CTexGen.GetInstance().GetVersion()
This should display the version of TexGen installed.
Troubleshooting
Q: I get the following error when linking _Core.so:
libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
A: Try removing libpython2.5.a from the libraries to link to by setting PYTHON_LIBRARY to a bogus path, e.g.:
PYTHON_LIBRARY: ~/
By doing so you may receive a warning similar to this:
Warning: Ignoring path found in link libraries for target: _Core, path is: /home/username. Expected a library name or a full path to a library name.
This warning may be ignored.