Skip to content

Fix/opentims system install fallback - #9148

Merged
pjones merged 13 commits into
OpenMS:developfrom
michalsta:fix/opentims-system-install-fallback
Apr 15, 2026
Merged

pjones merged 13 commits into
OpenMS:developfrom
michalsta:fix/opentims-system-install-fallback

Conversation

@michalsta

@michalsta michalsta commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Use standard CMake mechanisms to find OpenTIMS package already installed on system, fall back to git fetch+build from source (previous mechanism) if not present. Needs OpenTIMS 1.2.0b4 installed.

Summary by CodeRabbit

  • New Features

    • Better OpenTIMS integration: automatic detection of system installs with a robust fallback build and consistent namespaced linking so Bruker TimsTOF .d file support is more reliable.
  • Chores

    • More consistent handling of compression and SQLite linkage to reduce build issues and improve runtime reliability.

@github-actions

Copy link
Copy Markdown
Contributor

@michalsta The following names might be missing from the AUTHORS file:

  • Achal Bajpai

  • Aditya Muzumdar

  • Akshat Shrivastava

  • alhigaylan

  • Anagha Rao

  • anamaria-uofg

  • Arslan Siraj

  • Arslan-Siraj

  • Arvind Dhavala

  • Avni2000

  • axelwalter

  • Bhuvan B

  • Binayak Bhattacharjee

  • Chandra Pratap Shah

  • Chirag

  • Chris Bielow

  • Claer

  • enetz

  • Eugen Netz

  • Fengchao

  • Hannes Roest

  • Hendrik Weisser

  • JeeH-K

  • Jeremi Maciejewski

  • JKVISION1101

  • Johannes von Kleist

  • Jonas Scheid

  • Joshua Charkow

  • julianuspfeuffer

  • Julianus Pfeuffer

  • Justin Sing

  • Ketan Saini

  • Krishna Dubey

  • Krrish Verma

  • Ma Li

  • Martin Lang

  • matteopilz

  • Matteo Pilz

  • MatthewThe

  • Matthias Bernt

  • Michael R. Crusoe

  • Michał Startek

  • Mohamed Ali

  • mr-c

  • NarendraRaoJami

  • Peter J. Jones

  • Peter Jones

  • Radu Suciu

  • Ralf Gabriels

  • rickhelmus

  • Ritik Kumar

  • ronak-15

  • Samuel Wein

  • Santhil Kherwal

  • satyam yadav

  • Simon Gene Gottlieb

  • singjc

  • SK

  • Soubhagya Mohapatra

  • Srikanth K N

  • Srikanthkn0

  • timosachsenberg

  • Timo Sachsenberg

  • Tom David Mueller

  • Tom David Müller

  • trapho

  • Yasset Perez-Riverol

  • yumengyann

  • yuvraj-coder1

Please consider applying the following patch:

--- AUTHORS	2026-04-14 16:32:41.836453712 +0000
+++ AUTHORS.new	2026-04-14 16:32:47.353012441 +0000
@@ -91,6 +91,7 @@
  - Ole Schulz-Trieglaff
  - Oliver Alka
  - Oliver Kohlbacher
+ - openms-jenkins-bot
  - Pasquale Domenico Colaianni
  - Patricia Scheil
  - Peter J. Jones

@coderabbitai

coderabbitai Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new CMake Find module for Opentims, changes external-lib logic to prefer a system/config package with a FetchContent fallback, updates how sqlite3/zstd are wired depending on discovery mode, and switches project and test linkages to the namespaced target opentims::opentims_cpp.

Changes

Cohort / File(s) Summary
CMake Find Module
cmake/Modules/FindOpentims.cmake
New find-module: tries find_package(opentims CONFIG QUIET) with Opentims_ROOT_DIR hints, validates imported target or falls back to find_path/find_library. Exposes Opentims_FOUND, Opentims_INCLUDE_DIR, Opentims_LIBRARIES; may create opentims::opentims_cpp IMPORTED target and marks cache vars advanced.
External Library Integration
cmake/cmake_findExternalLibs.cmake
Replaces unconditional FetchContent with a two-path flow: attempt find_package(Opentims QUIET) then FetchContent fallback (v1.2.0b4). Reads INTERFACE_COMPILE_DEFINITIONS to decide sqlite injection; switches build option to OPENTIMS_BUILD_LIB, keeps Python OFF and static sqlite ON; preserves zstd selection logic and adds add_library(opentims::opentims_cpp ALIAS opentims_cpp) in the fetch branch.
Targets & Linkage Updates
src/openms/CMakeLists.txt, src/tests/class_tests/openms/CMakeLists.txt
Replaced direct opentims_cpp linkage with namespaced opentims::opentims_cpp for OpenMS and tests; sqlite3 linkage preserved for tests. No source/API changes.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(220,230,241,0.5)
    participant CMake
    participant ConfigPkg as "Config Package\n(opentims)"
    participant Finder as "Finder\n(find_path/find_library)"
    participant Fetch as "FetchContent\n(opentims repo)"
    participant SQLite as "SQLiteCpp/sqlite3"
    participant Zstd as "zstd (system/bundled)"
    participant Target as "opentims::opentims_cpp"
    end
    CMake->>ConfigPkg: try find_package(opentims CONFIG QUIET)
    alt config package found
        ConfigPkg->>CMake: provide imported target
        CMake->>Target: validate/import target properties
        CMake->>SQLite: inspect INTERFACE_COMPILE_DEFINITIONS -> maybe inject include/link
        CMake->>Zstd: prefer system zstd targets if present
    else config not found
        CMake->>Finder: find_path(opentims++/opentims.h), find_library(opentims_cpp)
        Finder-->>CMake: return include/lib paths
        CMake->>Target: create IMPORTED STATIC target with properties
        CMake->>SQLite: set up sqlite3 linkage if needed
        CMake->>Zstd: use bundled zstddeclib.c if no system zstd
    end
    alt use FetchContent fallback
        CMake->>Fetch: clone & configure (OPENTIMS_BUILD_LIB ON, Python OFF, static sqlite)
        Fetch->>Target: build opentims_cpp
        CMake->>Target: add namespace alias opentims::opentims_cpp
        CMake->>SQLite: supply SQLite include/link privately
    end
