diff --git a/Documentation/Doxygen/3-DeveloperManual/Starting/SettingUpMITK/BuildInstructions.dox b/Documentation/Doxygen/3-DeveloperManual/Starting/SettingUpMITK/BuildInstructions.dox index e281bb8a9e..1d60e02a9d 100644 --- a/Documentation/Doxygen/3-DeveloperManual/Starting/SettingUpMITK/BuildInstructions.dox +++ b/Documentation/Doxygen/3-DeveloperManual/Starting/SettingUpMITK/BuildInstructions.dox @@ -1,233 +1,233 @@ /** \page BuildInstructionsPage Build Instructions \tableofcontents \section BuildInstructions_Introduction Introduction The CMake-based build system of MITK supports a "superbuild" process, meaning that it will download, configure, and build all required third-party libraries (except Qt) automatically. These instructions will show you how to use the MITK superbuild. \note This page explains explicitly how to build MITK itself. If you want to create your own project based on MITK, the process described below is completely automated. Please see \ref HowToNewProject. For more advanced users, the last sections explains how to inject custom build libraries into the superbuild process. \section BuildInstructions_Prerequisites Prerequisites You need: -# Git (there are also numerous third-party graphical clients available). We recommend using Git, but see below for a way how to get the current source code without using it. -# CMake (version \minimumCMakeVersion or higher) -# Qt \minimumQt6Version if you plan to develop Qt-based applications -# If you are using macOS you need an XCode installation and the Command Line Tools as it provides the neccessary compilers and SDKs To build MITK on Linux, install the following packages, e. g. with APT: \code{.unparsed} -sudo apt install build-essential doxygen git graphviz libfreetype6-dev libglu1-mesa-dev libssl-dev libtiff5-dev libxcomposite1 libxcursor1 libxdamage-dev libxi-dev libxkbcommon-x11-0 libxt-dev mesa-common-dev +sudo apt install build-essential doxygen git graphviz libfreetype6-dev libglu1-mesa-dev libssl-dev libtiff5-dev libxcomposite1 libxcursor1 libxdamage-dev libxi-dev libxkbcommon-x11-dev libxt-dev mesa-common-dev \endcode For the optional and experimental (!) Python integration, install NumPy and SimpleITK v1.x, e. g.: \code{.unparsed} sudo apt install python3-numpy python3-pip pip3 install SimpleITK \endcode \section BuildInstructions_Qt A note about Qt As we do not provide Qt in the MITK superbuild you need to install Qt manually. The Qt Company provides online installers for all supported platforms. We highly recommend to install Qt to the default location of the installer as it will allow MITK to automatically find Qt without any further action needed. Make sure to also select the following required components: - Qt 5 Compatibility Module - Qt State Machines - Qt WebEngine On Windows, the Qt installer offers a welcome and straight forward way to install OpenSSL. You find it under the Tools node. \section BuildInstructions_Get_Source Get a source tree Since MITK is under active development we recommend to use Git to check out the latest stable release from the homepage. If you decide to use the most current nightly release, make sure to get a stable tree: Check the MITK dashboard before checking out. If the build tree is not clean, you can specify an older revision for the checkout or get a stable tar ball from www.mitk.org. To clone MITK's current Git repository do: \code git clone https://phabricator.mitk.org/source/mitk.git MITK \endcode \section BuildInstructions_Build_With_CMake Build MITK with CMake Create a new directory for the superbuild binary tree, change to it and call CMake: In the shell (assuming your current directory is the same as the one where you issued the git clone command): \code mkdir MITK-superbuild cd MITK-superbuild ccmake ../MITK \endcode If you use Windows or prefer to use the CMake GUI, start the CMake GUI and enter the location of the source tree and binary tree, choose a suitable generator and configure the project. CMake will present you a couple of options, these are the most important ones: - CMAKE_PREFIX_PATH The path to your Qt installation, e.g., C:/Qt/5.12.9/msvc2017_64 or /home/user/Qt/5.12.9/gcc_64 - MITK_USE_BLUEBERRY Build the BlueBerry application framework - MITK_USE_Boost_LIBRARIES If you need binary Boost libraries, specify them here. - MITK_USE_OpenCV Build MITK code which depends on OpenCV (this will download and build OpenCV 2.4) - MITK_USE_Python3 Enables Python wrapping in MITK. This will also configure ITK, VTK, and OpenCV (if enabled) to build Python wrappers. - MITK_USE_Qt6 Build MITK code which depends on Qt 6 If you are satisfied with the configuration of your MITK superbuild, generate the project files with CMake by pressing "Generate". Linux and macOS users usually just enter "make" (optionally supplying the number threads to be used for a parallel build): \code make -j6 \endcode Windows users using Visual Studio can open the generated MITK-superbuild.sln solution file in the MITK-superbuild directory and start the build by building the BUILD_ALL project. \section BuildInstructions_Customize Customize your MITK superbuild The MITK superbuild configures MITK as well as all external libraries. The build directories of these libraries, and of MITK itself are located inside the MITK-superbuild directory. For example, the directory layout may look like: \code MITK-superbuild |- ep "external projects" |-bin |-lib |-include |-src |- MITK-build \endcode To change the configuration of the MITK build itself, choose the MITK-build directory as the binary directory in the CMake GUI (not the MITK-superbuild directory). After generating the project files, build the MITK project by either issuing "make" in the MITK-build directory (Linux, macOS), or by opening MITK-build/MITK.sln (Windows). You may also change the configuration of any project configured via the superbuild process. Make sure to also build the changed project and also the projects which depend on it. \section BuildInstructions_Running Running Applications On Linux, just execute the application you want to run. MITK executables are located in MITK-superbuild/MITK-build/bin On Windows, the PATH environment variable must contain the directories containing the third-party libraries. This is automatically done from Visual Studio. For running the applications directly use the generated batch files in the MITK-superbuild/MITK-build/bin. \section BuildInstructions_Documentation Documentation If you have the Doxygen documentation tool installed, you get a new project (Visual Studio) or "make" target named "doc". You can build this to generate the HTML documentation of MITK in the Documentation/Doxygen directory of your MITK-build binary tree or in the MITK_DOXYGEN_OUTPUT_DIR CMake variable (if specified). \section BuildInstructions_As_Toolkit Use MITK in your own project (as a toolkit) To use MITK in your external project, add the CMake command find_package(MITK REQUIRED) to your CMakeLists.txt and make use of the CMake macros mitk_create_module() and mitk_create_executable() provided by MITK. Here is a very basic example CMakeLists.txt including MITK as a project: \code cmake_minimum_required(VERSION 3.18 FATAL_ERROR) project(MyProject) find_package(MITK 2023.12 REQUIRED) add_executable(MyApp main.cpp) target_link_libraries(MyApp MitkCore) \endcode with the main.cpp being \code #include #include int main() { MITK_INFO << "Hello world!"; return 0; } \endcode \section BuildInstructions_Advanced_Customization Superbuild customization You can inject pre-build third-party libraries into the MITK superbuild by setting certain CMake variables before the first configure step. MITK will then use these third-party libraries instead of downloading and building them by itself. Note that you must take care of configuring those libraries with all options MITK requires. The variables listed below are provided for injecting third-party libraries. Their occurrence in the CMake GUI or in ccmake may depend on specific MITK_USE_* options set to ON. You may also use the variable names below without the EXTERNAL_ prefix, for example when providing their values on a command line call to CMake. - EXTERNAL_BOOST_ROOT Set this variable to your custom Boost installation - EXTERNAL_CTK_DIR Set this variable to your CTK binary tree (the directory containing the CTKConfig.cmake file) - EXTERNAL_CableSwig_DIR Set this variable to your CableSwig binary tree for Python wrapping (the directory containing the CableSwigConfig.cmake file) - EXTERNAL_DCMTK_DIR Set this variable to your DCMTK binary tree (the directory containing the DCMTKConfig.cmake file) - EXTERNAL_GDCM_DIR Set this variable to your GDCM binary tree (the directory containing the GDCMConfig.cmake file) - EXTERNAL_ITK_DIR Set this variable to your ITK binary tree (the directory containing the ITKConfig.cmake file) - EXTERNAL_OpenCV_DIR Set this variable to your OpenCV binary tree (the directory containing the OpenCVConfig.cmake file) - EXTERNAL_VTK_DIR Set this variable to your VTK binary tree (the directory containing the VTKConfig.cmake file) To set CMake options before the first configure step is invoked, supply them on the command line, i.e. \code ccmake -DITK_DIR:PATH=/opt/ITK-release ../MITK \endcode */ diff --git a/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationHandle.cpp b/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationHandle.cpp index 9b92df55a2..7fd1e10acc 100644 --- a/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationHandle.cpp +++ b/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationHandle.cpp @@ -1,381 +1,381 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryApplicationHandle.h" #include #include #include #include "berryApplicationDescriptor.h" #include "berryApplicationContainer.h" #include "berryCTKPluginActivator.h" #include #include #include #include #include namespace berry { static const QString STARTING = "org.blueberry.app.starting"; static const QString STOPPED = "org.blueberry.app.stopped"; ApplicationHandle::ApplicationHandle(const QString& instanceId, const QHash& arguments, ApplicationDescriptor* descriptor) : instanceId(instanceId) , descriptor(descriptor) , defaultAppInstance(false) , arguments(arguments) , status(FLAG_STARTING) , result(0) , setResult(false) , application(nullptr) { if (instanceId.isEmpty() || descriptor == nullptr) { throw std::invalid_argument("Parameters must not be null!"); } defaultAppInstance = arguments.isEmpty() || this->arguments.remove(ApplicationDescriptor::APP_DEFAULT); } ApplicationDescriptor* ApplicationHandle::getApplicationDescriptor() const { return descriptor; } QString ApplicationHandle::getState_unlocked() const { switch (status) { case FLAG_STARTING : return STARTING; case FLAG_ACTIVE : return ApplicationHandle::RUNNING; case FLAG_STOPPING : return ApplicationHandle::STOPPING; case FLAG_STOPPED : default : // must only check this if the status is STOPPED; otherwise we throw exceptions before we have set the registration. if (!GetServiceRegistration()) { throw ctkIllegalStateException("This instance of the application has been stopped: " + getInstanceId()); } return STOPPED; } } QString ApplicationHandle::getState() const { QMutexLocker l(&mutex); return getState_unlocked(); } QVariant ApplicationHandle::getExitValue(long timeout) const { QMutexLocker l(&mutex); if (!handleRegistration && application == nullptr) return result; QTime stopTime = QTime::currentTime().addMSecs(timeout); while(!setResult && (QTime::currentTime() < stopTime || timeout == 0)) { QCoreApplication::processEvents( QEventLoop::AllEvents, 100 ); } if (!result.isValid()) { throw ctkApplicationException(ctkApplicationException::APPLICATION_EXITVALUE_NOT_AVAILABLE); } return result; } QString ApplicationHandle::getInstanceId() const { return instanceId; } void ApplicationHandle::destroy() { if (STOPPING == getState()) return; // when this method is called we must force the application to exit. // first set the status to stopping SetAppStatus(FLAG_STOPPING); // now force the application to stop IApplication* app = GetApplication(); if (app != nullptr) { app->Stop(); } // make sure the app status is stopped SetAppStatus(FLAG_STOPPED); } QHash ApplicationHandle::GetArguments() const { return arguments; } void ApplicationHandle::ApplicationRunning() { // first set the application handle status to running SetAppStatus(FLAG_ACTIVE); // now run the splash handler /* final ServiceReference[] monitors = getStartupMonitors(); if (monitors == null) return; SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable e) { // just continue ... the exception has already been logged by // handleException(ISafeRunnable) } public void run() throws Exception { for (int i = 0; i < monitors.length; i++) { StartupMonitor monitor = (StartupMonitor) Activator.getContext().getService(monitors[i]); if (monitor != null) { monitor.applicationRunning(); Activator.getContext().ungetService(monitors[i]); } } } }); */ } QVariant ApplicationHandle::run(const QVariant& context_) { QVariant context = context_; if (context.isValid()) { // always force the use of the context if it is not null arguments[IApplicationContext::APPLICATION_ARGS] = context; } else { // get the context from the arguments context = arguments[IApplicationContext::APPLICATION_ARGS]; } QVariant tempResult; try { { QMutexLocker l(&mutex); if (!(status.testFlag(FLAG_STARTING) || status.testFlag(FLAG_STOPPING))) { throw ctkApplicationException(ctkApplicationException::APPLICATION_INTERNAL_ERROR, QString("The application instance has been stopped before it could be started: ") + getInstanceId()); } application = GetConfiguration()->CreateExecutableExtension("run"); waitCondition.wakeAll(); } tempResult = application->Start(this); - if (!tempResult.isValid()) tempResult = QVariant(QVariant::Int); + if (!tempResult.isValid()) tempResult = QVariant(); tempResult = SetInternalResult(tempResult, nullptr); } catch (...) { tempResult = SetInternalResult(tempResult, nullptr); throw; } if (org_blueberry_core_runtime_Activator::DEBUG) { qDebug() << QString("The application \"%1\" returned with code: %2.").arg( getApplicationDescriptor()->getApplicationId()).arg(tempResult.toString()); } return tempResult; } void ApplicationHandle::stop() { try { destroy(); } catch (const ctkIllegalStateException&) { // Do nothing; we don't care that the application was already stopped // return with no error } } void ApplicationHandle::SetAppStatus_unlocked(Status status) { if (this->status == status) { return; } if (status & FLAG_STARTING) { throw std::invalid_argument("Cannot set app status to starting"); } // if status is stopping and the context is already stopping then return if (status & FLAG_STOPPING) { if (this->status & (FLAG_STOPPING | FLAG_STOPPED)) { return; } } // change the service properties to reflect the state change. this->status = status; ctkServiceRegistration handleReg = GetServiceRegistration(); if (!handleReg) return; handleReg.setProperties(GetServiceProperties_unlocked()); // if the status is stopped then unregister the service if (this->status & FLAG_STOPPED) { // GetApplicationDescriptor().getContainerManager().unlock(this); handleReg.unregister(); SetServiceRegistration(ctkServiceRegistration()); } } void ApplicationHandle::SetAppStatus(Status status) { QMutexLocker l(&mutex); SetAppStatus_unlocked(status); } void ApplicationHandle::SetServiceRegistration(const ctkServiceRegistration& sr) { this->handleRegistration = sr; } ctkServiceRegistration ApplicationHandle::GetServiceRegistration() const { return handleRegistration; } ctkDictionary ApplicationHandle::GetServiceProperties_unlocked() const { ctkDictionary props; props[APPLICATION_PID] = getInstanceId(); props[APPLICATION_STATE] = getState_unlocked(); props[APPLICATION_DESCRIPTOR] = getApplicationDescriptor()->getApplicationId(); props[ApplicationDescriptor::APP_TYPE] = getApplicationDescriptor()->GetThreadTypeString(); props[APPLICATION_SUPPORTS_EXITVALUE] = true; if (defaultAppInstance) { props[ApplicationDescriptor::APP_DEFAULT] = defaultAppInstance; } return props; } ctkDictionary ApplicationHandle::GetServiceProperties() const { ctkDictionary props; props[APPLICATION_PID] = getInstanceId(); props[APPLICATION_STATE] = getState(); props[APPLICATION_DESCRIPTOR] = getApplicationDescriptor()->getApplicationId(); props[ApplicationDescriptor::APP_TYPE] = getApplicationDescriptor()->GetThreadTypeString(); props[APPLICATION_SUPPORTS_EXITVALUE] = true; if (defaultAppInstance) { props[ApplicationDescriptor::APP_DEFAULT] = defaultAppInstance; } return props; } QVariant ApplicationHandle::SetInternalResult(const QVariant& result, IApplication* /*tokenApp*/) { QMutexLocker l(&mutex); if (setResult) { throw ctkIllegalStateException("The result of the application is already set."); } /* if (isAsync) { if (!setAsyncResult) throw new IllegalStateException("The application must return IApplicationContext.EXIT_ASYNC_RESULT to set asynchronous results."); //$NON-NLS-1$ if (application != tokenApp) throw new IllegalArgumentException("The application is not the correct instance for this application context."); //$NON-NLS-1$ } else { if (result == IApplicationContext.EXIT_ASYNC_RESULT) { setAsyncResult = true; return nullptr_RESULT; // the result well be set with setResult } } */ this->result = result; setResult = true; application = nullptr; waitCondition.wakeAll(); // The application exited itself; notify the app context SetAppStatus_unlocked(FLAG_STOPPING); // must ensure the STOPPING event is fired SetAppStatus_unlocked(FLAG_STOPPED); // only set the exit code property if this is the default application // (bug 321386) only set the exit code if the result != null; when result == null we assume an exception was thrown if (IsDefault() && !result.isNull()) { //FrameworkProperties::SetProperty(FrameworkProperties::PROP_EXITCODE, result.toInt()); } return result; } IApplication* ApplicationHandle::GetApplication() const { QMutexLocker l(&mutex); if (handleRegistration && application == nullptr) { // the handle has been initialized by the container but the launcher has not // gotten around to creating the application object and starting it yet. waitCondition.wait(&mutex, 5000); // timeout after a while in case there was an internal error and there will be no application created } return application; } bool ApplicationHandle::IsDefault() const { return defaultAppInstance; } IConfigurationElement::Pointer ApplicationHandle::GetConfiguration() const { IExtension::Pointer applicationExtension = getApplicationDescriptor()->GetContainerManager()-> GetAppExtension(getApplicationDescriptor()->getApplicationId()); if (applicationExtension.IsNull()) { throw ctkRuntimeException(QString("Application \"%1\" could not be found in the registry. The applications available are: %2.") .arg(getApplicationDescriptor()->getApplicationId()) .arg(getApplicationDescriptor()->GetContainerManager()->GetAvailableAppsMsg())); } QList configs = applicationExtension->GetConfigurationElements(); if (configs.isEmpty()) { throw ctkRuntimeException(QString("Invalid (empty) application extension \"%1\".") .arg(getApplicationDescriptor()->getApplicationId())); } return configs.front(); } }