Skip to content

fix(cmake): install DeePMD config for C library builds#5475

Merged
njzjz merged 5 commits into
deepmodeling:masterfrom
njzjz-bothub:fix-5035-cmake-config
May 30, 2026
Merged

fix(cmake): install DeePMD config for C library builds#5475
njzjz merged 5 commits into
deepmodeling:masterfrom
njzjz-bothub:fix-5035-cmake-config

Conversation

@njzjz-bot
Copy link
Copy Markdown
Contributor

@njzjz-bot njzjz-bot commented May 29, 2026

Problem

  • Installing DeePMD-kit against a precompiled libdeepmd_c skipped CMake package config generation.
  • LAMMPS built-in mode then failed at find_package(DeePMD) because no DeePMDConfig.cmake/DeePMDTargets.cmake was installed.

Change

  • Generate DeePMDConfig.cmake for DEEPMD_C_ROOT builds.
  • Install an imported DeePMD::deepmd_c target pointing at the imported C library.
  • Include equivalent package metadata in the packaged libdeepmd_c tarball.

Verification

  • git diff --check
  • Configured a fake precompiled C-library prefix and verified find_package(DeePMD REQUIRED CONFIG) exposes DeePMD::deepmd_c with the expected imported library/include paths.

Fixes #5035

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)

Summary by CodeRabbit

  • Chores
    • Improved C API packaging and CMake config for more reliable discovery and linking.
    • Standardized install layout under lib/cmake/ and added packaged/imported targets for consistent consumption.
    • Enhanced package/version file generation to support builds that include only the C interface.
  • Tests
    • Added a consumer build step to validate the installed package and linking experience.

Review Change Stack

Installing DeePMD-kit from a precompiled C library skipped the CMake package config generation, so LAMMPS built-in mode could not resolve find_package(DeePMD).

Generate DeePMDConfig.cmake and DeePMDTargets.cmake for DEEPMD_C_ROOT builds, and include the same package metadata in the packaged libdeepmd_c tarball.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
@github-actions github-actions Bot added the C label May 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6d737498-cec7-4a3d-8ad6-8bfe40fdb65a

📥 Commits

Reviewing files that changed from the base of the PR and between 1597b76 and 809ce30.

📒 Files selected for processing (3)
  • source/cmake/DeePMDImportedTargets.cmake.in
  • source/cmake/DeePMDPackagedTargets.cmake.in
  • source/install/build_from_c.sh
✅ Files skipped from review due to trivial changes (1)
  • source/cmake/DeePMDImportedTargets.cmake.in
🚧 Files skipped from review as they are similar to previous changes (2)
  • source/cmake/DeePMDPackagedTargets.cmake.in
  • source/install/build_from_c.sh

📝 Walkthrough

Walkthrough

Generates and installs CMake package config/version files into lib/cmake/, adds templates declaring an imported DeePMD C library target, conditions installing an imported-targets file vs exported targets on DEEPMD_C_ROOT, moves include(CMakePackageConfigHelpers) earlier, and adds an install-time consumer verification step.

Changes

CMake Package Configuration for Pre-Compiled C Library

Layer / File(s) Summary
C library target templates
source/cmake/DeePMDImportedTargets.cmake.in, source/cmake/DeePMDPackagedTargets.cmake.in
New templates declare @CMAKE_PROJECT_NAME@::@LIB_DEEPMD_C@ as a shared imported target and set IMPORTED_LOCATION and INTERFACE_INCLUDE_DIRECTORIES for both imported-from-build and packaged-install scenarios.
Package config/version generation and install
source/CMakeLists.txt, source/api_c/CMakeLists.txt, source/cmake/Config.cmake.in
include(CMakePackageConfigHelpers) moved earlier. Root and api_c CMakeLists generate ConfigVersion.cmake, Config.cmake, and packaged targets into lib/cmake/<project>; when DEEPMD_C_ROOT is set they configure+install DeePMDImportedTargets.cmake, otherwise they install exported targets. Config.cmake.in now uses @CMAKE_PROJECT_NAME@ in check_required_components.
Install-time consumer verification
source/install/build_from_c.sh
Install script now creates a temporary CMake consumer project that configures with CMAKE_PREFIX_PATH=${INSTALL_PREFIX}, verifies the DeePMD::deepmd_c target exists (fatal if missing), and builds a minimal executable linking that target.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(cmake): install DeePMD config for C library builds' directly and accurately summarizes the main objective: installing CMake configuration files for C library builds.
Linked Issues check ✅ Passed The PR successfully addresses issue #5035 by generating and installing CMake package config files (DeePMDConfig.cmake, DeePMDTargets.cmake, and imported targets) for DEEPMD_C_ROOT builds, enabling downstream projects like LAMMPS to find and link DeePMD.
Out of Scope Changes check ✅ Passed All changes focus on CMake package configuration generation and installation for C library builds, with no unrelated modifications beyond the scope of fixing issue #5035.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@source/api_c/CMakeLists.txt`:
- Around line 63-74: The PACKAGE_C block in source/api_c/CMakeLists.txt uses
variables config_file, version_file, generated_dir, and targets_export_name that
are only set when BUILD_CPP_IF AND NOT BUILD_PY_IF; either wrap the entire
PACKAGE_C section in the same guard (if(BUILD_CPP_IF AND NOT BUILD_PY_IF) ...
endif) or explicitly initialize those variables (config_file, version_file,
generated_dir, targets_export_name) unconditionally inside the if(PACKAGE_C)
branch so configure_package_config_file(), configure_file(), and install(FILES
...) always have defined values; update the block referencing
configure_package_config_file, configure_file, and install(FILES ...)
accordingly to prevent undefined-variable failures when PACKAGE_C is TRUE but
BUILD_CPP_IF/BUILD_PY_IF differ.