Loading

Suggested reviewers

  • pjones
  • jpfeuffer

Poem

🐇 I hop through CMake meadows, sniff for Opentims clear,
If config hides away, FetchContent scurries near,
SQLite tucked close, zstd either found or sewn,
Namespaced targets leap — a tidy garden grown,
Tiny paws, big builds, and a carrot-shaped cheer.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a system install fallback mechanism for OpenTIMS via CMake's find_package, with git FetchContent as the fallback path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmake/cmake_findExternalLibs.cmake (1)

281-326: ⚠️ Potential issue | 🔴 Critical

Critical: Duplicate WITH_OPENTIMS block must be removed.

This existing block at lines 281-326 was not removed, but a new block with find_package fallback logic was added at lines 408-475. Both blocks are gated by if (WITH_OPENTIMS) and will execute sequentially, causing:

  1. The first block fetches and builds opentims via FetchContent
  2. The second block's find_package(Opentims QUIET) then runs (but won't help since targets already exist)
  3. Duplicate FetchContent_Declare for opentims
  4. The add_library(opentims::opentims_cpp ALIAS opentims_cpp) on line 471 will fail because the target was already created

The new block at lines 408-475 is the intended replacement that wraps FetchContent with a find_package guard. This original block should be removed entirely.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmake/cmake_findExternalLibs.cmake` around lines 281 - 326, Remove the
original duplicate WITH_OPENTIMS block (the
FetchContent_Declare/FetchContent_MakeAvailable sequence that creates opentims
and opentims_cpp, including the zstd fallback and target_* calls) so only the
newer block with find_package(Opentims QUIET) and the guarded FetchContent
remains; ensure you delete the entire first if (WITH_OPENTIMS) ... endif() that
references FetchContent_Declare(opentims),
target_include_directories(opentims_cpp ...), target_link_libraries(opentims_cpp
...), target_sources(opentims_cpp ...), and the message about Built opentims_cpp
so add_library(opentims::opentims_cpp ALIAS opentims_cpp) in the later block
will not collide with preexisting targets.
🧹 Nitpick comments (3)
cmake/cmake_findExternalLibs.cmake (1)

414-427: System-installed opentims may lack INTERFACE_COMPILE_DEFINITIONS when discovered via manual fallback.

When FindOpentims.cmake uses the manual search fallback (no CMake config package), the imported target is created without INTERFACE_COMPILE_DEFINITIONS. This means _opentims_defs will be empty or NOTFOUND, and the OPENTIMS_LINK_SQLITE_STATICALLY check will never match—even if the library was actually built with that option.

Consider either:

  1. Documenting that system installs must provide a CMake config package for full compatibility
  2. Adding a fallback that assumes OPENTIMS_LINK_SQLITE_STATICALLY for manually-discovered libraries (since OpenMS requires sqlite3 linking anyway)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmake/cmake_findExternalLibs.cmake` around lines 414 - 427, The imported
target opentims::opentims_cpp may not expose INTERFACE_COMPILE_DEFINITIONS when
discovered via the manual fallback, so the get_target_property(_opentims_defs
opentims::opentims_cpp INTERFACE_COMPILE_DEFINITIONS) check can be empty and
miss OPENTIMS_LINK_SQLITE_STATICALLY; update the logic after get_target_property
to treat an empty/NOTFOUND _opentims_defs as a potential manual-install case and
fall back to assuming OPENTIMS_LINK_SQLITE_STATICALLY (or at least perform the
same include/link injection) when Opentims_FOUND was set via the manual search
path, ensuring target_include_directories and target_link_libraries are applied
to opentims::opentims_cpp if the property is missing but the library was
discovered manually.
cmake/Modules/FindOpentims.cmake (2)

