diff --git a/.github/workflows/compile-check.yml b/.github/workflows/compile-check.yml index 072875f..c95e6f8 100644 --- a/.github/workflows/compile-check.yml +++ b/.github/workflows/compile-check.yml @@ -63,7 +63,65 @@ jobs: - name: Compile mmCoreAndDevices and ScopeOne shell: bash - run: ./scripts/build-unix.sh + run: ./scripts/build.sh + + compile-installed-qt: + name: Compile (Linux, installed Qt 6.8) + runs-on: ubuntu-24.04 + timeout-minutes: 180 + + steps: + - name: Check out ScopeOne + uses: actions/checkout@v7 + + - name: Install build dependencies + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y \ + git \ + build-essential \ + cmake \ + autoconf \ + automake \ + libtool \ + autoconf-archive \ + pkg-config \ + libboost-all-dev \ + ninja-build curl zip unzip \ + libegl-dev libopengl-dev libx11-xcb-dev libxrender-dev \ + libxcb-cursor-dev libxcb-icccm4-dev libxcb-util-dev libxcb-keysyms1-dev \ + libxcb-randr0-dev libxcb-sync-dev libxcb-xinput-dev libxcb-glx0-dev \ + libxkbcommon-x11-dev + + - name: Set up vcpkg + shell: bash + run: | + git clone https://github.com/microsoft/vcpkg.git "$RUNNER_TEMP/scopeone-vcpkg" + git -C "$RUNNER_TEMP/scopeone-vcpkg" checkout "$(jq -r '."builtin-baseline"' vcpkg.json)" + "$RUNNER_TEMP/scopeone-vcpkg/bootstrap-vcpkg.sh" -disableMetrics + mkdir -p "$RUNNER_TEMP/vcpkg-binary-cache" + echo "VCPKG_ROOT=$RUNNER_TEMP/scopeone-vcpkg" >> "$GITHUB_ENV" + echo "VCPKG_DEFAULT_BINARY_CACHE=$RUNNER_TEMP/vcpkg-binary-cache" >> "$GITHUB_ENV" + + - name: Cache vcpkg binaries + uses: actions/cache@v6 + with: + path: ${{ runner.temp }}/vcpkg-binary-cache + key: vcpkg-scopeone-ubuntu-24.04-installed-qt-${{ hashFiles('vcpkg.json') }} + restore-keys: vcpkg-scopeone-ubuntu-24.04-installed-qt- + + # The oldest Qt that ScopeOne supports, so a newer Qt API used by mistake fails here + - name: Install Qt + uses: jurplel/install-qt-action@v4 + with: + version: 6.8.0 + modules: qtserialport + cache: true + + - name: Compile mmCoreAndDevices and ScopeOne + shell: bash + run: ./scripts/build.sh --qt "$QT_ROOT_DIR" compile-macos: name: Compile (macOS) @@ -100,33 +158,19 @@ jobs: - name: Compile mmCoreAndDevices and ScopeOne shell: bash - run: ./scripts/build-unix.sh + run: ./scripts/build.sh compile-windows: name: Compile (Windows) runs-on: windows-2022 timeout-minutes: 180 - env: - # Keep in sync with windows-release.yml - MMCORE_COMMIT: 212cc416eec291634c916078a31efd4c5f914c64 - steps: - name: Check out ScopeOne uses: actions/checkout@v7 with: submodules: recursive - - name: Set up MSVC - shell: pwsh - run: | - $vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath - cmd /c "`"$vsPath\VC\Auxiliary\Build\vcvars64.bat`" >nul && set" | ForEach-Object { - if ($_ -match '^([^=]+)=(.*)$' -and [Environment]::GetEnvironmentVariable($Matches[1]) -ne $Matches[2]) { - "$($Matches[1])=$($Matches[2])" >> $env:GITHUB_ENV - } - } - - name: Set up vcpkg shell: pwsh run: | @@ -147,20 +191,7 @@ jobs: key: vcpkg-scopeone-x64-windows-${{ hashFiles('vcpkg.json') }} restore-keys: vcpkg-scopeone-x64-windows- - - name: Build MMCore + # build.ps1 clones the latest mmCoreAndDevices and builds MMCore, and the runner has no CUDA + - name: Compile MMCore, Core, drivers and GUI shell: pwsh - run: | - $mm = "$env:GITHUB_WORKSPACE\ScopeOneCore\external\mmCoreAndDevices" - git init $mm - git -C $mm fetch --depth 1 https://github.com/micro-manager/mmCoreAndDevices.git $env:MMCORE_COMMIT - git -C $mm checkout FETCH_HEAD - msbuild "$mm\MMCore\MMCore.vcxproj" /p:Configuration=Release /p:Platform=x64 "/p:SolutionDir=$mm\" /m /nologo /v:minimal - if ($LASTEXITCODE -ne 0) { throw "Building MMCore failed." } - if (-not (Test-Path "$mm\build\Release\x64\MMCore.lib")) { throw "MMCore.lib was not produced." } - - - name: Compile Core, plugins and GUI - shell: pwsh - run: | - .\scripts\build.ps1 --configure ` - --pluginConfigureOption -DSCOPEONE_ENABLE_CUDA=OFF ` - --pluginConfigureOption -DSCOPEONE_ENABLE_INFERENCE=OFF + run: .\scripts\build.ps1 diff --git a/.github/workflows/windows-release.yml b/.github/workflows/windows-release.yml index cc9d2b7..0322306 100644 --- a/.github/workflows/windows-release.yml +++ b/.github/workflows/windows-release.yml @@ -16,11 +16,7 @@ concurrency: cancel-in-progress: false env: - MMCORE_COMMIT: 212cc416eec291634c916078a31efd4c5f914c64 - BOOST_VERSION: 1.86.0 CUDA_VERSION: 12.8.1 - ONNXRUNTIME_PACKAGE: onnxruntime-win-x64-gpu_cuda12-1.30.0 - ONNXRUNTIME_VERSION: 1.30.0 jobs: package: @@ -65,16 +61,6 @@ jobs: } exit 0 - - name: Set up MSVC - shell: pwsh - run: | - $vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath - cmd /c "`"$vsPath\VC\Auxiliary\Build\vcvars64.bat`" >nul && set" | ForEach-Object { - if ($_ -match '^([^=]+)=(.*)$' -and [Environment]::GetEnvironmentVariable($Matches[1]) -ne $Matches[2]) { - "$($Matches[1])=$($Matches[2])" >> $env:GITHUB_ENV - } - } - - name: Set up vcpkg shell: pwsh run: | @@ -95,61 +81,6 @@ jobs: key: vcpkg-scopeone-x64-windows-${{ hashFiles('vcpkg.json') }} restore-keys: vcpkg-scopeone-x64-windows- - - name: Cache Boost - id: boost-cache - uses: actions/cache@v6 - with: - path: ${{ runner.temp }}\boost - key: boost-${{ env.BOOST_VERSION }}-vc143-x64 - - - name: Build Boost for SerialManager - if: steps.boost-cache.outputs.cache-hit != 'true' - shell: pwsh - run: | - $name = "boost_$($env:BOOST_VERSION -replace '\.', '_')" - $archive = "$env:RUNNER_TEMP\$name.7z" - Invoke-WebRequest "https://archives.boost.io/release/$env:BOOST_VERSION/source/$name.7z" -OutFile $archive - 7z x $archive "-o$env:RUNNER_TEMP" -y | Out-Null - Push-Location "$env:RUNNER_TEMP\$name" - .\bootstrap.bat - if ($LASTEXITCODE -ne 0) { throw "Boost bootstrap failed." } - .\b2 --with-thread --with-chrono --with-date_time --with-system toolset=msvc-14.3 address-model=64 architecture=x86 link=static runtime-link=shared threading=multi variant=release -j4 stage - if ($LASTEXITCODE -ne 0) { throw "Boost build failed." } - Pop-Location - $boostRoot = "$env:RUNNER_TEMP\boost" - New-Item -ItemType Directory -Force -Path $boostRoot | Out-Null - Move-Item "$env:RUNNER_TEMP\$name\boost" "$boostRoot\boost" - Move-Item "$env:RUNNER_TEMP\$name\stage\lib" "$boostRoot\lib" - - - name: Build Micro-Manager core and adapters - shell: pwsh - run: | - $mm = "$env:GITHUB_WORKSPACE\ScopeOneCore\external\mmCoreAndDevices" - git init $mm - git -C $mm fetch --depth 1 https://github.com/micro-manager/mmCoreAndDevices.git $env:MMCORE_COMMIT - git -C $mm checkout FETCH_HEAD - $boostRoot = "$env:RUNNER_TEMP\boost" - $properties = @( - "/p:Configuration=Release", - "/p:Platform=x64", - "/p:SolutionDir=$mm\", - "/p:MM_BOOST_INCLUDEDIR=$boostRoot", - "/p:MM_BOOST_LIBDIR=$boostRoot\lib", - "/m", - "/nologo", - "/v:minimal" - ) - foreach ($project in @( - "MMCore\MMCore.vcxproj", - "DeviceAdapters\DemoCamera\DemoCamera.vcxproj", - "DeviceAdapters\Utilities\Utilities.vcxproj", - "DeviceAdapters\SerialManager\SerialManager.vcxproj" - )) { - msbuild "$mm\$project" @properties - if ($LASTEXITCODE -ne 0) { throw "Building $project failed." } - } - Get-ChildItem "$mm\build\Release\x64" -File | Select-Object Name, Length - - name: Install CUDA if: matrix.gpu shell: pwsh @@ -174,14 +105,6 @@ jobs: "CUDA_PATH_V$($short -replace '\.', '_')=$cudaPath" >> $env:GITHUB_ENV "$cudaPath\bin" >> $env:GITHUB_PATH - - name: Download ONNX Runtime - if: matrix.gpu - shell: pwsh - run: | - $archive = "$env:RUNNER_TEMP\$env:ONNXRUNTIME_PACKAGE.zip" - Invoke-WebRequest "https://github.com/microsoft/onnxruntime/releases/download/v$env:ONNXRUNTIME_VERSION/$env:ONNXRUNTIME_PACKAGE.zip" -OutFile $archive - Expand-Archive $archive -DestinationPath "$env:GITHUB_WORKSPACE\ScopeOneCore\external" - - name: Set up NSIS shell: pwsh run: | @@ -190,20 +113,11 @@ jobs: choco install nsis -y --no-progress } + # build.ps1 clones the latest mmCoreAndDevices and builds MMCore, and Core is built with CUDA + # when the step above put nvcc on the path - name: Build and package shell: pwsh - run: | - $options = @() - if ("${{ matrix.gpu }}" -eq "true") { - $options += @("--guiConfigureOption", "-DSCOPEONE_PACKAGE_VARIANT=gpu") - } - else { - $options += @( - "--pluginConfigureOption", "-DSCOPEONE_ENABLE_CUDA=OFF", - "--pluginConfigureOption", "-DSCOPEONE_ENABLE_INFERENCE=OFF" - ) - } - .\scripts\build.ps1 --configure --package @options + run: .\scripts\build.ps1 --package - name: Check packages shell: pwsh @@ -214,9 +128,11 @@ jobs: Get-Item $file | Select-Object Name, Length } $listing = 7z l "build\$name.zip" - $hasGpuFiles = [bool]($listing | Select-String -Pattern "cufft64|onnxruntime|ScopeOneInference") - if ("${{ matrix.gpu }}" -eq "true" -and -not $hasGpuFiles) { throw "The GPU package has no CUDA or ONNX Runtime files." } - if ("${{ matrix.gpu }}" -ne "true" -and $hasGpuFiles) { throw "The standard package must not contain CUDA or ONNX Runtime files." } + # Both packages carry ONNX Runtime, and only the GPU one its CUDA provider and cuFFT + if (-not ($listing | Select-String -Pattern "onnxruntime\.dll")) { throw "The package has no ONNX Runtime." } + $hasGpuFiles = [bool]($listing | Select-String -Pattern "cufft64|onnxruntime_providers_cuda") + if ("${{ matrix.gpu }}" -eq "true" -and -not $hasGpuFiles) { throw "The GPU package has no CUDA files." } + if ("${{ matrix.gpu }}" -ne "true" -and $hasGpuFiles) { throw "The standard package must not contain CUDA files." } - name: Upload packages uses: actions/upload-artifact@v7 @@ -257,8 +173,8 @@ jobs: run: | ls -l packages cat > notes.md <<'NOTES' - - **Standard** (`win-x64`): live imaging, recording and image processing on CPU. - - **GPU** (`win-x64-gpu`): adds CUDA processing and ONNX inference. Needs an NVIDIA GPU. + - **Standard** (`win-x64`): live imaging, recording, image processing and inference on CPU. + - **GPU** (`win-x64-gpu`): adds CUDA processing and ONNX inference on CUDA. Needs an NVIDIA GPU. ONNX inference on CUDA also needs cuDNN 9 and the cuBLAS of CUDA 12 on the `PATH`, which the package does not include. NOTES gh release create "v${{ steps.version.outputs.version }}" packages/* \ --target "$GITHUB_SHA" \ diff --git a/.gitignore b/.gitignore index 1507cac..cc522c8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,14 +3,11 @@ !/src/** !/ScopeOneCore/ !/ScopeOneCore/** -!/plugins/ -!/plugins/** -!/ScopeOneCuda/ -!/ScopeOneCuda/** -!/ScopeOneInference/ -!/ScopeOneInference/** +!/drivers/ +!/drivers/** /ScopeOneCore/install/ /ScopeOneCore/build/ +/drivers/build/ /ScopeOneCore/external/* !/ScopeOneCore/external/ScopeWriter/ !/ScopeOneCore/external/ScopeWriter/** @@ -29,6 +26,9 @@ !/config/MMConfig_demo.cfg !/config/dual_hamamatsu_897D.cfg !/config/MMConfig_demo_dual.cfg +!/config/ScopeOne_MM_demo.cfg +!/config/ScopeOne_demo.cfg +!/config/ScopeOne_Cobolt_Jive.cfg !/CMakeLists.txt !/README.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fb9c02..038bedf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.23) include("${CMAKE_CURRENT_LIST_DIR}/ScopeOneCore/cmake/ScopeOneVersion.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/ScopeOneCore/cmake/ScopeOneQt.cmake") scopeone_resolve_version(SCOPEONE_VERSION "${CMAKE_CURRENT_LIST_DIR}") project(ScopeOne VERSION "${SCOPEONE_VERSION}" LANGUAGES CXX) @@ -37,7 +38,7 @@ configure_file( @ONLY ) -find_package(Qt6 COMPONENTS +find_package(Qt6 ${SCOPEONE_QT_MINIMUM_VERSION} COMPONENTS Core Gui Widgets @@ -47,6 +48,7 @@ find_package(Qt6 COMPONENTS Concurrent REQUIRED ) +message(STATUS "Using Qt ${Qt6_VERSION} from ${Qt6_DIR}") find_package(ScopeOneCore CONFIG REQUIRED) @@ -62,84 +64,14 @@ if (WIN32 AND TARGET Qt6::qmake) endif () endif () -set(SCOPEONE_UI_SOURCES - src/main.cpp - src/CameraScaleDialog.cpp - src/ConfigPresetWidget.cpp - src/DeviceControlWidget.cpp - src/DevicePropertyWidget.cpp - src/PositionListFile.cpp - src/RecordingWidget.cpp - src/StageMosaicDialog.cpp - src/PluginManagerDialog.cpp - src/ScopeOneLocalApiServer.cpp - src/ScopeOneToolPlugin.cpp - src/AboutDialog.cpp - src/Appearance.cpp - src/CollapsibleSection.cpp - src/CommandSearchBox.cpp - src/ConsoleWidget.cpp - src/EmptyHint.cpp - src/MainWindow.cpp - src/PtyProcess.cpp - src/SettingsDialog.cpp - src/TerminalWidget.cpp - src/ToolIcons.cpp - src/UpdateChecker.cpp - src/WelcomeOverlay.cpp - src/ImageAnalysis.cpp - src/ImageGalleryWidget.cpp - src/ImageProcessingWidget.cpp - src/ImageWorkspace.cpp - src/InspectWidget.cpp - src/OrthogonalViewsDialog.cpp - src/ParameterDialog.cpp - src/ParticleDetectionDialog.cpp - src/PreviewWidget.cpp - src/ProfilePlotWindow.cpp - src/ResultsWindow.cpp - src/RoiManagerWindow.cpp - ${CMAKE_SOURCE_DIR}/resources/resources.qrc -) - -set(SCOPEONE_UI_HEADERS - src/CameraScaleDialog.h - src/ConfigPresetWidget.h - src/DeviceControlWidget.h - src/DevicePropertyWidget.h - src/PositionListFile.h - src/RecordingWidget.h - src/StageMosaicDialog.h - src/PluginManagerDialog.h - src/ScopeOneLocalApiServer.h - src/ScopeOneToolPlugin.h - src/AboutDialog.h - src/Appearance.h - src/CollapsibleSection.h - src/CommandSearchBox.h - src/ConsoleWidget.h - src/EmptyHint.h - src/MainWindow.h - src/PtyProcess.h - src/SettingsDialog.h - src/TerminalWidget.h - src/ToolIcons.h - src/UpdateChecker.h - src/WelcomeOverlay.h - src/ImageAnalysis.h - src/ImageGalleryWidget.h - src/ImageProcessingWidget.h - src/ImageWorkspace.h - src/InspectWidget.h - src/OrthogonalViewsDialog.h - src/ParameterDialog.h - src/ParticleDetectionDialog.h - src/PreviewWidget.h - src/ProfilePlotWindow.h - src/ResultsWindow.h - src/RoiManagerWindow.h - src/StackAxes.h +# Every source file of src is part of the application, the tools in src/tools included, and +# ScopeOneMcpServer.cpp is its own executable +file(GLOB_RECURSE SCOPEONE_UI_FILES CONFIGURE_DEPENDS + "${CMAKE_SOURCE_DIR}/src/*.cpp" + "${CMAKE_SOURCE_DIR}/src/*.h" ) +list(REMOVE_ITEM SCOPEONE_UI_FILES "${CMAKE_SOURCE_DIR}/src/ScopeOneMcpServer.cpp") +set(SCOPEONE_UI_SOURCES ${SCOPEONE_UI_FILES} ${CMAKE_SOURCE_DIR}/resources/resources.qrc) if (WIN32) list(APPEND SCOPEONE_UI_SOURCES ${CMAKE_SOURCE_DIR}/resources/app_icon.rc) @@ -148,7 +80,6 @@ endif () qt_add_executable(ScopeOne WIN32 ${SCOPEONE_UI_SOURCES} - ${SCOPEONE_UI_HEADERS} ) qt_add_executable(ScopeOneMcpServer src/ScopeOneMcpServer.cpp @@ -221,6 +152,8 @@ install(TARGETS ScopeOne ScopeOneMcpServer install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/config/MMConfig_demo.cfg" "${CMAKE_CURRENT_SOURCE_DIR}/config/MMConfig_demo_dual.cfg" + "${CMAKE_CURRENT_SOURCE_DIR}/config/ScopeOne_demo.cfg" + "${CMAKE_CURRENT_SOURCE_DIR}/config/ScopeOne_MM_demo.cfg" DESTINATION . ) @@ -231,11 +164,17 @@ if (WIN32) "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_BINDIR}/ScopeOne_DriverHost.exe" ) else () - file(GLOB SCOPEONE_CORE_RUNTIME_FILES + # The lib folder of the Core install holds only Core's libraries and ONNX Runtime, and the + # copied DriverHost resolves them beside itself. Named one by one, the list had missed the + # macOS dylibs. + file(GLOB SCOPEONE_CORE_LIBRARIES LIST_DIRECTORIES false + "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_LIBDIR}/*.so*" + "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_LIBDIR}/*.dylib" + ) + set(SCOPEONE_CORE_RUNTIME_FILES "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_BINDIR}/ScopeOne_DriverHost" - "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_LIBDIR}/libScopeOneCore.so*" - "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_LIBDIR}/libScopeWriter.so*" + ${SCOPEONE_CORE_LIBRARIES} ) endif () @@ -243,46 +182,57 @@ if (SCOPEONE_CORE_RUNTIME_FILES) # A target of its own that runs on every build. As a post-build step of ScopeOne it ran only # when the application itself was relinked, so a rebuilt core library was left behind next # to an older copy that the application kept loading. - add_custom_target(ScopeOneCoreRuntime ALL - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${SCOPEONE_CORE_RUNTIME_FILES} - "$" - COMMAND_EXPAND_LISTS - ) + if (WIN32) + add_custom_target(ScopeOneCoreRuntime ALL + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${SCOPEONE_CORE_RUNTIME_FILES} + "$" + COMMAND_EXPAND_LISTS + ) + else () + # A library comes as a file and its links, libonnxruntime.so, .so.1 and .so.1.30.0, and + # copying them as files put three full copies of ONNX Runtime beside ScopeOne + string(REPLACE ";" "|" _core_runtime_files "${SCOPEONE_CORE_RUNTIME_FILES}") + add_custom_target(ScopeOneCoreRuntime ALL + COMMAND ${CMAKE_COMMAND} + "-DFILES=${_core_runtime_files}" + "-DDEST=$" + -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/CopyRuntimeFiles.cmake" + VERBATIM + ) + endif () add_dependencies(ScopeOneCoreRuntime ScopeOne) endif () -if (UNIX AND NOT APPLE) - file(GLOB SCOPEONE_CORE_SHARED_LIBRARIES - LIST_DIRECTORIES false - "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_LIBDIR}/libScopeOneCore.so*" - "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_LIBDIR}/libScopeWriter.so*" - ) - install(FILES - ${SCOPEONE_CORE_SHARED_LIBRARIES} - DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) +if (WIN32) + install(FILES ${SCOPEONE_CORE_RUNTIME_FILES} DESTINATION .) +elseif (NOT APPLE) + install(FILES ${SCOPEONE_CORE_LIBRARIES} DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif () -foreach (_plugin_kind IN ITEMS processing hardware tools) - set(_plugin_dir "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_BINDIR}/plugins/${_plugin_kind}") - if (EXISTS "${_plugin_dir}") - add_custom_command(TARGET ScopeOne POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${_plugin_dir}" - "$/plugins/${_plugin_kind}" - ) - install(DIRECTORY "${_plugin_dir}/" DESTINATION "plugins/${_plugin_kind}") - endif () -endforeach () +set(_driver_dir "${ScopeOneCore_ROOT}/${CMAKE_INSTALL_BINDIR}/drivers") +if (EXISTS "${_driver_dir}") + # Copied on every build. As a step after linking ScopeOne it ran only when ScopeOne itself was + # relinked, so rebuilt drivers stayed old beside the application and crashed a newer DriverHost. + add_custom_target(ScopeOneDrivers ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${_driver_dir}" + "$/drivers" + ) + add_dependencies(ScopeOneDrivers ScopeOne) + install(DIRECTORY "${_driver_dir}/" DESTINATION "drivers") +endif () if (WIN32) if (WINDEPLOYQT_EXECUTABLE) + # windeployqt finds the modules of ScopeOne.exe only, and Serial Port is linked by the + # serial driver alone, so it is named here add_custom_command(TARGET ScopeOne POST_BUILD COMMAND "${WINDEPLOYQT_EXECUTABLE}" --no-translations --no-compiler-runtime --release + --serialport "$" WORKING_DIRECTORY "${SCOPEONE_QT_BIN_DIR}" VERBATIM @@ -292,37 +242,14 @@ if (WIN32) endif () endif () -# # Fast Release build -# if (MSVC) -# target_compile_options(ScopeOne PRIVATE -# $<$:/MP> -# ) -# endif () - -# LTO Release build +# /MP compiles the sources of one project in parallel, which the Visual Studio generator does not, +# and Release builds use LTO if (MSVC) - target_compile_options(ScopeOne PRIVATE - $<$:/GL /fp:fast /arch:AVX2> - ) - target_link_options(ScopeOne PRIVATE - $<$:/LTCG> - ) + target_compile_options(ScopeOne PRIVATE /MP $<$:/GL /fp:fast /arch:AVX2>) + target_link_options(ScopeOne PRIVATE $<$:/LTCG>) + target_compile_options(ScopeOneMcpServer PRIVATE /MP) endif () if (WIN32) - install(CODE " - file(GLOB _core_runtime_files - \"$/*.dll\" - \"$/ScopeOne_DriverHost.exe\" - ) - if (_core_runtime_files) - file(INSTALL - DESTINATION \"\${CMAKE_INSTALL_PREFIX}\" - TYPE FILE - FILES \${_core_runtime_files} - ) - endif() - ") - install(CODE " set(_runtime_dir \"${CMAKE_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}\") if (NOT EXISTS \"\${_runtime_dir}/$\") @@ -373,9 +300,9 @@ set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/Experimental-Microscopy-Lab/S set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}") -set(SCOPEONE_PACKAGE_VARIANT "" CACHE STRING "Package variant suffix, for example gpu") -if (SCOPEONE_PACKAGE_VARIANT) - set(CPACK_PACKAGE_FILE_NAME "ScopeOne-${PROJECT_VERSION}-win-x64-${SCOPEONE_PACKAGE_VARIANT}") +# A Core built with CUDA makes the GPU package +if (ScopeOneCore_WITH_CUDA) + set(CPACK_PACKAGE_FILE_NAME "ScopeOne-${PROJECT_VERSION}-win-x64-gpu") else () set(CPACK_PACKAGE_FILE_NAME "ScopeOne-${PROJECT_VERSION}-win-x64") endif () diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11d10aa..105ab1b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,33 +1,65 @@ # Development guidelines -These rules apply to everyone who changes ScopeOne. The README explains how to build; this file -explains how the code is meant to be written. Each rule says why. When a rule and its reason +These rules apply to everyone who changes ScopeOne. The README explains how to build: on Windows, +`powershell -ExecutionPolicy Bypass -File .\scripts\build.ps1 --run` after installing Git and the +Visual Studio Build Tools, and on Linux and macOS `./scripts/build.sh`. This file explains +how the code is meant to be written. Each rule says why. When a rule and its reason disagree in a specific case, follow the reason and say so in the review. +## Philosophy + +**C++ and Python.** The parts that drive the hardware and handle every frame are written in C++: +acquisition, recording, display, and processing that has to keep up with the camera. They have to be +fast and predictable, and Qt lets the same code run on Windows, Linux and macOS. Python is for the +methods researchers write themselves: a processing step, an analysis of recorded data, or a script +that runs an experiment through the Local API. Each Python module runs in its own process, so a slow +or broken script cannot hold up the microscope. When a Python method turns out to be needed at the +full frame rate, it is rewritten in C++. + +**One place for processing.** Frames from every camera end up in the same pipeline, whatever the +platform and whatever the hardware. A processing step can be a C++ module on the CPU, a CUDA module +on an NVIDIA GPU, an ONNX model, or a Python function, and it plugs in the same way. Whoever adds a +method gets the live view, recording and the Local API with it, and the person at the microscope +just picks the method. + ## Boundaries **Layers.** Dependencies point one way: | Part | Folder | Namespace | May use | |---|---|---|---| -| Core | `ScopeOneCore` | `scopeone::core`, `core::internal`, `core::imageops` | Qt Core, OpenCV, MMCore, ScopeWriter. No Qt Widgets. | +| Core | `ScopeOneCore` | `scopeone::core`, `core::internal`, `core::imageops`, `core::internal::cuda` and `core::internal::inference` for the CUDA and ONNX modules | Qt Core, OpenCV, MMCore, ScopeWriter, and CUDA and ONNX Runtime when they are built. No Qt Widgets. | | Application | `src` | `scopeone::ui` | Core, Qt Widgets | | MCP server | `src/ScopeOneMcpServer.cpp` | | Qt Core, Qt Network and the Local API protocol. Not Core. | -| Plugins | `plugins`, `ScopeOneCuda`, `ScopeOneInference` | their own | `scopeone::PluginSDK` | +| Drivers | `drivers` | their own | `scopeone::DriverSDK` | | Python package | `ScopeOneCore/python/scopeone` | `scopeone` | the Local API protocol | -A lower layer never knows about a higher one. Core does not include from `src`, and plugins do -not include Core internals. This keeps each part buildable and usable without the ones above it. +A lower layer never knows about a higher one. Core does not include from `src`, and drivers do not include +Core internals. This keeps each part buildable and usable without the ones above it. **Entry points.** Code outside Core enters through the public headers in `ScopeOneCore/include/scopeone` and the `ScopeOneCore` facade. `ScopeOneCore/internal` is for Core -alone. Plugins see only the SDK headers; a tool plugin gets `ScopeOneToolCore`, not the Core. +alone. Drivers see only `ScopeOneCore/sdk`, enforced by the build. A narrow entry point is what lets Core change its insides without breaking callers. **Decide the layer first.** Before writing a feature, decide where it belongs. Anything that must work without a window (acquisition, hardware, processing, recording, data) goes into Core and is reachable through the Local API before it gets a widget. Anything that only changes what -is shown goes into `src`. Hardware and optional processing go into plugins. +is shown goes into `src`. Hardware goes into drivers. + +**Tools.** A window of the Tools menu, with its own state and workflow, goes into its own folder +under `src/tools`. It uses only the public Core headers and `ToolContext` from +`src/tools/ToolContext.h`, and registers itself with `SCOPEONE_REGISTER_TOOL` at the end of its +source file, so adding a tool changes neither `MainWindow` nor CMake. Its algorithm belongs in Core. +A command that takes an image and parameters and returns a result is not a tool; it belongs in the +image menus. + +**Extension boundary.** Drivers and Python processing modules are the only public +extension points, and both run outside the ScopeOne process. Every other processing method +belongs in Core, with its window in `src`. The CUDA and ONNX modules are in Core too, under +`src/cuda` and `src/inference`, and `SCOPEONE_ENABLE_CUDA` builds Core without CUDA. The +messages between ScopeOne and `ScopeOne_DriverHost` are internal too and are described in +`ScopeOneCore/DRIVERHOST_PROTOCOL.md`. **Python API.** The `ScopeOne` client controls a running ScopeOne and moves frames in and out as numpy arrays. It does not reimplement analysis that numpy already does. `scopeone.processing` @@ -125,7 +157,7 @@ not send style-only changes. - Constant strings use `QStringLiteral`; text the user sees goes through `tr()`. - Our own code does not throw. MMCore, OpenCV and ONNX Runtime do, so catch their exceptions at the call site and turn them into an error value or a log message. -- Casts: `qobject_cast` for QObjects, `static_cast` otherwise. `dynamic_cast` only across plugin +- Casts: `qobject_cast` for QObjects, `static_cast` otherwise. `dynamic_cast` only across library interfaces. - Logging: `qWarning` for real problems. Do not leave `qDebug` behind. @@ -182,7 +214,7 @@ with a slash. and moving code are separate changes, because they hide the real change in review. Do not touch lines you are not changing. -**Build everything you touched.** Core, the application and the plugins all build before you +**Build everything you touched.** Core, the drivers and the application all build before you send a change, with no new warnings. A change in a header builds every part that includes it. **Run what you changed.** A change to behavior is run in the application, with a configuration @@ -202,12 +234,15 @@ in only some of them is a bug. the existing dependencies cannot meet, a licence that allows redistribution with ScopeOne, and a pinned version in `vcpkg.json`. +**Qt version.** ScopeOne supports Qt 6.8 and later, so code does not use Qt API added after 6.8. +A newer API that is worth it is a reason to raise the minimum; open an issue to discuss it. + ## Versions **Core.** The version is `MAJOR.MINOR.MMDD`: `MAJOR.MINOR` comes from `VERSION`, the last part is the date of the last commit. Raise `MINOR` whenever a public SDK header changes. ScopeOne loads -a plugin only when its Core `MAJOR.MINOR` matches, and each plugin kind has its own -`scopeOneApi` contract version. +a driver only when its Core `MAJOR.MINOR` matches, and drivers have their own `scopeOneApi` +contract version. **Dependencies are pinned.** vcpkg packages, Python (`==3.14.*`) and Python packages (`numpy==2.5.3`) use exact versions. Upgrade them together, on purpose. diff --git a/README.md b/README.md index 9a48877..6bde7be 100644 --- a/README.md +++ b/README.md @@ -29,17 +29,16 @@ Deep learning is becoming an increasingly powerful tool for microscopy image res