In `@source/cmake/DeePMDImportedTargets.cmake.in`:
- Around line 4-5: The INTERFACE_INCLUDE_DIRECTORIES for the imported target is
pointing to "`@DEEPMD_INCLUDE_C_DIR`@/deepmd" which causes downstream includes
like `#include` <deepmd/c_api.h> to resolve to include/deepmd/deepmd/c_api.h;
change the INTERFACE_INCLUDE_DIRECTORIES value to the install include root
"`@DEEPMD_INCLUDE_C_DIR`@" (leave IMPORTED_LOCATION as "`@deepmd_c`@") and make the
identical adjustment in the packaged-target template so exported consumers get
the correct include root; update the PROPERTIES block that sets
INTERFACE_INCLUDE_DIRECTORIES accordingly.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fb3a563e-178e-41b1-9d32-c6ab11ac9a01

📥 Commits

Reviewing files that changed from the base of the PR and between 93f5580 and 97ed60c.

📒 Files selected for processing (5)
  • source/CMakeLists.txt
  • source/api_c/CMakeLists.txt
  • source/cmake/Config.cmake.in
  • source/cmake/DeePMDImportedTargets.cmake.in
  • source/cmake/DeePMDPackagedTargets.cmake.in

Comment thread source/api_c/CMakeLists.txt Outdated
Comment thread source/cmake/DeePMDImportedTargets.cmake.in Outdated
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
source/cmake/DeePMDPackagedTargets.cmake.in (1)

1-5: ⚡ Quick win

Add a target-existence guard around the imported-library add_library() to prevent duplicate imported-target definitions.

CMake’s install(EXPORT ...)-generated Targets files don’t guarantee an idempotency guard for each imported target; while find_package() typically caches successful results (so repeated calls are less likely to re-include), this hand-written template can still be included directly or under different conditions, which would make add_library(... IMPORTED) fail if DeePMD::deepmd_c already exists. Guarding the declaration is low-cost and removes that risk.

♻️ Wrap the declaration in a target-existence guard
+if(NOT TARGET `@CMAKE_PROJECT_NAME`@::`@LIB_DEEPMD_C`@)
 add_library(`@CMAKE_PROJECT_NAME`@::`@LIB_DEEPMD_C`@ SHARED IMPORTED)
 set_target_properties(
   `@CMAKE_PROJECT_NAME`@::`@LIB_DEEPMD_C`@
   PROPERTIES IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/lib/@CMAKE_SHARED_LIBRARY_PREFIX@@LIB_DEEPMD_C@@CMAKE_SHARED_LIBRARY_SUFFIX@"
              INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include")
+endif()
🤖 Prompt for 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.

In `@source/cmake/DeePMDPackagedTargets.cmake.in` around lines 1 - 5, Wrap the
imported target declaration in a target-existence guard: check if the target
`@CMAKE_PROJECT_NAME`@::`@LIB_DEEPMD_C`@ does not exist before calling
add_library(... IMPORTED) and move the subsequent set_target_properties(...)
(the IMPORTED_LOCATION and INTERFACE_INCLUDE_DIRECTORIES properties) inside that
same guard so you don't attempt to redefine an already-existing imported target;
use CMake's if (NOT TARGET <target>) ... endif() around the add_library and
set_target_properties calls.
🤖 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.

Nitpick comments:
In `@source/cmake/DeePMDPackagedTargets.cmake.in`:
- Around line 1-5: Wrap the imported target declaration in a target-existence
guard: check if the target `@CMAKE_PROJECT_NAME`@::`@LIB_DEEPMD_C`@ does not exist
before calling add_library(... IMPORTED) and move the subsequent
set_target_properties(...) (the IMPORTED_LOCATION and
INTERFACE_INCLUDE_DIRECTORIES properties) inside that same guard so you don't
attempt to redefine an already-existing imported target; use CMake's if (NOT
TARGET <target>) ... endif() around the add_library and set_target_properties
calls.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 76378965-02e3-412f-93fb-79d2ef8fc09b