52-61: Manual fallback creates target without compile definitions.

When creating the imported target via manual discovery, INTERFACE_COMPILE_DEFINITIONS is not set. If the discovered library was built with OPENTIMS_LINK_SQLITE_STATICALLY, downstream code in cmake_findExternalLibs.cmake (line 422) won't detect this and won't inject the required sqlite3 dependencies.

This is a known limitation of manual discovery (you can't introspect how a library was built), but it should be documented or handled with a safe default assumption.

Option: Document limitation in module header
 # Hints:
 #  Set Opentims_ROOT_DIR to the root of a custom installation.
+#
+# Note: When discovered via manual search (no CMake config package),
+# compile definitions like OPENTIMS_LINK_SQLITE_STATICALLY cannot be
+# introspected. OpenMS will assume static sqlite linking is required.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmake/Modules/FindOpentims.cmake` around lines 52 - 61, The manual-import
branch that creates the imported target (when Opentims_FOUND is true and adding
opentims::opentims_cpp via add_library) does not set
INTERFACE_COMPILE_DEFINITIONS, so consumers can't detect
OPENTIMS_LINK_SQLITE_STATICALLY; update this module to (1) add a clear header
comment explaining this limitation and instruct downstream users how to override
compile definitions if needed, and (2) when creating the imported target
(add_library(opentims::opentims_cpp ...)/set_target_properties), explicitly set
INTERFACE_COMPILE_DEFINITIONS (e.g., to an empty list or a documented safe
default) so the property exists and downstream code in
cmake_findExternalLibs.cmake can behave deterministically; reference
Opentims_LIBRARY, Opentims_INCLUDE_DIR, INTERFACE_COMPILE_DEFINITIONS, and
OPENTIMS_LINK_SQLITE_STATICALLY in the comment.

25-27: IMPORTED_LOCATION may be unset for interface or alias targets.

When the config package defines opentims::opentims_cpp as an interface library or alias, get_target_property(... IMPORTED_LOCATION) at line 26 will return NOTFOUND, leaving Opentims_LIBRARIES empty in the status message. However, since Opentims_LIBRARIES is used only for informational output (not actual linking), this is acceptable. The actual linking uses the opentims::opentims_cpp target directly, which works correctly regardless.

For better robustness, consider iterating through configuration-specific properties like IMPORTED_LOCATION_RELEASE or checking if the target has the property before using it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmake/Modules/FindOpentims.cmake` around lines 25 - 27, The
get_target_property call for opentims::opentims_cpp uses IMPORTED_LOCATION which
may be NOTFOUND for interface/alias targets, causing Opentims_LIBRARIES to be
empty; update the logic around the get_target_property for opener target
opentims::opentims_cpp so it first checks has_property or falls back to
configuration-specific properties (e.g., IMPORTED_LOCATION_RELEASE,
IMPORTED_LOCATION_DEBUG) or skips setting Opentims_LIBRARIES when no imported
location exists, while keeping Opentims_INCLUDE_DIR from
INTERFACE_INCLUDE_DIRECTORIES and preserving the informational-only use of
Opentims_LIBRARIES.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmake/cmake_findExternalLibs.cmake`:
- Around line 433-437: The FetchContent_Declare block for the opentims
dependency uses GIT_TAG v1.2.0b1 but the PR description requires OpenTIMS
v1.2.0b3; update the FetchContent_Declare invocation for the opentims target to
use the correct tag (change the GIT_TAG value), or if the documented version is
wrong, update the PR description to match GIT_TAG—ensure consistency between the
FetchContent_Declare (opentims / GIT_TAG) and the PR documentation.

---

Outside diff comments:
In `@cmake/cmake_findExternalLibs.cmake`:
- Around line 281-326: Remove the original duplicate WITH_OPENTIMS block (the
FetchContent_Declare/FetchContent_MakeAvailable sequence that creates opentims
and opentims_cpp, including the zstd fallback and target_* calls) so only the
newer block with find_package(Opentims QUIET) and the guarded FetchContent
remains; ensure you delete the entire first if (WITH_OPENTIMS) ... endif() that
references FetchContent_Declare(opentims),
target_include_directories(opentims_cpp ...), target_link_libraries(opentims_cpp
...), target_sources(opentims_cpp ...), and the message about Built opentims_cpp
so add_library(opentims::opentims_cpp ALIAS opentims_cpp) in the later block
will not collide with preexisting targets.

---

Nitpick comments:
In `@cmake/cmake_findExternalLibs.cmake`:
- Around line 414-427: The imported target opentims::opentims_cpp may not expose
INTERFACE_COMPILE_DEFINITIONS when discovered via the manual fallback, so the
get_target_property(_opentims_defs opentims::opentims_cpp
INTERFACE_COMPILE_DEFINITIONS) check can be empty and miss
OPENTIMS_LINK_SQLITE_STATICALLY; update the logic after get_target_property to
treat an empty/NOTFOUND _opentims_defs as a potential manual-install case and
fall back to assuming OPENTIMS_LINK_SQLITE_STATICALLY (or at least perform the
same include/link injection) when Opentims_FOUND was set via the manual search
path, ensuring target_include_directories and target_link_libraries are applied
to opentims::opentims_cpp if the property is missing but the library was
discovered manually.

In `@cmake/Modules/FindOpentims.cmake`:
- Around line 52-61: The manual-import branch that creates the imported target
(when Opentims_FOUND is true and adding opentims::opentims_cpp via add_library)
does not set INTERFACE_COMPILE_DEFINITIONS, so consumers can't detect
OPENTIMS_LINK_SQLITE_STATICALLY; update this module to (1) add a clear header
comment explaining this limitation and instruct downstream users how to override
compile definitions if needed, and (2) when creating the imported target
(add_library(opentims::opentims_cpp ...)/set_target_properties), explicitly set
INTERFACE_COMPILE_DEFINITIONS (e.g., to an empty list or a documented safe
default) so the property exists and downstream code in
cmake_findExternalLibs.cmake can behave deterministically; reference
Opentims_LIBRARY, Opentims_INCLUDE_DIR, INTERFACE_COMPILE_DEFINITIONS, and
OPENTIMS_LINK_SQLITE_STATICALLY in the comment.
- Around line 25-27: The get_target_property call for opentims::opentims_cpp
uses IMPORTED_LOCATION which may be NOTFOUND for interface/alias targets,
causing Opentims_LIBRARIES to be empty; update the logic around the
get_target_property for opener target opentims::opentims_cpp so it first checks
has_property or falls back to configuration-specific properties (e.g.,
IMPORTED_LOCATION_RELEASE, IMPORTED_LOCATION_DEBUG) or skips setting
Opentims_LIBRARIES when no imported location exists, while keeping
Opentims_INCLUDE_DIR from INTERFACE_INCLUDE_DIRECTORIES and preserving the
informational-only use of Opentims_LIBRARIES.
🪄 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: 18ba1c3f-2518-4b7f-bdab-14c0e52b7dd0

📥 Commits

Reviewing files that changed from the base of the PR and between daa9562 and a7fe66b.

📒 Files selected for processing (2)
  • cmake/Modules/FindOpentims.cmake
  • cmake/cmake_findExternalLibs.cmake

Comment on lines +14 to +28
# Prefer a CMake config package produced by opentims's own install rules.
find_package(opentims CONFIG QUIET
HINTS
"${Opentims_ROOT_DIR}"
"${Opentims_ROOT_DIR}/lib/cmake/opentims"
)
if(opentims_FOUND)
if(NOT TARGET opentims::opentims_cpp)
message(FATAL_ERROR "opentims config package found but target opentims::opentims_cpp is missing")
endif()
set(Opentims_FOUND TRUE)
get_target_property(Opentims_INCLUDE_DIR opentims::opentims_cpp INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(Opentims_LIBRARIES opentims::opentims_cpp IMPORTED_LOCATION)
return()
endif()

@jpfeuffer jpfeuffer Apr 14, 2026 •

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.

I think Cmake kind of does that distinction transparently, if you know what I mean.

You call find_package(${LIB}) from any main cmake file. This looks for a config file in ${LIB}_ROOT (or other system paths) automatically and if not, it falls back to whatever is done in cmake/Modules/Find${LIB}.cmake (if that Module exists locally or provided by CMake)

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.

You can force it to use one mode or the other by adding options to find_package() but by default it automatically tries both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not enough of of CMake wizard to answer this intelligently, so I'll let Claude speak ;)

You're right that find_package(Foo) with no mode tries Config then Module automatically — but that switching only happens at the outermost call. Once CMake dispatches to our FindOpentims.cmake module,
it's fully in charge; CMake does not separately try Config mode afterward. The explicit find_package(opentims CONFIG QUIET) on line 22 is therefore necessary so that users with an upstream opentimsConfig.cmake get the proper imported target (including OPENTIMS_LINK_SQLITE_STATICALLY when relevant), with find_path/find_library as a fallback for installs that have no config package.

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.

Haha I don't get it. If the outermost call dispatches to Module mode, it does so because there is no Config found. Why would one want to try to find the Config again in the Find Module? It cannot magically appear.
@coderabbitai What do you think?

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.

@jpfeuffer, actually there are two concrete reasons why the inner find_package(opentims CONFIG QUIET) call inside FindOpentims.cmake is not redundant:

1. Module mode preempts Config mode entirely

CMake has two modes: "Module" mode and "Config" mode. Module mode is invoked with the basic signature, and only if no module is found does the command fall back to Config mode. Module mode searches for Find<PackageName>.cmake in CMAKE_MODULE_PATH first.

Since OpenMS registers its own cmake/Modules/ directory in CMAKE_MODULE_PATH and FindOpentims.cmake exists there, CMake finds the module immediately and never attempts Config mode at the outer level. The inner find_package(opentims CONFIG QUIET) is therefore the only place Config mode is ever tried.

2. Case sensitivity of config filenames on Linux

Even in a world without the FindOpentims.cmake module, there is a case-sensitivity trap. CMake config mode searches for a file called <PackageName>Config.cmake or <lower-case-package-name>-config.cmake.

So find_package(Opentims) (capital O) would look for OpentimsConfig.cmake (capital O) or opentims-config.cmake. But as pjones observed, the installed package ships opentimsConfig.cmake (lowercase o). If nameConfig.cmake is available, only find_package(name) works, not find_package(Name) — i.e. on a case-sensitive filesystem, the capital-O outer call would miss it. The inner find_package(opentims CONFIG QUIET) (lowercase) correctly matches opentimsConfig.cmake.

This is very likely the root cause of pjones's observation that the system-installed opentims 1.2.0b3 wasn't being detected — FindOpentims.cmake existed in CMAKE_MODULE_PATH, so the outer Config mode search was skipped entirely, and the inner Config call needs to use the correct lowercase name to match the installed file.

The fix to properly propagate Opentims_ROOT_DIR as a HINTS path to the inner call (which the current code already does) is also important for non-standard install prefixes.


🧠 Learnings used
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 8530
File: src/pyOpenMS/CMakeLists.txt:78-80
Timestamp: 2026-01-12T12:26:12.890Z
Learning: In the OpenMS build system (src/pyOpenMS/CMakeLists.txt and related), when building pyOpenMS in standalone mode (via find_package(OpenMS REQUIRED)), the OpenMSConfig.cmake automatically finds all necessary public dependencies including Qt6, so Qt6_VERSION and related variables are available in both standalone and in-tree builds.

Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8975
File: CMakeLists.txt:76-98
Timestamp: 2026-03-24T08:16:28.331Z
Learning: In OpenMS/OpenMS CMakeLists.txt, when using CMake FetchContent with DOWNLOAD_NO_EXTRACT TRUE for a plain (non-archive) file download (e.g., a .fasta file), the downloaded file lands in `<name>_SOURCE_DIR` with its original filename. The path `${<name>_SOURCE_DIR}/<filename>` is therefore the correct way to reference it, NOT `${<name>_DOWNLOADED_FILE}`. This was empirically verified by timosachsenberg in PR `#8975`.

@timosachsenberg

Copy link
Copy Markdown
Contributor

@pjones author bot does some strange things

@pjones

pjones commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

@pjones author bot does some strange things

Have you looked at the commits in this PR? They go back to 2022. The source branch for this PR is really, really weird.

@pjones

pjones commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

@michalsta I just tried to build this branch using an external opentims 1.2.0b3 and it doesn't find opentims and tries to use git. If it helps, here's the layout of the opentims package that shows up in the openms build environment:

result/
├── include
│   └── opentims++
│       ├── bruker_api.h
│       ├── converters.h
│       ├── mio.hpp
│       ├── opentims_all.h
│       ├── opentims.h
│       ├── platform.h
│       ├── platform_os.h
│       ├── scan2inv_ion_mobility_converter.h
│       ├── so_manager.h
│       ├── sqlite3.h
│       ├── sqlite_helper.h
│       ├── thread_mgr.h
│       ├── tof2mz_converter.h
│       ├── zstd_errors.h
│       └── zstd.h
├── lib
│   ├── cmake
│   │   └── opentims
│   │       ├── opentimsConfig.cmake
│   │       ├── opentimsTargets.cmake
│   │       └── opentimsTargets-release.cmake
│   └── libopentims_cpp.a
└── opentimspy
    ├── dimension_translations.py
    ├── __init__.py
    ├── misc.py
    ├── opentims++
    │   ├── bruker_api.h
    │   ├── converters.h
    │   ├── mio.hpp
    │   ├── opentims_all.h
    │   ├── opentims.h
    │   ├── platform.h
    │   ├── platform_os.h
    │   ├── scan2inv_ion_mobility_converter.h
    │   ├── so_manager.h
    │   ├── sqlite3.h
    │   ├── sqlite_helper.h
    │   ├── thread_mgr.h
    │   ├── tof2mz_converter.h
    │   ├── zstd_errors.h
    │   └── zstd.h
    ├── opentims.py
    ├── opentimspy_cpp.cpython-313-x86_64-linux-gnu.so
    ├── plotting.py
    └── sql.py

michalsta and others added 5 commits April 15, 2026 12:02
Adds FindOpentims.cmake and wraps the opentims FetchContent block in
cmake_findExternalLibs.cmake with a find_package guard. If opentims is
already installed (e.g. by a package manager or from source), CMake uses
it directly and skips the git clone entirely. When no installation is
found the existing FetchContent path is taken unchanged, so there is no
regression for builds with network access.

Fixes OpenMS#9147

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…NITIONS

- Bump FetchContent GIT_TAG from v1.2.0b1 to v1.2.0b3 to match the
  version in opentims pyproject.toml and the available git tags.
- FindOpentims.cmake: explicitly set INTERFACE_COMPILE_DEFINITIONS to
  an empty list on the manual-import target so downstream consumers can
  distinguish "property absent" (CONFIG path) from "property set but
  empty" (manual path); add explanatory comment.
- FindOpentims.cmake: fall back to IMPORTED_LOCATION_<Config> variants
  and clear Opentims_LIBRARIES to "" (not NOTFOUND) for interface-only
  CONFIG targets where IMPORTED_LOCATION is unset.
- cmake_findExternalLibs.cmake: when INTERFACE_COMPILE_DEFINITIONS is
  NOTFOUND and the library was not found via a CMake config package,
  conservatively inject OpenMS sqlite3 since the build flags are unknown.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
CMake stores configuration-specific target properties under UPPERCASE
suffixes (IMPORTED_LOCATION_RELEASE, not IMPORTED_LOCATION_Release).
The fallback loop in FindOpentims.cmake was using mixed-case names, so
the loop never matched and Opentims_LIBRARIES ended up empty when the
package was installed without a bare IMPORTED_LOCATION property (e.g.
a Release-only install from cmake --install).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… bump to v1.2.0b4

- Remove the old FetchContent-only block (lines 281-326) that predated
  the system-install fallback logic; the surviving block at the bottom
  of the file already handles both paths correctly.
- Rename OPENTIMS_BUILD_CPP_LIB -> OPENTIMS_BUILD_LIB to match the
  refactored opentims CMakeLists.txt (idiomatic BUILD_SHARED_LIBS
  convention; the separate OPENTIMS_BUILD_SHARED_LIB option is gone).
- Bump GIT_TAG from v1.2.0b3 to v1.2.0b4 to track the latest release.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The unnamespaced opentims_cpp target only exists when opentims is built
via FetchContent. When found as a system install, only the namespaced
opentims::opentims_cpp imported target is available.

Use the namespaced form everywhere so both paths work without
conditional logic.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@michalsta
michalsta force-pushed the fix/opentims-system-install-fallback branch from a188b1b to e127366 Compare April 15, 2026 10:03

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
cmake/Modules/FindOpentims.cmake (2)

79-84: Consider using UNKNOWN IMPORTED for library type flexibility.

Using STATIC IMPORTED assumes the library is always statically built. If OpenTIMS could be built as a shared library, UNKNOWN IMPORTED would let CMake infer the type from the file extension.

This is a minor concern since OpenTIMS likely ships as a static library, but using UNKNOWN is more robust.

♻️ Optional: Use UNKNOWN for type inference
-    add_library(opentims::opentims_cpp STATIC IMPORTED)
+    add_library(opentims::opentims_cpp UNKNOWN IMPORTED)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmake/Modules/FindOpentims.cmake` around lines 79 - 84, The current
add_library call creates an IMPORTED target with a fixed STATIC type; change the
library type to UNKNOWN by using add_library(opentims::opentims_cpp UNKNOWN
IMPORTED) so CMake can infer shared vs static from the file extension. Update
the add_library invocation that defines the target opentims::opentims_cpp (leave
set_target_properties and IMPORTED_LOCATION / INTERFACE_* properties unchanged)
to ensure type-flexible linking without altering the rest of the target config.

14-19: Config mode hints may explain reported detection failure.

The HINTS only take effect when Opentims_ROOT_DIR is explicitly set. If the user installs OpenTIMS to a non-standard prefix without setting this variable, find_package(opentims CONFIG) won't find it unless CMAKE_PREFIX_PATH or opentims_DIR is configured. This likely explains pjones' report that system OpenTIMS wasn't detected.

Consider adding the standard <PackageName>_ROOT variable that CMake 3.12+ searches automatically:

♻️ Suggested improvement for discovery
+# Support both the standard CMake <PackageName>_ROOT variable and custom hint.
+# CMake 3.12+ automatically searches opentims_ROOT, but we also support Opentims_ROOT_DIR.
+if(DEFINED Opentims_ROOT_DIR AND NOT DEFINED opentims_ROOT)
+  set(opentims_ROOT "${Opentims_ROOT_DIR}")
+endif()
+
 # Prefer a CMake config package produced by opentims's own install rules.
 find_package(opentims CONFIG QUIET
   HINTS
     "${Opentims_ROOT_DIR}"
     "${Opentims_ROOT_DIR}/lib/cmake/opentims"
+    "${opentims_ROOT}"
+    "${opentims_ROOT}/lib/cmake/opentims"
 )

Alternatively, update the module documentation to clarify that users should set CMAKE_PREFIX_PATH or opentims_DIR (the standard CMake variable for config mode) to point to their installation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmake/Modules/FindOpentims.cmake` around lines 14 - 19, The current
find_package(opentims CONFIG ...) call only uses HINTS with Opentims_ROOT_DIR
which CMake doesn't consult automatically; update the module so discovery also
uses the standard package root/config variable and common prefix mechanisms: add
support and mentions for opentims_DIR and CMAKE_PREFIX_PATH and, if desired,
check for the conventional <PackageName>_ROOT variable behavior (Opentims_ROOT)
so find_package(opentims CONFIG) will find installs without requiring
Opentims_ROOT_DIR to be manually set; update the FindOpentims.cmake logic and/or
module documentation to reference opentims_DIR and CMAKE_PREFIX_PATH as
supported ways to point to the OpenTIMS installation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmake/Modules/FindOpentims.cmake`:
- Around line 79-84: The current add_library call creates an IMPORTED target
with a fixed STATIC type; change the library type to UNKNOWN by using
add_library(opentims::opentims_cpp UNKNOWN IMPORTED) so CMake can infer shared
vs static from the file extension. Update the add_library invocation that
defines the target opentims::opentims_cpp (leave set_target_properties and
IMPORTED_LOCATION / INTERFACE_* properties unchanged) to ensure type-flexible
linking without altering the rest of the target config.
- Around line 14-19: The current find_package(opentims CONFIG ...) call only
uses HINTS with Opentims_ROOT_DIR which CMake doesn't consult automatically;
update the module so discovery also uses the standard package root/config
variable and common prefix mechanisms: add support and mentions for opentims_DIR
and CMAKE_PREFIX_PATH and, if desired, check for the conventional
<PackageName>_ROOT variable behavior (Opentims_ROOT) so find_package(opentims
CONFIG) will find installs without requiring Opentims_ROOT_DIR to be manually
set; update the FindOpentims.cmake logic and/or module documentation to
reference opentims_DIR and CMAKE_PREFIX_PATH as supported ways to point to the
OpenTIMS installation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96fa66c3-4491-4073-a5dc-fa8348c739ba

📥 Commits

Reviewing files that changed from the base of the PR and between dbd3e9e and a188b1b.

📒 Files selected for processing (4)
  • cmake/Modules/FindOpentims.cmake
  • cmake/cmake_findExternalLibs.cmake
  • src/openms/CMakeLists.txt
  • src/tests/class_tests/openms/CMakeLists.txt
✅ Files skipped from review due to trivial changes (1)
  • src/tests/class_tests/openms/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmake/cmake_findExternalLibs.cmake

michalsta and others added 2 commits April 15, 2026 12:07
…xport

CMake requires every target linked by an exported target to be either an
imported target or present in an export set — even for PRIVATE deps of a
shared library.

When opentims is found as a system install, opentims::opentims_cpp is an
IMPORTED target and no export registration is needed.  When it is built
from source via FetchContent the target is a regular build target, which
triggers:

  export called with target "OpenMS" which requires target "opentims_cpp"
  that is not in any export set.

Fix by calling install_library(opentims_cpp) in the FetchContent path,
which adds the target to OpenMSTargets — the same pattern used by
Evergreen, SQLiteCpp, and other bundled dependencies.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Two issues from code review:

1. The manual-import fallback used `add_library(... STATIC IMPORTED)`.
   Change to `UNKNOWN IMPORTED` so CMake infers shared vs static from the
   file extension rather than assuming static.  The rest of the
   set_target_properties call (IMPORTED_LOCATION, INTERFACE_*) is unchanged.

2. Only Opentims_ROOT_DIR (an OpenMS-specific variable) was listed in the
   hints/docs.  Add opentims_ROOT to the find_path/find_library HINTS in
   the manual-search fallback so the standard CMP0074 package root variable
   is also effective there.  Update the module header to document all
   supported discovery mechanisms: opentims_DIR, opentims_ROOT,
   CMAKE_PREFIX_PATH, and Opentims_ROOT_DIR (legacy).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@michalsta

Copy link
Copy Markdown
Contributor Author

@pjones author bot does some strange things

Have you looked at the commits in this PR? They go back to 2022. The source branch for this PR is really, really weird.

Yes, my bad: i initially started this off master branch, then realised its the wrong one, so I updated to devel but apparently that was not without side effects. I think it's fixed now with the force push.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmake/cmake_findExternalLibs.cmake`:
- Around line 390-394: The PR description still says "Requires OpenTIMS 1.2.0b3"
while the CMake FetchContent_Declare for opentims sets GIT_TAG to v1.2.0b4;
update the PR description to reference v1.2.0b4 (or add a note that 1.2.0b3
remains supported) and confirm compatibility, and if compatibility is required
document it in the PR description so the FetchContent_Declare (opentims /
GIT_TAG) and PR text are consistent.
- Around line 378-384: The condition that injects OpenMS sqlite3 uses
`_opentims_defs MATCHES "NOTFOUND"` which never matches the manual-fallback case
where `_opentims_defs` is set to an empty string; update the if condition in the
block that references `_opentims_defs` and `opentims_FOUND` (the same block that
calls target_include_directories(opentims::opentims_cpp ...) and
target_link_libraries(opentims::opentims_cpp ...)) to also treat an empty-string
`_opentims_defs` as the manual-fallback case (e.g., check `_opentims_defs
STREQUAL ""` in addition to MATCHES "NOTFOUND") so the sqlite3 include/link
injection runs when opentims is not found via config package.
🪄 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: 968f5993-0717-40f5-9327-cf7acb406d55

📥 Commits

Reviewing files that changed from the base of the PR and between e127366 and de75ec9.

📒 Files selected for processing (1)
  • cmake/cmake_findExternalLibs.cmake

Comment thread cmake/cmake_findExternalLibs.cmake Resolved
Comment thread cmake/cmake_findExternalLibs.cmake Resolved
michalsta and others added 2 commits April 15, 2026 12:23
…halsta/OpenMS into fix/opentims-system-install-fallback
install_library() adds opentims_cpp to the install-tree export
(OpenMSTargets via install(EXPORT)), but the build-tree export()
call in export_macros.cmake uses _OPENMS_EXPORT_TARGETS, which is
only populated by openms_register_export_target().

Without this call CMake errors at generate time:
  export called with target "OpenMS" which requires target
  "opentims_cpp" that is not in any export set.

Matches the pattern used by Evergreen and IsoSpec in their
own CMakeLists.txt files.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@jpfeuffer

Copy link
Copy Markdown
Contributor

@pjones The layout looks ok. But what is the layout of the external package? That would be the important one.

The namings are a bit unconventional (_cpp.a, ++/ include dir) but should work. Depends on what is in the .cmake config.

Can you also run OpenMS cmake with --debug-find?

michalsta and others added 2 commits April 15, 2026 13:11
…tchContent path

Two bugs in the FetchContent branch that only manifest on CI (where
opentims is not installed system-wide):

1. BUILD_SHARED_LIBS=true is set in the top-level CMakeLists.txt
   (line 287) before cmake_findExternalLibs.cmake is included.
   Without an explicit override, opentims's CMakeLists.txt would
   produce libopentims_cpp.so instead of libopentims_cpp.a.  The
   shared library lands in _deps/opentims-build/ rather than the
   system library path, so the build-time linker fails with
   "undefined reference to TimsDataHandle" when linking test
   binaries against libOpenMS.so (libopentims_cpp.so's directory
   is not in the test's -L search path).  Fix: save/restore
   BUILD_SHARED_LIBS around FetchContent_MakeAvailable(opentims).

2. target_link_libraries(opentims_cpp PRIVATE sqlite3) links the
   bundled SQLite3 CMake target to the opentims_cpp STATIC library.
   For static library targets, CMake propagates PRIVATE deps into
   the link interface, so the export mechanism requires sqlite3 to
   be in the same export set.  This conflicts with SQLiteCpp's own
   sqlite3 export and causes a CMake generate error.  Fix: provide
   only the sqlite3 include directory (needed for compilation with
   OPENTIMS_LINK_SQLITE_STATICALLY); the sqlite3 symbols are
   resolved at final link time through OpenMS's SQLiteCpp dependency
   (SQLiteCpp PUBLIC-links sqlite3, so libsqlite3.a appears in
   libOpenMS.so's link command after libopentims_cpp.a).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…llback sentinel

FindOpentims.cmake sets INTERFACE_COMPILE_DEFINITIONS to "" on the manually
created UNKNOWN IMPORTED target to signal "found via header/library search,
sqlite linkage unknown".  The previous condition only checked MATCHES "NOTFOUND"
(which CMake sets when get_target_property finds no property), so it never fired
for the empty-string case — skipping the sqlite3 include/link injection for
system installs that lack a CMake config package.

Add OR _opentims_defs STREQUAL "" to catch this case.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@michalsta

Copy link
Copy Markdown
Contributor Author

okay, I think I've managed to coax it into building. The opentims side is done as well, with tag v1.2.0b4 being the one containing necessary changes. Ready for the merge when you are.

@pjones

pjones commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

I needed to test this against the latest commit on opentims to pull in the sqlite_so_handle fix. Everything is working so I think we are good to merge.

Thank you very much @michalsta!!!

@pjones
pjones merged commit cf71232 into OpenMS:develop Apr 15, 2026
11 checks passed
@michalsta
michalsta deleted the fix/opentims-system-install-fallback branch April 15, 2026 13:44
github-actions Bot pushed a commit that referenced this pull request Apr 16, 2026
Add three missing entries for changes merged after the 2026-04-15 sync:
- #9154: BrukerTimsFile spectra marked as CENTROID
- #9148/#9147: system opentims install fallback before FetchContent
- #9151: Bruker DIA MS2 centroiding without denoising (min_support=0)

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 16, 2026
Add three missing entries for changes merged after the 2026-04-15 sync:
- #9154: BrukerTimsFile spectra marked as CENTROID
- #9148/#9147: system opentims install fallback before FetchContent
- #9151: Bruker DIA MS2 centroiding without denoising (min_support=0)

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.

4 participants