8000 Replace SlicerExecutionModel with a dcmqi-owned CLI generator by fedorov · Pull Request #569 · QIICR/dcmqi · GitHub
[go: up one dir, main page]

Skip to content

Replace SlicerExecutionModel with a dcmqi-owned CLI generator - #569

Open
fedorov wants to merge 11 commits into
masterfrom
remove-slicer-execution-model
Open

fedorov wants to merge 11 commits into
masterfrom
remove-slicer-execution-model

Conversation

@fedorov
@fedorov fedorov commented Nov 14, 2026 •
Copy link
Copy Markdown
Member

SlicerExecutionModel (SEM) is distributed under the 3D Slicer license. Debian does not consider that license DFSG-free (Slicer/SlicerExecutionModel#159). SEM is dcmqi's only dependency with this problem, so it is what keeps dcmqi out of Debian main.

This PR replaces the parts of SEM that dcmqi uses with code written for dcmqi. The applications' command-line interface does not change. The new code was written from the observed behavior of the dcmqi 1.5.7 binaries. Nothing was copied from SEM.

What changes

SEM piece Replacement
GenerateCLP (descriptor XML → <name>CLP.h) apps/GenerateCLP/dcmqiGenerateCLP.cxx, a build-time tool that needs only the C++ standard library. Code shared by all generated headers is in apps/GenerateCLP/dcmqiCLP.h.
SEM's bundled TCLAP Upstream TCLAP 1.2.5 headers (MIT), unmodified, in tclap/. -DTCLAP_INCLUDE_DIR=<dir> builds against a system copy instead, e.g. Debian's libtclap-dev.
SEMMacroBuildCLI CMake/dcmqiMacroBuildCLI.cmake and CMake/dcmqiCLIExecutableWrapper.cxx
  • Unchanged files. No application .cxx or .xml file changes. The existing tests are also unchanged.

  • Superbuild. The superbuild no longer builds SEM: CMakeExternals/SlicerExecutionModel.cmake is removed, and DCMQIConfig.cmake no longer sets SlicerExecutionModel_DIR.

  • Build targets. dcmqiMacroBuildCLI creates the same targets as SEMMacroBuildCLI did:

    • <name>Lib, with main renamed to ModuleEntryPoint, so the test drivers link as before
    • the <name> executable
    • the XML copied next to the executable
  • Slicer extension builds. The macro reads the SlicerExecutionModel_DEFAULT_CLI_* and SlicerExecutionModel_USE_UTF8 variables that 3D Slicer sets. A Slicer extension build should therefore place the CLIs where it does today.

    • Slicer turns off ITK's automatic IO factory registration. As SEMMacroBuildCLI did, the macro then builds each executable from Slicer's wrapper (SlicerExecutionModel_CLI_LIBRARY_WRAPPER_CXX), which calls itk::itkFactoryRegistration(). It also adds SlicerExecutionModel_EXTRA_INCLUDE_DIRECTORIES and SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES. The test drivers get the same include directories and libraries.
  • License notices. The packages now include doc/LICENSE.txt and, when the bundled TCLAP is used, doc/TCLAP-COPYING.txt, as TCLAP's MIT license requires. Slicer extension packaging is unchanged.

  • Standalone app builds removed. apps/seg, apps/paramaps and apps/sr can no longer be configured on their own against an installed dcmqi. That mode needed SEM from the installed package, and nothing builds it.

  • Cross-compiling. -DDCMQI_GENERATECLP_EXECUTABLE=<host dcmqiGenerateCLP> is passed through the superbuild to the inner build.

  • Strict generator. The generator accepts only the descriptor features dcmqi uses. It fails the build on anything else:

    • an unknown element or attribute
    • a missing, duplicate or reserved flag
    • a default that does not fit its parameter type

    Integer defaults are written to the generated code as plain decimal, so a default such as 010 cannot turn into an octal literal.

    A future XML edit therefore can't silently change behavior.

  • No Python or DCMTK. Python is not needed at build time or at runtime. The generator does not link DCMTK, so it also runs when DCMTK is built as shared libraries, as in Slicer extension builds on Windows.

  • Help layout. Upstream TCLAP wraps the usage block at 75 columns. dcmqiCLP.h keeps the one-argument-per-line layout of the current binaries.

Verification (macOS arm64)

  • Behavior against dcmqi 1.5.7. 251 invocations of the 7 applications were compared with the dcmqi 1.5.7 wheel binaries. They cover --help, --xml, --echo, short, long and combined flags, repeated flags, missing values, unknown flags, and invalid enum and integer values.
  • Tests. ctest passes 111 of 111. That includes 30 new tests:
    • 11 descriptors that the generator must reject
    • per application: the --xml output, and an unknown flag
    • invalid enum and integer values
    • comma-separated lists and short flags
  • Packaging. The CPack tarball has the same file list as the 1.5.7 release tarball. The executables keep the same rpath.
  • No SEM left. A configured superbuild has no SEM project. The binaries contain no SEM symbols and link only system libraries.

Not yet verified (why this is a draft)

  • CI: all builds pass on Linux (x64, arm64), macOS (arm64, x86_64) and Windows, with 124 of 124 tests on each.
  • A 3D Slicer extension build:
    • the CLIs read and write images, i.e. the ITK IO factories are registered. This is checked only with a stub project that uses Slicer's wrapper source with stand-in variables and a stand-in ITKFactoryRegistration library.
    • the CLIs land in cli-modules
    • Slicer discovers the modules
    • the QuantitativeReporting SEG and SR round trip works
  • Building against a system TCLAP. Only the vendored 1.2.5 has been tested.

Notes for reviewers

  • Windows CI cache. The Windows dependency cache key hashes CMakeExternals/*.cmake. Removing the SEM file therefore causes one dependency rebuild on Windows.
  • ITK.cmake left as is. CMakeExternals/ITK.cmake still sets KWSYS_USE_MD5, with a comment saying SEM requires it. The Linux and macOS cache keys hash that file, so the file is left alone here.
  • Commit message count. The message of the second commit says "753 invocations". The correct number is 251; 753 is the number of recorded files (stdout, stderr and exit code per invocation).

🤖 Generated with Claude Code

@fedorov
fedorov marked this pull request as ready for review November 16, 2026 17:05
@claude claude Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing Slicer ITK factory initialization breaks conversion I/O, while missing factory linkage and include paths prevent Slicer test drivers from building.

6 open issues
What changed in this PR

This PR replaces SlicerExecutionModel with dcmqi-owned command-line generation and build support, removing a licensing obstacle to Debian main while aiming to preserve existing application interfaces.

Changes:

  • Adds a strict XML-to-C++ generator, shared parsing helpers, and CLI compatibility tests.
  • Replaces SEM build integration with dcmqi CMake support and upstream MIT-licensed TCLAP headers.
  • Documents third-party licensing and adjusts CI configuration.
File Description
tclap/​tclap/​ZshCompletionOutput.h Adds upstream shell-completion output.
tclap/​tclap/​XorHandler.h Adds mutually exclusive argument handling.
tclap/​tclap/​Visitor.h Adds the argument visitor interface.
tclap/​tclap/​VersionVisitor.h Adds version-output handling.
tclap/​tclap/​ValuesConstraint.h Adds allowed-value validation.
tclap/​tclap/​ValueArg.h Adds single-value argument parsing.
tclap/​tclap/​UnlabeledValueArg.h Adds positional argument parsing.
tclap/​tclap/​UnlabeledMultiArg.h Adds repeated positional arguments.
tclap/​tclap/​SwitchArg.h Adds boolean switch parsing.
tclap/​tclap/​StdOutput.h Adds standard help and error output.
tclap/​tclap/​StandardTraits.h Adds string parsing traits.
tclap/​tclap/​sstream.h Adds stream compatibility support.
tclap/​tclap/​OptionalUnlabeledTracker.h Adds positional argument ordering checks.
tclap/​tclap/​MultiSwitchArg.h Adds counting switches.
tclap/​tclap/​MultiArg.h Adds repeated value arguments.
tclap/​tclap/​IgnoreRestVisitor.h Adds end-of-options handling.
tclap/​tclap/​HelpVisitor.h Adds help-output handling.
tclap/​tclap/​DocBookOutput.h Adds upstream DocBook output.
tclap/​tclap/​Constraint.h Adds the value constraint interface.
tclap/​tclap/​CmdLineOutput.h Adds the parser output interface.
tclap/​tclap/​CmdLineInterface.h Adds the command-line parser interface.
tclap/​tclap/​CmdLine.h Adds the upstream parser implementation.
tclap/​tclap/​ArgTraits.h Adds argument type traits.
tclap/​tclap/​ArgException.h Adds parsing exception types.
tclap/​tclap/​Arg.h Adds shared argument functionality.
tclap/​README.md Documents provenance and system-header selection.
tclap/​COPYING Includes TCLAP’s MIT license.
SuperBuild.cmake Removes SEM from dependencies.
README.md Documents bundled third-party licenses.
CMakeLists.txt Configures TCLAP and removes SEM package settings.
CMakeExternals/​SlicerExecutionModel.cmake Removes the SEM external project.
CMake/​dcmqiTest.cmake Updates test-driver dependencies and include precedence.
CMake/​dcmqiMacroBuildCLI.cmake Adds CLI generation, build, and installation support.
CMake/​DCMQIConfig.cmake.in Removes the exported SEM directory.
CMake/​dcmqiCLIUTF8.manifest Adds Windows UTF-8 process configuration.
CMake/​dcmqiCLIExecutableWrapper.cxx Adds the executable entry-point wrapper.
apps/​sr/​CMakeLists.txt Switches SR applications to the new macro.
apps/​seg/​CMakeLists.txt Switches SEG applications to the new macro.
apps/​paramaps/​CMakeLists.txt Switches parametric-map applications to the new macro.
apps/​GenerateCLP/​Testing/​dcmqiCheckCommand.cmake Adds command-result and output checks.
apps/​GenerateCLP/​Testing/​CMakeLists.txt Adds descriptor rejection and CLI tests.
apps/​GenerateCLP/​dcmqiGenerateCLP.cxx Implements descriptor validation and header generation.
apps/​GenerateCLP/​dcmqiCLP.h Adds shared parsing, help, and echo support.
apps/​GenerateCLP/​CMakeLists.txt Defines the generator and host-tool override.
apps/​CMakeLists.txt Integrates the generator and its tests.
.github/​workflows/​cmake-win.yml Adds a build-step identifier.
.github/​workflows/​cmake-macos.yml Adds a build-step identifier.
.github/​workflows/​cmake-linux.yml Pins the runner to Ubuntu 24.04.

Review effort: Balanced


int main(int argc, char* argv[])
{
return ModuleEntryPoint(argc, argv);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, and fixed in 483cf42. In a Slicer build, dcmqiMacroBuildCLI now uses the same three variables SEMMacroBuildCLI used:

  • Wrapper. The executable is built from Slicer's wrapper, SlicerExecutionModel_CLI_LIBRARY_WRAPPER_CXX, which calls itk::itkFactoryRegistration() before ModuleEntryPoint. It is compiled with MODULE_STATIC, since <name>Lib is static.
  • Include directories. SlicerExecutionModel_EXTRA_INCLUDE_DIRECTORIES is added to the executable.
  • Libraries. The executable links SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES.

Standalone builds still use dcmqiCLIExecutableWrapper.cxx and get no ITKFactoryRegistration dependency.

Verification so far is limited to a stub CMake project. It used Slicer's SEMCommandLineLibraryWrapper.cxx.in unchanged, stand-in variables and a stand-in ITKFactoryRegistration library. There, the factories were registered before the application ran. A real Slicer extension build is still pending.

Comment thread CMake/dcmqiTest.cmake
# The test drivers include the application source, so they must see the
# same TCLAP headers as ${_SELF_MODULE_NAME}Lib even if the including
# project has another copy of TCLAP on its include path.
target_include_directories(${_name} BEFORE PRIVATE ${DCMQI_TCLAP_INCLUDE_DIR})
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, and fixed in 483cf42. dcmqi_add_test_executable links SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES again, and also adds SlicerExecutionModel_EXTRA_INCLUDE_DIRECTORIES. Those were previously inherited from SEMMacroBuildCLI's directory-level include_directories().

In the stub project described in the other thread, the test driver compiled with HAS_ITK_FACTORY_REGISTRATION and linked ITKFactoryRegistration. A real Slicer extension build is still pending.

Comment on lines +45 to +46
if(NOT TARGET dcmqiGenerateCLP)
message(FATAL_ERROR "dcmqiMacroBuildCLI: the dcmqiGenerateCLP target is not defined")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retired in c1ce745: the find_package(DCMQI) branches are removed from apps/seg, apps/paramaps and apps/sr. The applications are now built only as part of dcmqi, either standalone or as a Slicer extension. Nothing builds them separately against an installed dcmqi, so exporting the generator and macro for that mode didn't seem worth the extra public surface.

Comment thread CMakeLists.txt
set(DCMQI_TCLAP_INCLUDE_DIR ${TCLAP_INCLUDE_DIR})
message(STATUS "${_msg} - no")
else()
set(DCMQI_TCLAP_INCLUDE_DIR ${DCMQI_SOURCE_DIR}/tclap)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1d024f1. Two notices are now installed to ${DCMQI_INSTALL_DOC_DIR} (doc/) in the RuntimeLibraries component, which is what the CPack packages contain:

  • LICENSE.txt
  • tclap/COPYING as TCLAP-COPYING.txt, when the bundled TCLAP is used

Slicer extension packaging is left unchanged. The CI packages for 6167719 contain doc/LICENSE.txt and doc/TCLAP-COPYING.txt. Checked on Linux x64, macOS arm64 and Windows.

Comment thread apps/GenerateCLP/CMakeLists.txt Outdated
Comment on lines +9 to +11
set(DCMQI_GENERATECLP_EXECUTABLE "" CACHE FILEPATH
"dcmqiGenerateCLP executable to run during the build instead of building it (for cross-compiling)")
mark_as_advanced(DCMQI_GENERATECLP_EXECUTABLE)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in df209c6. DCMQI_GENERATECLP_EXECUTABLE is now declared in the top-level CMakeLists.txt, before the superbuild branch, and marked with mark_as_superbuild(DCMQI_GENERATECLP_EXECUTABLE:FILEPATH).

A superbuild configured with -DDCMQI_GENERATECLP_EXECUTABLE=/opt/host/dcmqiGenerateCLP now has it in the inner build's initial cache:

set(DCMQI_GENERATECLP_EXECUTABLE "/opt/host/dcmqiGenerateCLP" CACHE FILEPATH ...)

|| value > INT_MAX)
{
throw DescriptorError(context + ": <default> must be an integer");
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, and fixed in 11b712c. After validation, the generator replaces the default with the parsed value (std::to_string), so the descriptor text is no longer copied into the generated code.

The new test dcmqiGenerateCLP_generates_integerDefaultDecimal uses a default of +008:

  • The generated header must contain int x = 8; and false, 8, "int".
  • The old generator wrote +008, which fails to compile with "invalid digit '8' in octal constant". The test fails against it.

The generated headers of all 7 dcmqi descriptors are unchanged.

fedorov and others added 5 commits November 16, 2026 15:37
Add the unmodified include/tclap/ directory of tclap-1.2.5.tar.gz
(SHA-256 bb649f76dae35e8d0dcba4b52acfd4e062d787e6a81b43f7a4b01275153165a6)
with its MIT license, for the command-line parsing code of the dcmqi
applications. tclap/README.md records the provenance; the README lists
TCLAP and JsonCpp as the third-party code in the source tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SlicerExecutionModel is under the 3D Slicer license, which Debian does
not consider DFSG-free (Slicer/SlicerExecutionModel#159), and it was the
only such dependency of dcmqi. Replace the parts dcmqi used with code
written for dcmqi, without copying from SlicerExecutionModel:

- apps/GenerateCLP/dcmqiGenerateCLP.cxx: build-time tool that reads an
  application's XML descriptor and writes <name>CLP.h with the PARSE_ARGS
  macro. It uses only the C++ standard library (no DCMTK, no Python) and
  accepts only the descriptor features dcmqi uses, failing the build on
  anything else.
- apps/GenerateCLP/dcmqiCLP.h: runtime support shared by the generated
  headers, on top of the vendored TCLAP.
- CMake/dcmqiMacroBuildCLI.cmake: replaces SEMMacroBuildCLI with the same
  targets (<name>Lib with main renamed ModuleEntryPoint, <name>, XML next
  to the executable) and honors the SlicerExecutionModel_DEFAULT_CLI_*
  variables that 3D Slicer sets for extension builds.

The applications' sources and XML descriptors are unchanged, and so is
their command-line behavior: --xml, --help, --echo, error messages and
exit codes match dcmqi 1.5.7 on a corpus of 753 invocations.
TCLAP_INCLUDE_DIR selects a system TCLAP instead of the vendored one.

Add tests for the generator's rejection of unsupported descriptors and
for the applications' --xml output and argument errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cache save steps run only when steps.build.outcome is 'success', but
no step had the id 'build', so the condition was never true and the
DCMTK, ITK and zlib builds were never saved. Each run that missed the
cache rebuilt them from scratch. Give the build steps that id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tid1500reader and tid1500writer failed to link with MSVC: their main()
takes "char** argv", which MSVC decorates differently from the
"char* argv[]" declared by the executable wrapper, although the two are
the same type. GCC and Clang decorate both the same way.

Declare ModuleEntryPoint extern "C" in dcmqiCLP.h, which every
application includes before main(), and in the wrapper. The symbol then
no longer depends on how an application spells argv. The application
sources are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dcmqi 1.5.7 Windows package has the Microsoft C/C++ runtime DLLs
(vcruntime140*, msvcp140*, concrt140) in bin/, next to the executables;
SlicerExecutionModel's build macro installed them. Without them the
applications do not start on systems that lack the Visual C++
Redistributable.

dcmqiMacroBuildCLI now includes InstallRequiredSystemLibraries once, with
the executables' install destination and the RuntimeLibraries component
that CPack packages. Packages on other platforms are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fedorov
fedorov force-pushed the remove-slicer-execution-model branch from 081c493 to 4299a61 Compare November 16, 2026 20:38
fedorov and others added 6 commits November 16, 2026 15:49
3D Slicer turns off ITK's automatic IO factory registration and supplies,
through SlicerConfig.cmake, a main() wrapper that calls
itk::itkFactoryRegistration() before the application, together with the
ITKFactoryRegistration include directories and library. SEMMacroBuildCLI
used all three; dcmqiMacroBuildCLI and the test drivers ignored them, so
the applications built as a Slicer extension could not read or write
images, and the test drivers, which call itkFactoryRegistration() when
the target exists, would not link.

Use SlicerExecutionModel_CLI_LIBRARY_WRAPPER_CXX, _EXTRA_INCLUDE_DIRECTORIES
and _EXTRA_EXECUTABLE_TARGET_LIBRARIES when they are defined. Standalone
builds are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The option was declared in apps/GenerateCLP, which only the inner build
reaches, and the superbuild did not pass it on. Setting it on the
top-level configure, as a cross-compile would, had no effect: the inner
build compiled a dcmqiGenerateCLP for the target, which cannot run on the
build host. Declare it in the top-level CMakeLists.txt and mark it for the
superbuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dcmqiGenerateCLP validated an integer <default> with strtol(..., 10) but
wrote the original text into the generated code, where a leading zero
makes the literal octal: "010" became 8 and "08" did not compile. Write
the parsed value instead. None of the dcmqi descriptors is affected; their
generated headers are unchanged.

Add a test that checks the generated header for such a default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The applications compile in the bundled TCLAP, whose MIT license requires
its notice in copies of the software, but the packages, which contain the
RuntimeLibraries component, shipped no license file at all. Install
LICENSE.txt, and tclap/COPYING as TCLAP-COPYING.txt when the bundled TCLAP
is used, into the doc directory of that component. Slicer extension
packaging is left as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
apps/seg, apps/paramaps and apps/sr called find_package(DCMQI) when
configured on their own, against an installed dcmqi. That relied on the
package exporting SlicerExecutionModel; the installed package does not
provide dcmqiGenerateCLP or dcmqiMacroBuildCLI, so the configuration no
longer works. Nothing builds it, so remove it: the applications are built
as part of dcmqi, standalone or as a Slicer extension.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"module" is a keyword in C++20 modules (SonarCloud cpp:S1669). Also use
std::size for the size of ParameterKinds (cpp:S7127). No change to the
generated headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0