📥 Commits

Reviewing files that changed from the base of the PR and between 97ed60c and 18a4171.

📒 Files selected for processing (4)
  • source/CMakeLists.txt
  • source/api_c/CMakeLists.txt
  • source/cmake/DeePMDImportedTargets.cmake.in
  • source/cmake/DeePMDPackagedTargets.cmake.in
🚧 Files skipped from review as they are similar to previous changes (2)
  • source/api_c/CMakeLists.txt
  • source/cmake/DeePMDImportedTargets.cmake.in

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.25%. Comparing base (93f5580) to head (809ce30).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5475      +/-   ##
==========================================
- Coverage   82.25%   82.25%   -0.01%     
==========================================
  Files         833      833              
  Lines       89094    89099       +5     
  Branches     4227     4225       -2     
==========================================
+ Hits        73287    73288       +1     
- Misses      14515    14519       +4     
  Partials     1292     1292              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Cover the downstream CMake scenario from issue deepmodeling#5035 by configuring a minimal consumer with find_package(DeePMD REQUIRED CONFIG) against the install prefix and linking DeePMD::deepmd_c.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 `@source/install/build_from_c.sh`:
- Around line 21-23: Several shell variables and command arguments are unquoted
causing word-splitting/globbing (ShellCheck SC2046/SC2086); update usages such
as CONSUMER_TMP_DIR (rm -rf ${CONSUMER_TMP_DIR} and mkdir -p
${CONSUMER_TMP_DIR}), SCRIPT_PATH, INSTALL_PREFIX, BUILD_TMP_DIR, and all
cmake/cmake --build invocations (including -j${NPROC} and any -D...=... args) to
use quoted expansions (e.g., "${CONSUMER_TMP_DIR}", "${SCRIPT_PATH}",
"${INSTALL_PREFIX}", "${BUILD_TMP_DIR}", and quote individual -D values or the
-j argument) so paths with spaces or special chars are safe and to eliminate
ShellCheck warnings.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 90fd3ce6-8da1-45cb-941f-4abcefcbb0a6

📥 Commits

Reviewing files that changed from the base of the PR and between 6dadb2f and 1597b76.

📒 Files selected for processing (1)
  • source/install/build_from_c.sh

Comment thread source/install/build_from_c.sh Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes CMake package discovery for builds that consume a precompiled libdeepmd_c via DEEPMD_C_ROOT, so downstream projects (e.g., LAMMPS built-in mode) can reliably find_package(DeePMD) and link DeePMD::deepmd_c.

Changes:

  • Generate/install DeePMDConfig.cmake + version file for DEEPMD_C_ROOT builds and install a generated targets file that defines an imported DeePMD::deepmd_c.
  • Add templates for imported/packaged DeePMDTargets.cmake generation.
  • Extend the CI-facing build_from_c.sh to build a small consumer project that validates find_package(DeePMD CONFIG) and DeePMD::deepmd_c.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
source/CMakeLists.txt Generate/install CMake package config also for DEEPMD_C_ROOT builds and install generated imported targets file.
source/cmake/Config.cmake.in Fix component-check package name used by the installed config.
source/cmake/DeePMDImportedTargets.cmake.in New template to define an imported DeePMD::deepmd_c for DEEPMD_C_ROOT installs.
source/cmake/DeePMDPackagedTargets.cmake.in New template to define an imported DeePMD::deepmd_c inside the libdeepmd_c tarball layout.
source/api_c/CMakeLists.txt Add generation/installation of config + targets files into the packaged libdeepmd_c staging tree.
source/install/build_from_c.sh Add a consumer CMake build step to validate installed package discovery/target availability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/cmake/DeePMDImportedTargets.cmake.in Outdated
Comment thread source/cmake/DeePMDPackagedTargets.cmake.in Outdated
Guard the hand-written DeePMD::deepmd_c imported target templates so repeated find_package(DeePMD) calls in the same configure step do not attempt to redefine the target.

Also quote path expansions in the C library build test script.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
@njzjz njzjz requested a review from wanghan-iapcm May 30, 2026 12:19
@njzjz njzjz added this pull request to the merge queue May 30, 2026
Merged via the queue into deepmodeling:master with commit 016141f May 30, 2026
70 checks passed
@njzjz njzjz deleted the fix-5035-cmake-config branch May 30, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] No cmake file is generated for LAMMPS, when installing the pre-compiled C library

4 participants