### GPU-Accelerated Online Image Processing -Despite the deep learning, traditional image processing methods remain essential. GPU-accelerated image processing pipeline can be applied to live camera streams or recorded images, including filtering, background subtraction, FFT, and more. Users can customize image processing algorithms and parameters to suit their specific needs via the ScopeOne plugin system. +Despite the deep learning, traditional image processing methods remain essential. GPU-accelerated image processing pipeline can be applied to live camera streams or recorded images, including filtering, background subtraction, FFT, and more. Users can customize image processing algorithms and parameters to suit their specific needs with Python processing modules. ## 🚀 Quick Start -### For Users - Download the latest release installer from the [Releases](https://github.com/Experimental-Microscopy-Lab/ScopeOne/releases) page. **System Requirements:** - Windows 10/11 (64-bit) - Micro-Manager device adapters for your hardware +- For the GPU package, an NVIDIA GPU; ONNX inference on CUDA also needs cuDNN 9 and the cuBLAS of CUDA 12 on the `PATH`, which the package does not include **Device Adapter Setup:** @@ -49,123 +48,214 @@ ScopeOne loads Micro-Manager configuration files (.cfg) directly and includes th There is an example dual-camera .cfg file in the config folder, just change the camera labels in Devices section to match your camera models. -### For Developers +## 🛠️ For Developers -Read [CONTRIBUTING.md](CONTRIBUTING.md) before changing the code. +**TL;DR.** On a fresh machine, without spending time on setting up the C++ environment, run these commands. They install the tools, clone ScopeOne, and let the script build everything else, and start ScopeOne. The first build takes long, see [Build times](#build-times). -**Prerequisites:** +Windows: -- [CMake](https://cmake.org/download/) 3.23 or newer -- A C++20 compiler: [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) (MSVC v143 toolset) on Windows, GCC or Clang on Linux and macOS (experimental) -- [vcpkg](https://github.com/microsoft/vcpkg) for Qt 6.11.2, OpenCV 4.14.0, and ScopeWriter's libtiff, zlib, zstd and crc32c -- Git, for the submodules (including mmCoreAndDevices) -- Python 3.14, only for the Python package and Python processing modules +```powershell +winget install Microsoft.VisualStudio.2022.BuildTools --override "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --passive --wait" +git clone --recurse-submodules https://github.com/Experimental-Microscopy-Lab/ScopeOne.git +cd ScopeOne +powershell -ExecutionPolicy Bypass -File .\scripts\build.ps1 --run +``` -Clone ScopeOne with its submodules, or initialize them in an existing checkout: +Linux (Debian, Ubuntu): -```powershell +```bash +sudo apt install \ + build-essential cmake autoconf automake libtool autoconf-archive \ + pkg-config ninja-build curl zip unzip libboost-all-dev +sudo apt install --no-upgrade \ + libegl-dev libopengl-dev libx11-xcb-dev libxrender-dev \ + libxcb-cursor-dev libxcb-icccm4-dev libxcb-util-dev libxcb-keysyms1-dev \ + libxcb-randr0-dev libxcb-sync-dev libxcb-xinput-dev libxcb-glx0-dev \ + libxkbcommon-x11-dev git clone --recurse-submodules https://github.com/Experimental-Microscopy-Lab/ScopeOne.git -git submodule update --init --recursive +cd ScopeOne +./scripts/build.sh --run ``` -The expected layout is: +macOS: -```text -ScopeOne/ - ScopeOneCore/ - include/scopeone/ Core API and external plugin contracts - external/ - mmCoreAndDevices/ - ScopeWriter/ +```bash +xcode-select --install +brew install cmake autoconf automake libtool autoconf-archive pkg-config ninja boost +git clone --recurse-submodules https://github.com/Experimental-Microscopy-Lab/ScopeOne.git +cd ScopeOne +./scripts/build.sh --run ``` -### Plugin layout +A coding agent such as Claude Code or Codex can also do this: ask it to set up and build ScopeOne by following this README. -ScopeOne loads plugins from `plugins/processing`, `plugins/tools` and `plugins/hardware` beside the application, and Python processing modules from `plugins/processing/python`. All plugins build against the installed `scopeone::PluginSDK` target and the contracts in `ScopeOneCore/include/scopeone`. Micro-Manager remains the built-in camera provider and loads its device adapters from `.cfg` files, while other native cameras use the `HardwareProvider` contract. [plugins/README.md](plugins/README.md) explains how to write, build and install a plugin. +Read [CONTRIBUTING.md](CONTRIBUTING.md) before changing the code. -**Windows Build Steps:** +### Qt -Set up vcpkg once outside the ScopeOne repository: +ScopeOne needs Qt 6.8 or later. There are three ways to get it. -```powershell -git clone https://github.com/microsoft/vcpkg.git C:/dev/vcpkg -C:/dev/vcpkg/bootstrap-vcpkg.bat -$env:VCPKG_ROOT = "C:/dev/vcpkg" -``` +- **Qt is already installed.** Pass its directory once and the script uses it instead of building Qt: -Build Core, plugins, and GUI with the repository script: + ```powershell + # Windows + powershell -ExecutionPolicy Bypass -File .\scripts\build.ps1 --qt C:\Qt\6.11.2\msvc2022_64 + # Linux and macOS + ./scripts/build.sh --qt ~/Qt/6.11.2/gcc_64 # macOS: ~/Qt/6.11.2/macos + ``` -```powershell -.\scripts\build.ps1 --configure -``` + On Windows the script saves the path as `SCOPEONE_QT_DIR` for your user account, and `--qt vcpkg` goes back to the Qt that vcpkg builds. On Linux and macOS, export `SCOPEONE_QT_DIR` with that path to keep it without `--qt`. -Later builds only need `.\scripts\build.ps1`. Core, GUI, and plugins share `vcpkg_installed/`, and CMake installs the dependencies on the first configure. +- **Install Qt yourself** with the [Qt Online Installer](https://www.qt.io/download-qt-installer-oss), then pass its directory as above. On Windows choose the MSVC 2022 64-bit build; MinGW does not work. -For a direct Core CMake configure: +- **Let the script build it.** Without `--qt`, vcpkg builds Qt on the first build, see [Build times](#build-times). -```powershell -cmake -S ScopeOneCore -B ScopeOneCore/build ` - "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" ` - "-DVCPKG_MANIFEST_DIR=$PWD" ` - "-DVCPKG_INSTALLED_DIR=$PWD/vcpkg_installed" ` - -DVCPKG_TARGET_TRIPLET=x64-windows -``` +### Windows, step by step -Run the built application: +1. **Install the C++ build tools.** In a terminal: -```powershell -.\build\Release\ScopeOne.exe -``` + ```powershell + winget install Microsoft.VisualStudio.2022.BuildTools --override "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --passive --wait" + ``` -**Linux and macOS Build Steps:** + `winget` comes with Windows 10 and 11. The command installs MSVC, the Windows SDK and CMake. It asks for administrator rights, downloads a few gigabytes and takes 10 to 20 minutes. An existing Visual Studio 2022 with "Desktop development with C++" works as well. -Micro-Manager is built from its own checkout because its native core and device adapters are not vcpkg dependencies. Everything else comes from vcpkg with the dynamic triplet of the host, so Qt is shared between the GUI, ScopeOneCore, and plugins. + A Qt passed with `--qt` needs the Qt Serial Port module, which the serial driver links. -1. Install the system build tools. +2. **Clone ScopeOne.** -Linux: + ```powershell + git clone --recurse-submodules https://github.com/Experimental-Microscopy-Lab/ScopeOne.git + cd ScopeOne + ``` -```bash -sudo apt install \ - git build-essential cmake autoconf automake libtool autoconf-archive \ - pkg-config ninja-build curl zip unzip libboost-all-dev -sudo apt install --no-upgrade \ - libegl-dev libopengl-dev libx11-xcb-dev libxrender-dev \ - libxcb-cursor-dev libxcb-icccm4-dev libxcb-util-dev libxcb-keysyms1-dev \ - libxcb-randr0-dev libxcb-sync-dev libxcb-xinput-dev libxcb-glx0-dev \ - libxkbcommon-x11-dev -``` +3. **Build and start it.** -The second command installs the X11 and OpenGL development files that vcpkg's `qtbase` port expects from the system. It is not a system Qt installation, and `--no-upgrade` keeps it from upgrading the installed Mesa drivers. + ```powershell + powershell -ExecutionPolicy Bypass -File .\scripts\build.ps1 --run + ``` -macOS: + Windows blocks `.ps1` scripts by default, and `-ExecutionPolicy Bypass` lifts that for this one command. To lift it for good, run `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned` once; the script then starts as `.\scripts\build.ps1 --run`. -```bash -xcode-select --install -brew install \ - git cmake autoconf automake libtool autoconf-archive \ - pkg-config ninja boost -``` + The script finds Visual Studio itself. It offers to download vcpkg into `%USERPROFILE%\vcpkg` and saves `VCPKG_ROOT` for your user account, and `--yes` accepts without asking. It then builds MMCore with the DemoCamera and Utilities adapters, ScopeOneCore, the drivers and the GUI. -2. Build from the ScopeOne repository root: + The first build takes long, see [Build times](#build-times). The last lines of the build show whether Core was built with the CUDA and ONNX modules. -```bash -./scripts/build-unix.sh -``` +4. **Try it without hardware.** Open `config\MMConfig_demo.cfg` in ScopeOne. The application is `build\Release\ScopeOne.exe`. + +5. **Build again after a change** with the same command. The options are: + + | Option | Effect | + |---|---| + | `--run` | Start ScopeOne after the build | + | `--target core`, `gui` or `drivers` | Build one part | + | `--configure` | Configure again, for new source files or a newly installed CUDA | + | `--clean` | Discard the build directories and the Core install and build from scratch | + | `--package` | Build the installer and zip, named `-gpu` when Core was built with CUDA | + | `--qt ` | Use an installed Qt, see [Qt](#qt) | + | `--yes` | Accept the vcpkg download without asking | + +### Linux and macOS, step by step + +macOS support is experimental. + +1. **Install the build tools.** + + Linux (Debian, Ubuntu): + + ```bash + sudo apt install \ + build-essential cmake autoconf automake libtool autoconf-archive \ + pkg-config ninja-build curl zip unzip libboost-all-dev + sudo apt install --no-upgrade \ + libegl-dev libopengl-dev libx11-xcb-dev libxrender-dev \ + libxcb-cursor-dev libxcb-icccm4-dev libxcb-util-dev libxcb-keysyms1-dev \ + libxcb-randr0-dev libxcb-sync-dev libxcb-xinput-dev libxcb-glx0-dev \ + libxkbcommon-x11-dev + ``` + + The second command installs the X11 and OpenGL development files that vcpkg's Qt needs, and `--no-upgrade` keeps the installed Mesa drivers. + + A Qt passed with `--qt` needs the Qt Serial Port module, which the serial driver links. + + macOS: + + ```bash + xcode-select --install + brew install \ + cmake autoconf automake libtool autoconf-archive \ + pkg-config ninja boost + ``` -If vcpkg is missing, the script offers to download it into `$HOME/vcpkg` or a folder you type, and `--yes` takes the default folder without asking. It then builds Micro-Manager's core with the DemoCamera and Utilities adapters, ScopeOneCore, the plugins and the GUI. Set `JOBS` to limit parallel jobs and `BUILD_TYPE` to change the CMake build type (default `Release`). Pass `--clean` to discard the previous build directories. + A Qt passed with `--qt` needs the Qt Serial Port module, which the serial driver links. -The executable is `build/ScopeOne`, and `config/MMConfig_demo.cfg` runs with the copied demo adapters. It loads Qt and OpenCV from `vcpkg_installed//lib`, so run it from the build tree. +2. **Clone ScopeOne.** + + ```bash + git clone --recurse-submodules https://github.com/Experimental-Microscopy-Lab/ScopeOne.git + cd ScopeOne + ``` + +3. **Build and start it.** + + ```bash + ./scripts/build.sh --run + ``` + + The script checks the build tools, offers to download vcpkg into `$HOME/vcpkg` or a folder you type (`--yes` takes the default), and builds Micro-Manager's core with the DemoCamera and Utilities adapters, ScopeOneCore, the drivers and the GUI. + + The first build takes long, see [Build times](#build-times). + +4. **Try it without hardware.** The application is `build/ScopeOne`. Run it from the build tree and open `config/MMConfig_demo.cfg`. + +5. **Build again after a change** with the same command. `--clean` discards the build directories and the Core install, `--run` starts ScopeOne afterwards, `JOBS` limits the parallel jobs and `BUILD_TYPE` sets the CMake build type (default `Release`). + +### Drivers and processing modules + +ScopeOne has two public extension points, drivers and Python processing modules, and both run outside the ScopeOne process. Drivers are loaded from `drivers` by `ScopeOne_DriverHost`, one process per device, and Python modules from `processing/python`. The CUDA and ONNX processing modules are part of Core. Core builds the CUDA modules when it finds nvcc, and ONNX inference always, with the GPU package of ONNX Runtime when CUDA is built and the CPU package otherwise. `-DSCOPEONE_ENABLE_CUDA=OFF` builds the standard Core. Micro-Manager remains the built-in camera provider and loads its device adapters from `.cfg` files. [drivers/README.md](drivers/README.md) explains how to write a driver and [ScopeOneCore/python/scopeone/README.md](ScopeOneCore/python/scopeone/README.md#python-processing-modules) how to write a Python processing module. Python 3.14 is needed only for the Python package and Python processing modules. + +### Build times + +The first build is the long one. vcpkg compiles Qt, OpenCV and their dependencies from source, about 160 CPU minutes, 11 minutes on a 48 core Linux machine, and Qt is the largest part of it. An installed Qt (see [Qt](#qt)) leaves most of it out. vcpkg keeps the compiled packages in its binary cache, so this happens once per machine, and builds after a change take seconds. + +The first build without the cache, per vcpkg package, on the 48 core Linux machine: + +| Package | Time | +|---|---| +| qtbase | 5.2 min | +| opencv4 | 2.2 min | +| qtsvg | 59 s | +| harfbuzz | 46 s | +| 33 others | under 25 s each | +| All 37 packages | 11 min 23 s | + +A fresh clone with the binary cache filled, on the same machine, about 5 minutes in all: + +| Step | Time | +|---|---| +| Clone Micro-Manager | 71 s | +| Configure Core: restore the 37 packages from the cache and download ONNX Runtime | 2.6 min | +| Build Core | 28 s | +| Configure and build the drivers | 11 s | +| Configure and build the GUI | 27 s | + +Builds after that: + +| Change | Time | +|---|---| +| Nothing changed | under 1 s | +| One GUI file | 8 s | +| One Core file | 5 s | ## 🤖 Automation and AI Agents -The desktop app exposes a language-neutral local control API and shared-memory frame channel. An AI agent does not run inside ScopeOne or depend on Python. A tool adapter can discover supported operation groups with the `capabilities` request, read a structured observation with `state_snapshot`, and invoke the exposed camera, stage, mosaic, processing, image analysis, experiment, recording, layer, and markup operations. Requests may carry an ID that is echoed by the app for correlation. Recording save operations use `ome-tiff` by default and also accept `ome-zarr`, `tiff` and `binary`. +The desktop app exposes a language-neutral local control API and shared-memory frame channel. A tool adapter can discover supported operation groups with the `capabilities` request, read a structured observation with `state_snapshot`, and invoke the exposed camera, stage, mosaic, processing, image analysis, experiment, recording, layer, and markup operations. Requests may carry an ID that is echoed by the app for correlation. Recording save operations use `ome-tiff` by default and also accept `ome-zarr`, `tiff` and `binary`. The API reports which operations mutate hardware, write files, remove state, or may run for a long time. An agent adapter should request user confirmation before those operations and verify the result with the returned read-back value, experiment status, or a new state snapshot. The Python package is one optional client implementation. See the [Python client and Local API protocol guide](ScopeOneCore/python/scopeone/README.md) for protocol details and runnable examples. ### MCP adapter -`ScopeOneMcpServer` is a standalone C++ MCP server included with ScopeOne. It uses MCP protocol version `2025-06-18` over standard input and output and forwards validated tool calls to the running desktop app through the Local API. It does not embed a model, open a network port, or depend on Python. +`ScopeOneMcpServer` is a standalone C++ MCP server included with ScopeOne. It uses MCP protocol version `2025-06-18` over standard input and output and forwards validated tool calls to the running desktop app through the Local API. #### Claude Code plugin @@ -177,7 +267,7 @@ Install ScopeOne first, then run these commands inside Claude Code: /reload-plugins ``` -When prompted, select `ScopeOneMcpServer.exe` from the same directory as `ScopeOne.exe`. Start ScopeOne before asking Claude to inspect or control it. The plugin supplies the MCP configuration and agent operating guidance, so no Python installation or manual MCP server launch is required. +When prompted, select `ScopeOneMcpServer.exe` from the same directory as `ScopeOne.exe`. Start ScopeOne before asking Claude to inspect or control it. The plugin supplies the MCP configuration and the agent guidance. #### Other MCP hosts @@ -190,9 +280,9 @@ To use it: Use `scopeone` as the server name, `stdio` as the transport, the absolute path to `ScopeOneMcpServer.exe` as the command, and no command-line arguments. The exact configuration syntax depends on the agent host. -The MCP tool set mirrors the Local API operation catalog, including system state, configuration, preview layers, independent image windows, automatic display levels, source alignment, markups, device properties, exposure, ROI, stages, stage mosaics, processing, experiments, recording sessions, frame transfer, and analysis. Agents can list, open, activate, process, save, and close independent image windows, read the current frame of any image layer, monitor live acquisition and writer progress, and optionally export or display particle masks. ScopeOne remains the authority for parameter validation and hardware read-back, and MCP tool calls are visible in the desktop UI through the same application state used by manual controls. +The MCP tool set mirrors the Local API operation catalog, including system state, configuration, preview layers, independent image windows, automatic display levels, source alignment, markups, device properties, exposure, ROI, stages, stage mosaics, processing, experiments, recording sessions, frame transfer, and analysis. Agents can list, open, activate, process, save, and close independent image windows, read the current frame of any image layer, monitor live acquisition and writer progress, and optionally export or display particle masks. MCP tool calls are visible in the desktop UI through the same application state used by manual controls. -Configuration loading and unloading report an explicit lifecycle state through the Local API and MCP. A configuration with non-camera initialization warnings is reported as `partially_loaded` with failed device labels; camera backend startup failures are cleaned up and reported as errors. During `loading` or `unloading`, hardware mutations are rejected until the operation finishes. +Configuration loading and unloading report an explicit lifecycle state through the Local API and MCP. A configuration with non-camera initialization warnings is reported as `partially_loaded` with failed device labels; cameras that fail to start are cleaned up and reported as errors. During `loading` or `unloading`, hardware mutations are rejected until the operation finishes. ## 🔬 Tested Devices @@ -200,7 +290,7 @@ Configuration loading and unloading report an explicit lifecycle state through t - Hamamatsu C13440 - Andor 897D -The current validation list is still short, but the codebase has been cleaned to remove early hard-coded device assumptions. In principle, ScopeOne should follow Micro-Manager device compatibility. +Other devices work through the same Micro-Manager device adapters. ## 🖥️ Tested System Configurations @@ -209,4 +299,5 @@ The current validation list is still short, but the codebase has been cleaned to - Fedora Linux 44 (Workstation Edition), Intel(R) Core(TM) i7-7700, 32 GB RAM - macOS 26.5.2, Apple M1 Pro, 16 GB RAM -We build and test ScopeOne on the above machines, which are comparatively older and weaker than many typical optical lab computers. However, ScopeOne still provides smooth real-time preview and processing on them. + +ScopeOne is built and tested on the above machines, which are comparatively older and weaker than many typical optical lab computers. However, ScopeOne still provides smooth real-time preview and processing on them, as an example, with a Hamamatsu C11440 camera at 2048 × 2048 and 100 fps, the live preview shows the overshoot of a PI M-112.1DG stage move: the stage passes the target and moves back. We have not seen this in the live preview of other camera control software. diff --git a/ScopeOneCore/CMakeLists.txt b/ScopeOneCore/CMakeLists.txt index 71330e3..7172c04 100644 --- a/ScopeOneCore/CMakeLists.txt +++ b/ScopeOneCore/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.23) include("${CMAKE_CURRENT_LIST_DIR}/cmake/ScopeOneVersion.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cmake/ScopeOneQt.cmake") scopeone_resolve_version(SCOPEONE_VERSION "${CMAKE_CURRENT_LIST_DIR}/..") project(ScopeOneCore VERSION "${SCOPEONE_VERSION}" LANGUAGES CXX) @@ -16,7 +17,8 @@ set(MMCORE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/mmCoreAndDevices") set(MMCORE_INCLUDE_DIR "${MMCORE_DIR}/MMCore") set(MMDEVICE_INCLUDE_DIR "${MMCORE_DIR}/MMDevice") -find_package(Qt6 COMPONENTS Core Gui Network Concurrent REQUIRED) +find_package(Qt6 ${SCOPEONE_QT_MINIMUM_VERSION} COMPONENTS Core Gui Network Concurrent REQUIRED) +message(STATUS "Using Qt ${Qt6_VERSION} from ${Qt6_DIR}") find_package(OpenCV CONFIG REQUIRED COMPONENTS core imgproc imgcodecs) set(SCOPEWRITER_BUILD_TESTS OFF) @@ -67,124 +69,59 @@ function(scopeone_add_runtime_copy_commands target destination) endforeach () endfunction() -set(CORE_SOURCES - src/ExperimentDocument.cpp - src/AcquisitionEngine.cpp - src/DriverHostProviderProxy.cpp - src/DaqDeviceManager.cpp - src/HardwareProvider.cpp - src/PluginManifest.cpp - src/HardwareRuntime.cpp - src/MicroManagerProvider.cpp - src/SimulatorProvider.cpp - src/ImageOps.cpp - src/ImageSceneModel.cpp - src/MMCoreManager.cpp - src/FrameBufferUtils.cpp - src/ParticleAnalysis.cpp - src/StageMosaicManager.cpp - src/ImageProcessingFramework.cpp - src/ProcessingPipeline.cpp - src/ToolTask.cpp - src/ToolFrameStream.cpp - src/ToolPlugin.cpp - src/ProcessingModuleRegistry.cpp - src/SpatiotemporalBinningModule.cpp - src/GaussianBlurModule.cpp - src/ImageOperationModules.cpp - src/FFTModule.cpp - src/FrequencyDomainFilterModule.cpp - src/MaskModule.cpp - src/IFFTModule.cpp - src/BackgroundCalibrationModule.cpp - src/DifferentialRollingModule.cpp - src/MDAManager.cpp - src/RecordingManager.cpp - src/CameraBackend.cpp - src/CameraManager.cpp - src/NativeCameraBackend.cpp - src/DriverHostCameraBackend.cpp - src/ScopeOneCore.cpp - src/ScanImageAssembler.cpp - src/SignalSourceManager.cpp -) +# Every source of Core is picked up from its folder, so a new file, such as a processing module that +# registers itself, needs no change here. DriverHostMain.cpp belongs to ScopeOne_DriverHost. +file(GLOB CORE_SOURCES CONFIGURE_DEPENDS src/*.cpp) +list(REMOVE_ITEM CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/DriverHostMain.cpp") +file(GLOB CORE_HEADERS CONFIGURE_DEPENDS internal/*.h include/scopeone/*.h) -set(CORE_HEADERS - include/scopeone/ExperimentDocument.h - include/scopeone/CameraProvider.h - include/scopeone/DaqDevice.h - include/scopeone/DriverHostProviderPlugin.h - include/scopeone/HardwareCapabilities.h - include/scopeone/HardwareProvider.h - include/scopeone/HardwareTypes.h - include/scopeone/ImageFrame.h - include/scopeone/PluginManifest.h - include/scopeone/PluginSDK.h - include/scopeone/ProcessingPlugin.h - include/scopeone/ScanImageAssembler.h - include/scopeone/scopeone_sdk_export.h - include/scopeone/SharedFrame.h - include/scopeone/SignalSource.h - include/scopeone/ToolFrameStream.h - include/scopeone/ToolPlugin.h - include/scopeone/ToolTask.h - internal/AcquisitionEngine.h - internal/CameraRuntimeControl.h - include/scopeone/SimulatorProvider.h - include/scopeone/ImageOps.h - include/scopeone/ImageSceneModel.h - internal/HardwareRuntime.h - internal/MicroManagerProvider.h - internal/MMCoreManager.h - internal/FrameBufferUtils.h - internal/ParticleAnalysis.h - internal/StageMosaicManager.h - internal/ImageProcessingFramework.h - internal/ProcessingModule.h - internal/ProcessingModuleRegistry.h - include/scopeone/ProcessingPipeline.h - internal/DriverHostProtocol.h - internal/SharedFrameRing.h - internal/DriverHostProviderProxy.h - internal/DaqDeviceManager.h - internal/SignalSourceManager.h - internal/SpatiotemporalBinningModule.h - internal/GaussianBlurModule.h - internal/ImageOperationModules.h - internal/FFTModule.h - internal/FrequencyDomainFilterModule.h - internal/MaskModule.h - internal/IFFTModule.h - internal/BackgroundCalibrationModule.h - internal/DifferentialRollingModule.h - internal/MDAManager.h - internal/RecordingManager.h - internal/CameraBackend.h - internal/CameraManager.h - include/scopeone/scopeone_core_export.h - include/scopeone/RecordingSession.h - include/scopeone/ScopeOneCore.h +# The driver SDK: the only headers and the only library a driver sees. It is a library of its +# own so a driver that reaches for anything else of Core does not compile or link. +set(SDK_HEADERS + sdk/include/scopeone/Camera.h + sdk/include/scopeone/DaqDevice.h + sdk/include/scopeone/Driver.h + sdk/include/scopeone/HardwareCapabilities.h + sdk/include/scopeone/DriverSDK.h + sdk/include/scopeone/Device.h + sdk/include/scopeone/HardwareTypes.h + sdk/include/scopeone/ImageFrame.h + sdk/include/scopeone/scopeone_sdk_export.h + sdk/include/scopeone/SignalSource.h +) +add_library(ScopeOneDriverSDK SHARED + sdk/src/Device.cpp + sdk/src/SignalSource.cpp + ${SDK_HEADERS} +) +add_library(scopeone::DriverSDK ALIAS ScopeOneDriverSDK) +set_target_properties(ScopeOneDriverSDK PROPERTIES EXPORT_NAME DriverSDK) +target_link_libraries(ScopeOneDriverSDK PUBLIC Qt::Core) +target_compile_definitions(ScopeOneDriverSDK PRIVATE SCOPEONE_SDK_EXPORTS) +target_include_directories(ScopeOneDriverSDK PUBLIC + $ + $ ) add_library(ScopeOneCore SHARED ${CORE_SOURCES} ${CORE_HEADERS}) add_library(scopeone::ScopeOneCore ALIAS ScopeOneCore) -add_library(ScopeOnePluginSDK INTERFACE) -add_library(scopeone::PluginSDK ALIAS ScopeOnePluginSDK) -if (UNIX AND NOT APPLE) - set_target_properties(ScopeWriter ScopeOneCore PROPERTIES - BUILD_RPATH "$ORIGIN" - INSTALL_RPATH "$ORIGIN" +# macOS has no $ORIGIN. Without an @loader_path entry the installed libraries and DriverHost had +# no LC_RPATH at all, so dyld could not resolve @rpath and the host died before loading a camera. +if (APPLE) + set(SCOPEONE_RPATH_ORIGIN "@loader_path") +elseif (UNIX) + set(SCOPEONE_RPATH_ORIGIN "$ORIGIN") +endif () +if (UNIX) + set_target_properties(ScopeWriter ScopeOneCore ScopeOneDriverSDK PROPERTIES + BUILD_RPATH "${SCOPEONE_RPATH_ORIGIN}" + INSTALL_RPATH "${SCOPEONE_RPATH_ORIGIN}" INSTALL_RPATH_USE_LINK_PATH TRUE ) endif () -set_target_properties(ScopeOnePluginSDK PROPERTIES EXPORT_NAME PluginSDK) -target_link_libraries(ScopeOnePluginSDK INTERFACE ScopeOneCore Qt::Core Qt::Gui) -target_include_directories(ScopeOnePluginSDK INTERFACE - $ - $ -) target_link_libraries(ScopeOneCore PUBLIC + ScopeOneDriverSDK Qt::Core Qt::Gui PRIVATE @@ -201,6 +138,199 @@ target_compile_definitions(ScopeOneCore PRIVATE SCOPEONE_CORE_EXPORTS SCOPEONE_CORE_VERSION_STRING="${PROJECT_VERSION}" ) + +# The CUDA processing modules are part of Core when nvcc is found, and turning them off builds the +# standard Core. ONNX inference is always built, from the ONNX Runtime package that matches CUDA. +set(_with_cuda OFF) +set(_with_inference OFF) +# Why a module that is turned on was left out, for the summary of the build scripts +set(_cuda_reason "") +set(_inference_reason "") +option(SCOPEONE_ENABLE_CUDA "Build the CUDA processing modules into Core when nvcc is available" ON) +if (SCOPEONE_ENABLE_CUDA) + # An nvcc that was uninstalled since the last configure is looked up again + if (SCOPEONE_CUDA_NVCC_EXECUTABLE AND NOT EXISTS "${SCOPEONE_CUDA_NVCC_EXECUTABLE}") + unset(SCOPEONE_CUDA_NVCC_EXECUTABLE CACHE) + unset(CMAKE_CUDA_COMPILER CACHE) + endif () + find_program(SCOPEONE_CUDA_NVCC_EXECUTABLE nvcc) + if (NOT SCOPEONE_CUDA_NVCC_EXECUTABLE) + set(_cuda_reason "nvcc was not found on the path") + message(STATUS "${_cuda_reason}; building Core without CUDA") + endif () +else () + unset(SCOPEONE_CUDA_NVCC_EXECUTABLE CACHE) + set(_cuda_reason "turned off with SCOPEONE_ENABLE_CUDA") +endif () +if (SCOPEONE_CUDA_NVCC_EXECUTABLE) + # A CUDA that cannot build here, such as one installed before Visual Studio and so without its + # MSBuild integration, or one too old for the MSVC version, left the configure failing. + # check_language tries it in a separate project first, and CUDA is left out when it fails. + if (NOT CMAKE_CUDA_COMPILER) + set(ENV{CUDACXX} "${SCOPEONE_CUDA_NVCC_EXECUTABLE}") + include(CheckLanguage) + check_language(CUDA) + endif () + if (CMAKE_CUDA_COMPILER) + get_filename_component(_cuda_toolkit_root "${CMAKE_CUDA_COMPILER}" DIRECTORY) + get_filename_component(_cuda_toolkit_root "${_cuda_toolkit_root}" DIRECTORY) + set(CUDAToolkit_ROOT "${_cuda_toolkit_root}" CACHE PATH + "CUDA toolkit selected by the compiler" FORCE) + enable_language(CUDA) + find_package(CUDAToolkit) + if (NOT TARGET CUDA::cufft) + set(_cuda_reason "the CUDA toolkit at ${_cuda_toolkit_root} has no cuFFT") + message(STATUS "${_cuda_reason}; building Core without CUDA") + endif () + else () + set(_cuda_reason "nvcc at ${SCOPEONE_CUDA_NVCC_EXECUTABLE} cannot build with this compiler, often a CUDA installed before Visual Studio or too old for it") + message(STATUS "${_cuda_reason}; building Core without CUDA") + endif () +endif () +if (SCOPEONE_CUDA_NVCC_EXECUTABLE AND TARGET CUDA::cufft) + set(SCOPEONE_CUDA_ARCHITECTURES "50;75;80;86;89" CACHE STRING "Target CUDA architectures") + file(GLOB _cuda_sources CONFIGURE_DEPENDS src/cuda/*.cpp internal/cuda/*.h) + file(GLOB _cuda_kernels CONFIGURE_DEPENDS src/cuda/*.cu) + target_sources(ScopeOneCore PRIVATE ${_cuda_sources} ${_cuda_kernels}) + set_source_files_properties(${_cuda_kernels} PROPERTIES SKIP_PRECOMPILE_HEADERS ON) + set_target_properties(ScopeOneCore PROPERTIES + CUDA_ARCHITECTURES "${SCOPEONE_CUDA_ARCHITECTURES}" + CUDA_SEPARABLE_COMPILATION OFF + ) + target_link_libraries(ScopeOneCore PRIVATE CUDA::cudart CUDA::cufft) + set(_with_cuda ON) + if (WIN32) + file(GLOB _cuda_runtime_dlls + "${CUDAToolkit_BIN_DIR}/cudart64_*.dll" + "${CUDAToolkit_BIN_DIR}/cufft64_*.dll" + ) + list(APPEND SCOPEONE_RUNTIME_DLLS ${_cuda_runtime_dlls}) + endif () +endif () + +# ONNX Runtime is the official prebuilt package from the ONNX Runtime releases on GitHub, +# downloaded into external on the first configure. Core built with CUDA takes the GPU package and +# Core without it the CPU package, so CUDA alone decides between the GPU and the standard build. +# ONNXRUNTIME_ROOT names another SDK instead. +set(SCOPEONE_ONNXRUNTIME_VERSION 1.30.0) +set(ONNXRUNTIME_ROOT "" CACHE PATH "ONNX Runtime SDK root; empty selects the official package in external") +set(_ort_package "") +if (WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64") + if (_with_cuda) + set(_ort_package "onnxruntime-win-x64-gpu_cuda12-${SCOPEONE_ONNXRUNTIME_VERSION}.zip") + set(_ort_sha256 d4667ea48eb0a10bc9b96b838f7b8975a6bf18de3bc5edd403a22e15c1458b23) + else () + set(_ort_package "onnxruntime-win-x64-${SCOPEONE_ONNXRUNTIME_VERSION}.zip") + set(_ort_sha256 c6ba983baf5681af108599675d2a89c2d145512d02de28aed0bff177cd0ba949) + endif () +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") + if (_with_cuda) + set(_ort_package "onnxruntime-linux-x64-gpu_cuda12-${SCOPEONE_ONNXRUNTIME_VERSION}.tgz") + set(_ort_sha256 f9886932ee7bb0b4d3fcab736a392d4ff5efaa0672b47f19f0cec03437cf64f1) + else () + set(_ort_package "onnxruntime-linux-x64-${SCOPEONE_ONNXRUNTIME_VERSION}.tgz") + set(_ort_sha256 a5ed5a3cac51fbb2e90da632ae43d19212faaa20e76484e62bcb7c23ddb3b3fd) + endif () +elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") + set(_ort_package "onnxruntime-linux-aarch64-${SCOPEONE_ONNXRUNTIME_VERSION}.tgz") + set(_ort_sha256 e16a27a8ed330bbc698df7330b0cf56e722f354e3bcc92118682c74ef3c3e3da) +elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") + # The macOS package has only the CPU provider + set(_ort_package "onnxruntime-osx-arm64-${SCOPEONE_ONNXRUNTIME_VERSION}.tgz") + set(_ort_sha256 6ebb5062a934537c352937821f9fe9718e7de1a2db1122a93dd363ffd53a7012) +endif () + +set(_ort_download_error "") +if (ONNXRUNTIME_ROOT) + set(_ort_root "${ONNXRUNTIME_ROOT}") +elseif (_ort_package) + string(REGEX REPLACE "\\.(zip|tgz)$" "" _ort_name "${_ort_package}") + set(_ort_root "${CMAKE_CURRENT_SOURCE_DIR}/external/${_ort_name}") + set(_ort_url "https://github.com/microsoft/onnxruntime/releases/download/v${SCOPEONE_ONNXRUNTIME_VERSION}/${_ort_package}") + if (NOT EXISTS "${_ort_root}/include") + message(STATUS "Downloading ${_ort_url}") + set(_ort_archive "${CMAKE_CURRENT_BINARY_DIR}/${_ort_package}") + # EXPECTED_HASH turned a failed download into a configure error, so the hash is + # checked after it. Without the network Core is built without ONNX inference, and the + # next configure tries again. + file(DOWNLOAD "${_ort_url}" "${_ort_archive}" + SHOW_PROGRESS + STATUS _ort_download + ) + list(GET _ort_download 0 _ort_download_code) + list(GET _ort_download 1 _ort_download_error) + if (_ort_download_code EQUAL 0) + file(SHA256 "${_ort_archive}" _ort_actual_sha256) + if (_ort_actual_sha256 STREQUAL _ort_sha256) + set(_ort_download_error "") + file(ARCHIVE_EXTRACT INPUT "${_ort_archive}" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/external") + else () + set(_ort_download_error "SHA256 mismatch") + endif () + endif () + file(REMOVE "${_ort_archive}") + endif () +else () + set(_ort_root "") +endif () + +# The found paths are cached, so a root that changed, such as the GPU package taking over +# once CUDA is found, kept linking the package of the earlier configure +if (NOT "${SCOPEONE_ONNXRUNTIME_ROOT_USED}" STREQUAL "${_ort_root}") + unset(ONNXRUNTIME_INCLUDE_DIR CACHE) + unset(ONNXRUNTIME_LIBRARY CACHE) +endif () +set(SCOPEONE_ONNXRUNTIME_ROOT_USED "${_ort_root}" CACHE INTERNAL "") +set(ONNXRUNTIME_ROOT "${_ort_root}") +find_path(ONNXRUNTIME_INCLUDE_DIR + NAMES onnxruntime_cxx_api.h + PATHS "${ONNXRUNTIME_ROOT}/include" + NO_DEFAULT_PATH +) +find_library(ONNXRUNTIME_LIBRARY + NAMES onnxruntime + PATHS "${ONNXRUNTIME_ROOT}/lib" + NO_DEFAULT_PATH +) +if (ONNXRUNTIME_INCLUDE_DIR AND ONNXRUNTIME_LIBRARY) + file(GLOB _inference_sources CONFIGURE_DEPENDS src/inference/*.cpp internal/inference/*.h) + target_sources(ScopeOneCore PRIVATE ${_inference_sources}) + target_include_directories(ScopeOneCore PRIVATE "${ONNXRUNTIME_INCLUDE_DIR}") + target_link_libraries(ScopeOneCore PRIVATE "${ONNXRUNTIME_LIBRARY}") + set(_with_inference ON) + if (WIN32) + file(GLOB _onnxruntime_dlls + "${ONNXRUNTIME_ROOT}/bin/onnxruntime*.dll" + "${ONNXRUNTIME_ROOT}/lib/onnxruntime*.dll" + ) + if (NOT _onnxruntime_dlls) + message(FATAL_ERROR "No ONNX Runtime DLLs found under ${ONNXRUNTIME_ROOT}") + endif () + list(APPEND SCOPEONE_RUNTIME_DLLS ${_onnxruntime_dlls}) + else () + # The installed Core resolves its libraries beside itself. Left in external, ONNX Runtime + # was not on its runpath and the GUI failed to link against the installed Core. + file(GLOB _onnxruntime_libs + "${ONNXRUNTIME_ROOT}/lib/libonnxruntime*.so*" + "${ONNXRUNTIME_ROOT}/lib/libonnxruntime*.dylib" + ) + install(FILES ${_onnxruntime_libs} DESTINATION "${CMAKE_INSTALL_LIBDIR}") + endif () +elseif (NOT ONNXRUNTIME_ROOT) + set(_inference_reason "no official ONNX Runtime package for ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}; set ONNXRUNTIME_ROOT") + message(STATUS "${_inference_reason}; building Core without ONNX inference") +elseif (_ort_download_error) + set(_inference_reason "downloading ${_ort_url} failed (${_ort_download_error}); extract it into ${CMAKE_CURRENT_SOURCE_DIR}/external") + message(STATUS "${_inference_reason}; building Core without ONNX inference") +else () + set(_inference_reason "ONNX Runtime was not found under ${ONNXRUNTIME_ROOT}") + message(STATUS "${_inference_reason}; building Core without ONNX inference") +endif () +# What this configure built in, for the build scripts to report +set(SCOPEONE_BUILT_WITH_CUDA "${_with_cuda}" CACHE INTERNAL "") +set(SCOPEONE_BUILT_WITH_INFERENCE "${_with_inference}" CACHE INTERNAL "") +set(SCOPEONE_CUDA_SKIP_REASON "${_cuda_reason}" CACHE INTERNAL "") +set(SCOPEONE_INFERENCE_SKIP_REASON "${_inference_reason}" CACHE INTERNAL "") target_include_directories(ScopeOneCore PUBLIC $ @@ -240,6 +370,11 @@ target_precompile_headers(ScopeOneCore PRIVATE ) target_link_directories(ScopeOneCore PRIVATE ${MMCORE_BIN_DIR}) +# Keeps the symbols of the static libraries in Core, MMCore among them, out of its exports. Linux +# exported them all, so DriverHost had linked MMCore through Core without noticing. +if (UNIX AND NOT APPLE) + target_link_options(ScopeOneCore PRIVATE "LINKER:--exclude-libs,ALL") +endif () scopeone_add_runtime_copy_commands(ScopeOneCore $) add_custom_command(TARGET ScopeOneCore POST_BUILD @@ -248,23 +383,33 @@ add_custom_command(TARGET ScopeOneCore POST_BUILD $ ) +# DriverHost does not link Core, so a driver process loads only the SDK, Qt Core and Network and +# MMCore. It builds the few Core sources it needs itself. add_executable(ScopeOne_DriverHost src/DriverHostMain.cpp + src/HardwareStreamCodec.cpp + src/DriverManifest.cpp + src/MicroManagerCamera.cpp + src/StreamRing.cpp ) -if (UNIX AND NOT APPLE) +if (UNIX) set_target_properties(ScopeOne_DriverHost PROPERTIES - BUILD_RPATH "$ORIGIN" - INSTALL_RPATH "$ORIGIN/../lib;$ORIGIN" + BUILD_RPATH "${SCOPEONE_RPATH_ORIGIN}" + INSTALL_RPATH "${SCOPEONE_RPATH_ORIGIN}/../lib;${SCOPEONE_RPATH_ORIGIN}" INSTALL_RPATH_USE_LINK_PATH TRUE ) endif () target_link_libraries(ScopeOne_DriverHost - ScopeOneCore + ScopeOneDriverSDK MMCore Qt::Core Qt::Network ) -target_compile_definitions(ScopeOne_DriverHost PRIVATE MMDEVICE_CLIENT_BUILD) +target_compile_definitions(ScopeOne_DriverHost PRIVATE + MMDEVICE_CLIENT_BUILD + SCOPEONE_CORE_STATIC + SCOPEONE_CORE_VERSION_STRING="${PROJECT_VERSION}" +) target_include_directories(ScopeOne_DriverHost PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} @@ -275,28 +420,19 @@ target_link_directories(ScopeOne_DriverHost PRIVATE ${MMCORE_BIN_DIR}) scopeone_add_runtime_copy_commands(ScopeOne_DriverHost $) -# Fast Release build -# if (MSVC) -# target_compile_options(ScopeOneCore PRIVATE -# $<$:/MP> -# ) -# endif () - -# LTO Release build +# /MP compiles the sources of one project in parallel, which the Visual Studio generator does not, +# and Release builds use LTO. Only for C++, nvcc takes neither. if (MSVC) - target_compile_options(ScopeOneCore PRIVATE - $<$:/GL /fp:fast /arch:AVX2> - ) - target_link_options(ScopeOneCore PRIVATE - $<$:/LTCG> - ) - - target_compile_options(ScopeOne_DriverHost PRIVATE - $<$:/GL /fp:fast /arch:AVX2> - ) - target_link_options(ScopeOne_DriverHost PRIVATE - $<$:/LTCG> - ) + set(_cxx "$") + set(_release_cxx "$,${_cxx}>") + foreach (_target IN ITEMS ScopeOneCore ScopeOne_DriverHost) + target_compile_options(${_target} PRIVATE + "$<${_cxx}:/MP>" + "$<${_release_cxx}:/GL>" "$<${_release_cxx}:/fp:fast>" "$<${_release_cxx}:/arch:AVX2>" + ) + target_link_options(${_target} PRIVATE $<$:/LTCG>) + endforeach () + target_compile_options(ScopeOneDriverSDK PRIVATE /MP) endif () @@ -311,7 +447,7 @@ write_basic_package_version_file( COMPATIBILITY SameMajorVersion ) -install(TARGETS ScopeOneCore ScopeOnePluginSDK +install(TARGETS ScopeOneCore ScopeOneDriverSDK EXPORT ScopeOneCoreTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" @@ -325,6 +461,11 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" FILES_MATCHING PATTERN "*.h" ) +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/sdk/include/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sdk" + FILES_MATCHING + PATTERN "*.h" +) install(EXPORT ScopeOneCoreTargets FILE ScopeOneCoreTargets.cmake NAMESPACE scopeone:: @@ -333,7 +474,7 @@ install(EXPORT ScopeOneCoreTargets install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ScopeOneCoreConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/ScopeOneCoreConfigVersion.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ScopeOnePlugin.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ScopeOneDriver.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ScopeOneCore" ) diff --git a/ScopeOneCore/DRIVERHOST_PROTOCOL.md b/ScopeOneCore/DRIVERHOST_PROTOCOL.md new file mode 100644 index 0000000..dd7828c --- /dev/null +++ b/ScopeOneCore/DRIVERHOST_PROTOCOL.md @@ -0,0 +1,200 @@ +# DriverHost protocol + +ScopeOne talks to every driver, and to each camera of a Micro-Manager configuration with more +than one camera, through a `ScopeOne_DriverHost` process. This file describes what crosses that +process boundary: control messages on a local socket, camera frames +in shared memory, and the chunks of signal sources and DAQ devices in stream rings. Both ends are part of ScopeOne, so the protocol is internal and changes +with it; drivers are written against `scopeone::DriverSDK` instead. It is version +8, `kProtocolVersion` in `ScopeOneCore/internal/DriverHostProtocol.h`, which holds the names used +below. + +## Process + +ScopeOne starts one host for each driver and for each camera of a Micro-Manager configuration +with more than one camera: + +```text +ScopeOne_DriverHost --provider --driver --hostKey + --launcherPid [--device ] [--properties ] +ScopeOne_DriverHost --provider micro-manager --micromanagerCamera --hostKey + --launcherPid +``` + +`--device` names the device to create in the driver, the first of its `deviceNames()` by default, and `--properties` carries its pre-init properties. `--micromanagerCamera` carries +`cameraId`, `adapter`, `device`, `exposureMs`, and `preInitProperties` and `properties`, arrays of +`{"name", "value"}` objects. The host loads the camera on a core of its own, as two cameras of the +same model in one process would share the state of one vendor library. The host loads the +driver or the camera, creates the devices and listens on the local socket +`ScopeOne..ctrl`, where `` is the first 16 hexadecimal digits of the SHA-1 of the host +key, as a Unix socket path on macOS holds at most 104 characters (a named pipe on Windows, a Unix +domain socket elsewhere). ScopeOne connects to it, and the host exits when the +process `--launcherPid` is gone. + +## Messages + +Each message is a 4-byte little-endian length followed by that many bytes of compact UTF-8 JSON. +A message is at most 64 MiB, because a DAQ session carries its output waveforms. Every message is an object with + +| Field | Value | +|---|---| +| `kind` | `Request`, `Response` or `Event` | +| `version` | the protocol version | +| `type` | the command or event name | +| `requestId` | a decimal string, in requests and their responses | + +ScopeOne sends requests. The host answers each one with a response of the same `type` and +`requestId` that has `ok` and, when `ok` is false, `error`. Events come from the host at any time +and carry `providerId`. + +64-bit integers such as `requestId` and `frameIndex` are sent as decimal strings. + +## Describe and shutdown + +`Describe` returns `providerId`, `providerName`, `providerVersion`, `devices`, `signalSources` +and `daqDevices`. +`signalSources` and `daqDevices` hold the JSON form of `SignalSourceDescriptor` and +`DaqDeviceDescriptor`, written by `ScopeOneCore/src/HardwareStreamCodec.cpp`. Each device is an object with + +| Field | Value | +|---|---| +| `deviceId` | the id ScopeOne uses in requests | +| `providerDeviceId`, `hardwareId`, `deviceName` | the driver's own names | +| `deviceKind` | `Camera`, `XYStage`, `ZStage`, `Shutter`, `State`, `Hub`, `Serial`, `Generic`, ... | +| `deviceState` | the numeric `HardwareDeviceState` | +| `deviceProperties` | an object of fixed device information | +| `capabilities` | the capability names below that the device supports | +| `sharedMemoryKey` | cameras only, the key of the frame ring | +| `sequence` | cameras only, whether the camera takes a series of images in one sequence acquisition | + +A driver without peripherals describes one device with an empty `deviceId`, and a request without a +`deviceId` addresses that device. With several devices, ScopeOne names them in the order of `devices`: +the label of the `ScopeOneDevice` line for one device, and `