fix(build): include GNUInstallDirs before add_subdirectory(subsystems)#36
Conversation
The DecayVolume and Calorimeter CMakeLists.txt files reference CMAKE_INSTALL_DATADIR in their install(FILES ... DESTINATION ...) rules for sbt.toml and calo.toml. The top-level CMakeLists.txt previously did include(GNUInstallDirs) only inside the "Installation" block at the bottom of the file, i.e. AFTER add_subdirectory(subsystems). That meant subsystems configured with an undefined CMAKE_INSTALL_DATADIR, so the resulting cmake_install.cmake had `file(INSTALL DESTINATION /SHiPGeometry ...)` (absolute root path). Strict CI environments fail the install step with "file cannot create directory: /SHiPGeometry"; permissive local environments silently drop the toml files from the install tree. Move include(GNUInstallDirs) above the add_subdirectory(...) calls so all subdirectories see the GNUInstallDirs variables, and drop the now-redundant local include in apps/CMakeLists.txt.
📝 WalkthroughWalkthrough
ChangesGNUInstallDirs inclusion reorder
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CMakeLists.txt`:
- Around line 46-49: The include(GNUInstallDirs) statement needs to be
repositioned in CMakeLists.txt because it currently appears after the first
add_subdirectory() call, but it must come before all add_subdirectory() calls to
make CMAKE_INSTALL_DATADIR, CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_LIBDIR, and
CMAKE_INSTALL_INCLUDEDIR available to subsystem CMakeLists files. Move the
include(GNUInstallDirs) line earlier in the file so it executes before any
add_subdirectory() calls begin.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: df9bd688-8d00-442e-b4af-d181d10aefc3
📒 Files selected for processing (2)
CMakeLists.txtapps/CMakeLists.txt
💤 Files with no reviewable changes (1)
- apps/CMakeLists.txt
Summary
subsystems/DecayVolume/CMakeLists.txtandsubsystems/Calorimeter/CMakeLists.txtinstallsbt.toml/calo.tomlviaand bake
CMAKE_INSTALL_PREFIX/CMAKE_INSTALL_DATADIRinto the compiled*_TOML_INSTALL_PATHmacros.But the top-level
CMakeLists.txtonly doesinclude(GNUInstallDirs)inside the bottom "Installation" block — i.e. afteradd_subdirectory(subsystems). So when subsystems are configured,CMAKE_INSTALL_DATADIRis undefined → empty, and the resultingcmake_install.cmakewrites:A non-root install then fails:
(Permissive environments silently drop the toml file from the install tree instead, which is arguably worse — surfaced this while bumping the conda recipe for v0.2.0.)
Fix
include(GNUInstallDirs)aboveadd_subdirectory(src)/subsystems/appsin the top-levelCMakeLists.txt.include(GNUInstallDirs)inapps/CMakeLists.txt.Verification
Locally:
Downstream (SHiP conda recipe) without
-DCMAKE_INSTALL_DATADIR=shareworkaround now landssbt.tomlandcalo.tomlunder$PREFIX/share/SHiPGeometry/.Summary by CodeRabbit