谈一谈我在win10上编译3Dslicer的经验。同样,对Slicer官网的原版英文教程不做更改,不做翻译。仅谈理解和实践经验。
目录
CONFIGURE and generate Slicer solution files
Workaround for if the firewall is blocking git protocol
编译环境:
系统:win10
Slicer版本:Slicer4.10.1 release
编译器:VS2015
从我自身编译过程来看,从源代码来编译Slicer release版本还是比较简单的,只要遵循官方教程应该可以很轻松的编译通过。但编译过程中也会有一些坑,希望避免。
PREREQUISITES
As of early 2018, Slicer migrated to Qt5. Qt4 support was removed in version 4.11.(从Slicer的4.11版开始删除了对Qt4的支持)See instructions at this labs page for the new requirements: https://www.slicer.org/wiki/Documentation/Labs/Qt5-and-VTK8
The prerequisites listed below are required to be able to configure/build/package/test Slicer.
Windows
Common Prerequisites:
- CMake >= 3.13.4(这边会有一个坑,下面说)
- Git >= 1.7.10
CMake must be able to find git.exe and patch.exe. If git is installed in the default location then they may be found there, but if they are not found then either add the folder that contains them to PATH environment variable; or set GIT_EXECUTABLE and Patch_EXECUTABLE as environment variables or as CMake variables at configure time.(默认在安装了Git之后只有git.exe的路径添加到了PATH环境变量中,所以一般要手动把patch.exe的路径也添加进去,后面Cmake要用到)
- Subversion (SVN) client: any SVN client that has command line tools
- SlikSvn , or
- TortoiseSVN - make sure you install Command line client tools component (disabled by default)
- NSIS (optional):Needed if packaging Slicer - Click here to download. Make sure you install the language packs.(最后在编译了Slicer的package工程后会生成一个.exe的安装文件)
- Qt5: Download qt-unified-windows-x86-online.exe and install Qt along with qtscript and qtwebengine components. For building with VS2015, Qt version 5.10.x or older is required. For more details, read step-by-step guide.(这边安装教程一步一步来就可以,因为是在线安装,可能因为网速慢下载失败)
Tested and recommended build environment:
- VS2015
- Make sure you enable installation of component Programming languages / Visual C++ / Common Tools for Visual C++ 2015 (in some distributions, this option is not enabled by default)(推荐下载官网上的安装包)
- Installation of Cumulative Servicing Release for Microsoft Visual Studio 2015 Update 3 (KB3165756) is required on some older VS2015 distributions
- Qt 5.10
- CMake >= 3.13.4(此时Cmake的最新版本是3.14.0,所以刚开始我下了最新版,然而在用Cmake生成解决方案时,生成器的选择对生成器的类型和位数作了分开,一个选了Visual Studio 14 2015,另一个选了X64,可是在build的过程中会出错,提示机器位数和工程位数有冲突,error LNK1112: module machine type 'x64' conflicts with target machine type 'X86' 。所以后来换了Cmake的低版本3.13.4,这个版本生成器的类型和位数是在一起的Visual Studio 14 2015 Win64,这次就可以成功完成build)
Experimental/deprecated build environments:
- Visual Studio 2017 (Community or any other edition) with VS2015 build tools (tested, works well)
- When configuring Visual Studio installer, enable installation of component VC++ 2015.3 v14.00 (v140) toolset for desktop
- Visual Studio 2015 toolset must be set in CMake: Optional toolset to use (argument to -T) need to be set to v140
- Cygwin (untested, probably does not work)
- Cygwin suite (building with cygwin gcc not supported, but the cygwin shell environment can be used to run git, svn, etc).
CHECKOUT slicer source files
Check out the code using git
and configure the git svn
bridge:
- While it is not enforced, we strongly recommend you to AVOID the use of SPACES for both the
source directory
and thebuild directory
. We mean it.(尽量不要在路径中有空格) - Due to maximum path length limitations during build the build process, source and build folders must be located in a folder with very short total path length. This is expecially critical on Windows and MacOS. For example, C:DS4 for source and C:DS4R for release-mode build folder works on Windows; and /sq5 has been confirmed to work on MacOS.(尽量减少路径长度)
1. Clone the github repository
cd MyProjects
git clone git://github.com/Slicer/Slicer.git
The Slicer
directory is automatically created after cloning Slicer.
2. Setup the development environment:
cd Slicer
./Utilities/SetupForDevelopment.sh
For more details see Development With Git.
On Windows enter the commands above in to a bash shell, such as Git Bash (part of msysgit) or use a Git client with a graphical user interface.
3. Configure the git svn
bridge to ensure the mapping with svn revision.
git-svn is only required for core developers with svn access - other people can skip it.
cd Slicer
git svn init http://svn.slicer.org/Slicer4/trunk
git update-ref refs/remotes/git-svn refs/remotes/origin/master
git checkout master
git svn rebase
If you plan to compile Slicer to develop your own extensions and test these extensions on Slicer releases, it is convenient to download the source code directly from SVN and specify the revision number corresponding to the release you want. To do so, replace <MARKER> and <SVNREVISION> in the command below with the selected revision and marker:
svn co http://svn.slicer.org/Slicer4/<MARKER> Slicer-r<SVNREVISION> -r <SVNREVISION>
Release SVN revision# Marker
4.10.0 27501 trunk
4.8.1 26813 branches/Slicer-4-8
4.8.0 26489 trunk
4.6.2 25516 branches/Slicer-4-6
4.5.0-1 24735 trunk
4.4 23774 trunk
4.3.1 22599 branches/Slicer-4-3
4.3.0 22408 trunk
More corresponding SVN revision numbers can be found here and here. The <MARKER> can be found at the bottom of this page http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=SVNREVISION by replacing SVNREVISION with the selected revision.
For example, to checkout the source code associated with revision 4.8.1, you would use the following command:
svn co http://svn.slicer.org/Slicer4/branches/Slicer-4-8 Slicer-r26813 -r 26813
(因为我之前是在win7下编译过slicer4.7.0 的debug版本,在其上开发的extensions想要移植到发行版上,所以刚开始我确实是想要要编译一个release版本的Slicer来开发和测试自己的extensions。但是在采用上述的svn co的命令行方式获取源码的过程中会有错误出现,试了几次都没有成功。因此,我会直接在上述地址中https://www.slicer.org/wiki/Release_Details的GitHub上clone或者下载zip格式的源码,然后进行编译)
CONFIGURE and generate Slicer solution files
There are many ways of customizing Slicer's user interface or feature set. This section describes how a custom Slicer build can be configured at build-time. See an overview of various other options in this presentation.
You can configure and generate Slicer solution files using either ccmake
or cmake-gui
. To streamline this process, you can also use the SlicerCustomAppTemplate project maintained by Kitware.
Customizing application build
Customized editions of Slicer can be generated without changing Slicer source code, just by modifying CMake variables:
- SlicerApp_APPLICATION_NAME: Custom application name to be used, instead of default "Slicer". The name is used in installation package name, window title bar, etc.
- Slicer_DISCLAIMER_AT_STARTUP: String that is displayed to the user after first startup of Slicer after installation (disclaimer, welcome message, etc).
- Slicer_DEFAULT_HOME_MODULE: Module name that is activated automatically on application start.
- Slicer_DEFAULT_FAVORITE_MODULES: Modules that will be added to the toolbar by default for easy access. List contains module names, separated by space character.
- Slicer_CLIMODULES_DISABLED: Built-in CLI modules that will be removed from the application. List contains module names, separated by semicolon character.
- Slicer_QTLOADABLEMODULES_DISABLED: Built-in Qt loadable modules that will be removed from the application. List contains module names, separated by semicolon character.
- Slicer_QTSCRIPTEDMODULES_DISABLED: Built-in scripted loadable modules that will be removed from the application. List contains module names, separated by semicolon character.
- Slicer_USE_PYTHONQT_WITH_OPENSSL: enable/disable building the application with SSL support (ON/OFF)
- Slicer_USE_SimpleITK: enable/disable SimpleITK support (ON/OFF)
- Slicer_BUILD_SimpleFilters: enable/disable building SimpleFilters. Requires SimpleITK. (ON/OFF)
- Slicer_BUILD_EMSegment: enable/disable building EM segmenter (ON/OFF)
- Slicer_USE_PYTHONQT_WITH_TCL: TCL support (ON/OFF)
- Slicer_EXTENSION_SOURCE_DIRS: Defines additional extensions that will be included in the application package as built-in modules. Full paths of extension source directories has to be specified, separated by semicolons.
Per-platform instructions
Windows
Recommended: run CMake (cmake-gui) from the Windows Start menu
Set the build directory. For example: C:Slicer-SuperBuild-Debug
or C:Slicer-SuperBuild-Release
.
- Because Windows doesn't support file path longer than 260 characters and has a maximum command line length, please make sure that the total path name of your
Slicer-build
directory is no longer than 50 characters (for examplec:workSlicerSlicer-SuperBuild
may work). In case of any build error, use very short directory names: C:S4 for source directory, C:S4D for debug build, C:S4R for release build. - You cannot use the same build tree for both release or debug mode builds. If both build types are needed, then the same source directory can be used, but a separate build directory should be created and configured for each build type.
- Select your compiler: Visual Studio 14 2015 Win64
- Do not configure yet.
- Add
Qt5_DIR
variable pointing to Qt5 folder such asC:Qt5.10.0msvc2015_64libcmakeQt5
. - Configure
- Click generate then close cmake-gui.
- If building in release mode:
- Open the top-level Slicer.sln file in the build directory in Visual Studio
- Set active configuration to Release. Visual Studio will select Debug build configuration by default when you first open the solution in the Visual Studio GUI. If you build Slicer in release mode and accidentally forget to switch the build configuration to Release then the build will fail. Note: you can avoid this manual configuration mode selection by setting
CMAKE_CONFIGURATION_TYPES
toRelease
in cmake-gui.
- If building in debug mode:
- Start Visual Studio using the Slicer launcher as described in Step-by-step debug instuctions
- Build the ALL_BUILD project
Alternative option: Configure and build using command-line or batch file
Instead of using CMake (cmake-gui), it is also possible to configure by creating a .bat file that contains command-line instructions and run this .bat file each time a Slicer needs to be re-built. The examples below assume Slicer source code is in C:S4
folder and Qt-5.10 is installed in default location.
Visual Studio 2015 in Release mode:
mkdir C:DS4R
cd /d C:DS4R
"C:Program FilesCMakeincmake.exe" -G "Visual Studio 14 2015 Win64" -DQt5_DIR:PATH=C:Qt5.10.0msvc2015_64libcmakeQt5 C:DS4
"C:Program FilesCMakeincmake.exe" --build . --config Release
Visual Studio 2015 in Debug mode:
mkdir C:DS4D
cd /d C:DS4D
"C:Program FilesCMakeincmake.exe" -G "Visual Studio 14 2015 Win64" -DQt5_DIR:PATH=C:Qt5.10.0msvc2015_64libcmakeQt5 C:DS4
"C:Program FilesCMakeincmake.exe" --build . --config Debug
Visual Studio 2017 with VS2015 toolset in Release mode:
mkdir C:DS4R
cd /d C:DS4R
"C:Program FilesCMakeincmake.exe" -G "Visual Studio 15 2017 Win64" -DQt5_DIR:PATH=C:Qt5.10.0msvc2015_64libcmakeQt5 C:DS4
"C:Program FilesCMakeincmake.exe" --build . --config Release
General information
Two projects are generated by either cmake
, ccmake
or cmake-gui
.
One of them is in the top-level bin directory Slicer-SuperBuild
and the other one is in the subdirectory Slicer-build
:
Slicer-SuperBuild/Slicer-build
- The first project in
Slicer-SuperBuild
manages all the external dependencies of Slicer (VTK, ITK, Python, ...). To build Slicer for the first time, run make (or build the solution file in Visual Studio) inSlicer-SuperBuild
, which will update and build the external libraries and if successful will then build the subproject Slicer-build. - The second project in
Slicer-SuperBuild/Slicer-build
is the "traditional" build directory of Slicer. After local changes in Slicer (or after an svn update on the source directory of Slicer), only running make (or building the solution file in Visual Studio) inSlicer-SuperBuild/Slicer-build
is necessary (the external libraries are considered built and up to date). - Warning: An significant amount of disk space is required to compile Slicer in Debug (>10GB on Windows)
Workaround for if the firewall is blocking git protocol
Some firewalls will block the git protocol. A possible workaround is to configure Slicer by disabling the option Slicer_USE_GIT_PROTOCOL
. Then the http protocol will be used instead. Consider also reading https://github.com/commontk/CTK/issues/33
BUILD Slicer
After configuration, start the build process in the Slicer-SuperBuild
directory
Windows (Visual Studio)
Start Windows Explorer. Need help?
- Open
Slicer-SuperBuildSlicer.sln
in Visual Studio - Select build configuration. Usually Release or Debug
- Select menu
Project -> Build Solution
If you make local changes to Slicer, open the solution file located in the directory Slicer-SuperBuild/Slicer-build
instead. You should then be able to either build all projects or just a specific one.
RUN Slicer
Windows
Start Windows Explorer. Need help?
Run Slicer-SuperBuild/Slicer-build/Slicer.exe
Notes:
- Windows: If build was OK, but Slicer doesn't start (e.g. gives the error:
[bin/Release/SlicerQT-real.exe] exit abnormally - Report the problem.
) then one possible root cause is that you have a copy ofPython26.dll
in your windows system directory (e.g.,c:WindowsSystem32python26.dll
). The solution is to rename or remove the python dll in the system directory. See more details here: http://www.na-mic.org/Bug/view.php?id=1180
TEST Slicer
After building, run the tests in the Slicer-SuperBuild/Slicer-build
directory
Windows (Visual Studio)
Start Windows Explorer. Need help?
- Open
Slicer-SuperBuildSlicer.sln
in Visual Studio - Select build configuration. Usually Release or Debug
- In the Solution Explorer, right click on RUN_TESTS project and then select Build
Note: RUN_TESTS project can be found in the CMakePredefinedTargets folder. See here for more details.
PACKAGE Slicer
Windows (Visual Studio)
Note: Make sure to patch VS2008 using the script fix-vc9-redist-manifests.ps1
Start Windows Explorer. Need help?
- Open
Slicer-SuperBuildSlicer-buildSlicer.sln
in Visual Studio - Select Release build configuration.
- In the Solution Explorer, right click on PACKAGE project in group CMakePredefinedTargets and then select Build
Note: PACKAGE project can be found in the CMakePredefinedTargets folder. See here for more details.
来自:https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions