Skip to content

Conversation

@jameskermode
Copy link
Member

Summary

Adds CMake package config support so LAMMPS and other CMake projects can use QUIP libraries via find_package(QUIP).

Closes #711

Changes

  • Add cmake/QUIPConfig.cmake.in template that creates imported targets:
    • QUIP::fox, QUIP::libAtoms, QUIP::GAP, QUIP::Potentials, QUIP::Utils
    • QUIP::QUIP (unified interface target)
  • Use Meson's cmake module to generate QUIPConfig.cmake and QUIPConfigVersion.cmake during installation
  • Add install: true to all library definitions so they are installed to the lib directory
  • Update fox and GAP submodules to include install: true

Usage

After building and installing QUIP with Meson:

meson setup builddir -Dgap=true
meson compile -C builddir
meson install -C builddir

CMake projects can then use:

find_package(QUIP REQUIRED)
target_link_libraries(myapp QUIP::QUIP)

Submodule PRs

This PR depends on corresponding changes in the submodules:

Test plan

  • meson setup succeeds with -Dgap=true
  • meson install installs all libraries and CMake config files
  • Test CMake project can find_package(QUIP) and access all variables/targets

🤖 Generated with Claude Code

Enable LAMMPS and other CMake projects to use QUIP libraries via
CMake's find_package() mechanism.

Changes:
- Add cmake/QUIPConfig.cmake.in template that creates imported targets
  (QUIP::fox, QUIP::libAtoms, QUIP::GAP, QUIP::Potentials, QUIP::Utils,
  QUIP::QUIP) for CMake consumers
- Use Meson's cmake module to generate QUIPConfig.cmake and
  QUIPConfigVersion.cmake during installation
- Add install: true to all library definitions so they are installed
  to the lib directory
- Update fox and GAP submodules to include install: true

After installation, CMake projects can use:
  find_package(QUIP REQUIRED)
  target_link_libraries(myapp QUIP::QUIP)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jameskermode
Copy link
Member Author

Tested and this should work with the LAMMPS QUIP plugin.

LAMMPS's cmake/Modules/Packages/ML-QUIP.cmake needs modification to support Meson-built QUIP. The change is to use CONFIG mode first (for Meson-built QUIP) before falling back to MODULE mode (for legacy Make-built libquip.a):

enable_language(Fortran)
-find_package(QUIP QUIET)
+
+# Try to find QUIP - first via CMake config files (Meson-built QUIP),
+# then via legacy FindQUIP module (Make-built libquip.a)
+find_package(QUIP QUIET CONFIG)
+if(NOT QUIP_FOUND)
+  find_package(QUIP QUIET MODULE)
+endif()

 if(QUIP_FOUND)
...
 else()
-  find_package(QUIP REQUIRED)
+  # QUIP was already found at the top of this file, just link it
+  if(NOT QUIP_FOUND)
+    find_package(QUIP QUIET CONFIG)
+    if(NOT QUIP_FOUND)
+      find_package(QUIP REQUIRED MODULE)
+    endif()
+  endif()
   target_link_libraries(lammps PRIVATE QUIP::QUIP ${LAPACK_LIBRARIES})
 endif()

This change is backward compatible - it will still work with legacy Make-built QUIP if no CMake config files are found.

@bernstei if you would be willing to test this works for you too then we can think about whether/how to update LAMMPS.

@bernstei
Copy link
Contributor

@bernstei if you would be willing to test this works for you too then we can think about whether/how to update LAMMPS.

do you mean just as a test on an independent setup? Because the only thing I ever do with cmake is compile lammps

@jameskermode
Copy link
Member Author

Yes, just test the LAMMPS + QUIPS compilation with this branch independently. As you can see I got some AI coding assistance with the CMake/Meson bridge. I've run in manually myself but a second pair of eyes would be good.

@bernstei
Copy link
Contributor

bernstei commented Jan 29, 2026

Yes, just test the LAMMPS + QUIPS compilation with this branch independently. As you can see I got some AI coding assistance with the CMake/Meson bridge. I've run in manually myself but a second pair of eyes would be good.

Sure, I'm happy to test that, but I'm a bit confused as to what exactly I should do.

Do I just grab a recent lammps, make this modification, and everything should work?

How does all this new stuff integrate with the auto download (or clone) and custom arch/Makefile.lammps that the lammps cmake currently creates? Do I need meson available?

@jameskermode
Copy link
Member Author

This will only work with the no-download route for now, and yes you'd need Meson to compile QUIP. We'd need to make more changes in LAMMPS to make it integrate with CMake+Meson QUIP build with the auto download route.

Build and install QUIP with Meson:

  # Clone QUIP with submodules
  git clone --recursive https://github.com/libAtoms/QUIP.git
  cd QUIP

  # Checkout this PR branch
  git checkout cmake-support
  cd src/fox && git checkout cmake-install-support && cd ../..
  cd src/GAP && git checkout cmake-install-support && cd ../..

  # Build and install
  meson setup builddir -Dgap=true
  meson compile -C builddir
  meson install -C builddir --destdir=/tmp/quip-install

Build LAMMPS with the pre-built QUIP:

Apply the ML-QUIP.cmake patch above then:

  cd lammps/cmake
  cmake -B ../build \
    -DPKG_ML-QUIP=yes \
    -DDOWNLOAD_QUIP=no \
    -DCMAKE_PREFIX_PATH=/tmp/quip-install/usr/local
  cmake --build ../build

@bernstei
Copy link
Contributor

I'm happy to test this procedure, assuming I can get meson to work

@bernstei
Copy link
Contributor

Looks like it almost worked

[100%] Linking CXX executable lmp
/home/cluster/bernstei/.local/lib/python3.11/site-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/lmp.dir/link.txt --verbose=1
//home/Software/lammps/src/quip-install/usr/local/lib64/liblibAtoms.so: undefined reference to `f90wrap_abort_'
collect2: error: ld returned 1 exit status
/opt/ohpc/pub/compiler/gcc/12.4.0/bin/c++ -march=native -ffast-math -O3 -DNDEBUG CMakeFiles/lmp.dir/home/Software/lammps/src/lammps_cmake_symmetrix/src/main.cpp.o -o lmp  -Wl,-rpath,/home/Software/lammps/src/lammps_cmake_symmetrix/build_serial_cpu_test_QUIP_cmake:/home/Software/python/miniconda3/lib: liblammps.so.0 /opt/ohpc/pub/compiler/gcc/12.4.0/lib64/libgomp.so /lib64/libpthread.so -Wl,-rpath-link,/home/Software/python/miniconda3/lib:/home/Software/lammps/src/lammps_cmake_symmetrix/build_serial_cpu_test_QUIP_cmake
make[2]: *** [CMakeFiles/lmp.dir/build.make:103: lmp] Error 1
make[2]: Leaving directory '/home/cluster/Software/lammps/src/lammps_cmake_symmetrix/build_serial_cpu_test_QUIP_cmake'
make[1]: *** [CMakeFiles/Makefile2:670: CMakeFiles/lmp.dir/all] Error 2
make[1]: Leaving directory '/home/cluster/Software/lammps/src/lammps_cmake_symmetrix/build_serial_cpu_test_QUIP_cmake'
make: *** [Makefile:136: all] Error 2

@jameskermode
Copy link
Member Author

Ah, I can see why that would happen. The f90wrap_abort_ function is in a separate stub library that's not being linked. On macOS I didn't see this because of -Wl,-undefined,dynamic_lookup, but Linux requires all symbols resolved at link time. Fix coming shortly.

The f90wrap_stub library provides the f90wrap_abort implementation
needed by libAtoms for non-Python usage. On macOS this wasn't caught
because of -Wl,-undefined,dynamic_lookup, but Linux requires all
symbols resolved at link time.

Changes:
- Install libf90wrap_stub.a alongside other libraries
- Add QUIP::f90wrap_stub target to CMake config
- Link f90wrap_stub into libAtoms interface dependencies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jameskermode
Copy link
Member Author

That problem should be fixed now.

@bernstei
Copy link
Contributor

Compiles with the cmake file patch above and the latest commit of this branch. I haven't checked performance.

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.

compile with cmake

3 participants