ENH: Remove eigen_internal; export ITKInternalEigen3_DIR#6304
ENH: Remove eigen_internal; export ITKInternalEigen3_DIR#6304blowekamp wants to merge 4 commits into
Conversation
|
|
||
| # Install Eigen3Config.cmake alongside other ITK module files, | ||
| # matching the path expected by ITKInternalEigen3_DIR. | ||
| set(CMAKE_INSTALL_DATADIR "${ITK_INSTALL_PACKAGE_DIR}/Modules") |
There was a problem hiding this comment.
WE should probably follow the ITK3P_ prefix convnetion here.
|
@blowekamp Thank you for continuing to work to make the Eigen3 integration better. This is complicated, but your changes look like improvements. If you have performed the tests that are described in the comment (i.e. building downstream products using ITK's internal Eigen3) then this is looking better. Thank you for adding the usage comments and cleaning up. |
|
@hjmjohnson I believe that I saw in some of your Eigen work that BRAINS and/or ANTs, are using ITK's provided Eigen3 but doing an "Eigen/X" include. Is that correct? That is unfortunately the 1 ( of 3 ) usages of Eigen that was removed to have clear separation of the path safe ITK eigen, and a system like eigen. The solution to such usage would be to be to use the ITK_EIGEN macro for the include OR to add the documented cmake code to do a find_package for Eigen. |
Code extracted from:
https://github.com/InsightSoftwareConsortium/eigen
at commit e8527abce63dee5ed7090a81f06e4d6e51519cf7 (for/itk-eigen-5.0.1-bc3b39870).
# By Eigen Upstream * upstream-Eigen3: Eigen3 2026-05-19 (e8527abc)
ITK_EIGEN(X) covers all internal Eigen includes via the header macro. Downstream projects locate Eigen3 by setting Eigen3_DIR from the exported ITKInternalEigen3_DIR. The eigen_internal target and its second include path are no longer needed. Eigen3Config.cmake is installed alongside ITK module files so ITKInternalEigen3_DIR resolves correctly in both build and install trees.
c1b9017 to
fa286ba
Compare
|
ANTs + BRAINSTools build cleanly with no Eigen-related regression. Methodology
Results
Coverage on the candidate: full clean ANTs SuperBuild (hundreds of ANTS source files, all SEM and ANTS Eigen-using paths). ~3974/4237 BRAINSTools inner targets compiled cleanly before hitting the SEM/Expat link step that is configured separately in this test harness. Zero Eigen-related compile or link errors in any ANTs or BRAINSTools translation unit on the candidate. |
|
| Filename | Overview |
|---|---|
| Modules/ThirdParty/Eigen3/CMakeLists.txt | Removes eigen_internal target, sets ITKEigen3_LIBRARIES to empty (correct for header-only), exports ITKInternalEigen3_DIR for both build and install trees. Path logic is sound. Contains a verbose 15-line downstream-usage comment that violates the ITK prose budget. |
| Modules/ThirdParty/Eigen3/src/CMakeLists.txt | Overrides CMAKE_INSTALL_DATADIR to route Eigen3Config.cmake to ${ITK_INSTALL_PACKAGE_DIR}/Modules before calling add_subdirectory(itkeigen); removes itk_module_target(eigen_internal) call. Functional change is correct. |
| Modules/ThirdParty/Eigen3/src/itkeigen/CMakeLists.txt | Removes eigen_internal INTERFACE target and its standalone-project boilerplate (option, GNUInstallDirs); retains eigen_external. Two comments need correction: stale eigen_internal reference and inaccurate claim that the parent calls include(GNUInstallDirs). |
| Modules/ThirdParty/Eigen3/src/itk_eigen.h.in | Removes the downstream-usage Doxygen comment block that documented ITKInternalEigen3_DIR. Content migrated to CMakeLists.txt comments (where it should be further trimmed). No functional change. |
| Modules/ThirdParty/Eigen3/UpdateFromUpstream.sh | Updates the upstream Eigen3 tag reference from for/itk-5.0.1-v3 to for/itk-eigen-5.0.1-bc3b39870; no logic change. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[downstream project\nfind_package ITK] --> B{ITK_USE_SYSTEM_EIGEN?}
B -- yes --> C[ITKEigen3_EXPORT_CODE\nfind_package Eigen3 system]
B -- no --> D[ITKEigen3_EXPORT_CODE\nset ITKInternalEigen3_DIR]
D --> E{build tree?}
E -- yes --> F[ITKInternalEigen3_DIR =\nITKEigen3_BINARY_DIR/src/itkeigen\ncontains Eigen3Config.cmake]
E -- no install tree --> G[ITKInternalEigen3_DIR =\nITK_MODULES_DIR\n= prefix/ITK_INSTALL_PACKAGE_DIR/Modules]
F --> H[downstream:\nset Eigen3_DIR = ITKInternalEigen3_DIR\nfind_package Eigen3 CONFIG\ntarget_link_libraries ... Eigen3::Eigen]
G --> H
Comments Outside Diff (1)
-
Modules/ThirdParty/Eigen3/src/itkeigen/CMakeLists.txt, line 880 (link)Stale comment:
eigen_internalwas removed by this PR. The install rule now only serveseigen_external.
Reviews (1): Last reviewed commit: "ENH: Remove eigen_internal; set ITKInter..." | Re-trigger Greptile
| # Re-using internal Eigen3 in another project: | ||
| # A downstream project can re-use ITK's vendored Eigen3 via the exported | ||
| # Eigen3Config.cmake without depending on the ITK_EIGEN() macro. | ||
| # | ||
| # find_package(ITK REQUIRED COMPONENTS ITKEigen3) | ||
| # if(DEFINED ITKInternalEigen3_DIR) | ||
| # set(Eigen3_DIR ${ITKInternalEigen3_DIR}) | ||
| # endif() | ||
| # find_package(Eigen3 REQUIRED CONFIG) | ||
| # add_executable(main main.cpp) | ||
| # target_link_libraries(main PUBLIC ${ITK_LIBRARIES}) | ||
| # target_link_libraries(main PUBLIC Eigen3::Eigen) | ||
| # | ||
| # Then the project can include Eigen headers directly: | ||
| # #include <Eigen/Eigenvalues> |
There was a problem hiding this comment.
Verbose in-source comment exceeds prose budget
The 15-line downstream usage example violates the ITK prose budget rule for in-source comments (1 short line, ≤ 100 chars; default = none). Usage examples belong in documentation (e.g., Documentation/, Doxygen, or the ITK Software Guide), not in CMakeLists.txt. Moving this documentation comment from itk_eigen.h.in to a CMakeLists.txt source file doesn't change its status as committed text subject to the budget.
Context Used: AGENTS.md (source)
| # CMAKE_INSTALL_INCLUDEDIR and CMAKE_INSTALL_DATADIR are inherited from the | ||
| # parent ITK project (which calls include(GNUInstallDirs)) and src/CMakeLists.txt. |
There was a problem hiding this comment.
Inaccurate comment about
include(GNUInstallDirs)
A search of the ITK top-level CMakeLists.txt and CMake/ directory confirms that ITK does NOT call include(GNUInstallDirs) at any parent scope. The previous code called it here directly; the claim that it is "inherited from the parent ITK project" is incorrect. Since CMAKE_INSTALL_INCLUDEDIR is only used to set INCLUDE_INSTALL_DIR, which is never referenced in Eigen3Config.cmake.in, this is currently harmless — but the comment will mislead future readers.
| # CMAKE_INSTALL_INCLUDEDIR and CMAKE_INSTALL_DATADIR are inherited from the | |
| # parent ITK project (which calls include(GNUInstallDirs)) and src/CMakeLists.txt. | |
| # CMAKE_INSTALL_DATADIR is set by src/CMakeLists.txt; CMAKE_INSTALL_INCLUDEDIR | |
| # is not provided by the parent and is unused in Eigen3Config.cmake.in. |
hjmjohnson
left a comment
There was a problem hiding this comment.
This represents a good step forward. There are a few nit with your comment about naming, and greptile items.
I think the long comment is good in this case, and greptile should be ignored in this case.
I'll leave it to @blowekamp to decide if another round of nit fixes should be included in this PR.
Remove the
eigen_internalCMake target and replace it with exportedITKInternalEigen3_DIRpointing to the vendoredEigen3Config.cmake.Design rationale
All ITK-internal Eigen includes go through the
ITK_EIGEN(X)macro initk_eigen.h, which resolves toitkeigen/Eigen/X. Theeigen_internalINTERFACE target existed to provide a second include root (
src/itkeigen)so that
<Eigen/X>worked alongside<itkeigen/Eigen/X>. With the macroenforcing the
itkeigen/prefix for internal code, that second root isunnecessary.
Downstream projects that need
<Eigen/X>can use the exportedEigen3Config.cmakeviaITKInternalEigen3_DIR, which is now set inthe
ITKEigen3module's export code for both build and install trees.Eigen3Config.cmakeis installed alongside other ITK module files(
${ITK_INSTALL_PACKAGE_DIR}/Modules) to match the path thatITK_MODULES_DIRexposes at find-time.EIGEN_MPL2_ONLYis not propagated to external consumers viaEigen3::Eigen; it remains an ITK-internal enforcement only, appliedthrough
itk_eigen.hwhenITK_USE_EIGEN_MPL2_ONLYis ON.The
WIP:second commit removes stale standalone-project boilerplatefrom
itkeigen/CMakeLists.txtthat predates theadd_subdirectoryintegration and needs verification before promoting.
AI assistance
GitHub Copilot assisted with design, implementation, and commit authoring.
Changes were reviewed, tested locally with
ninja install, and verifiedby inspecting installed paths in the build tree.