Skip to content

Commit d48ca25

Browse files
authored
Merge pull request lammps#4209 from akohlmey/plumed-plugin
Add support to build the PLUMED package as a plugin
2 parents 0ad6404 + af5f437 commit d48ca25

15 files changed

+306
-6
lines changed

cmake/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ endif()
1212
if(POLICY CMP0075)
1313
cmake_policy(SET CMP0075 NEW)
1414
endif()
15+
# set policy to silence warnings about requiring execute permission for find_program
16+
# we use OLD because the python-config script for the Fedora MinGW cross-compiler requires it currently
17+
if(POLICY CMP0109)
18+
cmake_policy(SET CMP0109 OLD)
19+
endif()
1520
# set policy to silence warnings about timestamps of downloaded files. review occasionally if it may be set to NEW
1621
if(POLICY CMP0135)
1722
cmake_policy(SET CMP0135 OLD)

cmake/Modules/Packages/ML-PACE.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2023.11.25.fix.tar.gz" CACHE STRING "URL for PACE evaluator library sources")
1+
# PACE library support for ML-PACE package
2+
3+
# set policy to silence warnings about timestamps of downloaded files. review occasionally if it may be set to NEW
4+
if(POLICY CMP0135)
5+
cmake_policy(SET CMP0135 OLD)
6+
endif()
27

8+
set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2023.11.25.fix.tar.gz" CACHE STRING "URL for PACE evaluator library sources")
39
set(PACELIB_MD5 "b45de9a633f42ed65422567e3ce56f9f" CACHE STRING "MD5 checksum of PACE evaluator library tarball")
410
mark_as_advanced(PACELIB_URL)
511
mark_as_advanced(PACELIB_MD5)

cmake/Modules/Packages/PLUMED.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Plumed2 support for PLUMED package
22

3+
# set policy to silence warnings about timestamps of downloaded files. review occasionally if it may be set to NEW
4+
if(POLICY CMP0135)
5+
cmake_policy(SET CMP0135 OLD)
6+
endif()
7+
38
# for supporting multiple concurrent plumed2 installations for debugging and testing
49
set(PLUMED_SUFFIX "" CACHE STRING "Suffix for Plumed2 library")
510
mark_as_advanced(PLUMED_SUFFIX)
@@ -81,6 +86,9 @@ if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND (CMAKE_CROSSCOMPILING))
8186
DEPENDS plumed_build
8287
COMMENT "Copying Plumed files"
8388
)
89+
if(CMAKE_PROJECT_NAME STREQUAL "lammps")
90+
target_link_libraries(lammps INTERFACE LAMMPS::PLUMED)
91+
endif()
8492

8593
else()
8694

@@ -155,6 +163,9 @@ else()
155163
endif()
156164
set_target_properties(LAMMPS::PLUMED PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
157165
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
166+
if(CMAKE_PROJECT_NAME STREQUAL "lammps")
167+
target_link_libraries(lammps PRIVATE LAMMPS::PLUMED)
168+
endif()
158169
else()
159170
find_package(PkgConfig REQUIRED)
160171
pkg_check_modules(PLUMED REQUIRED plumed${PLUMED_SUFFIX})
@@ -169,7 +180,9 @@ else()
169180
endif()
170181
set_target_properties(LAMMPS::PLUMED PROPERTIES INTERFACE_LINK_LIBRARIES "${PLUMED_LOAD}")
171182
set_target_properties(LAMMPS::PLUMED PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PLUMED_INCLUDE_DIRS}")
183+
if(CMAKE_PROJECT_NAME STREQUAL "lammps")
184+
target_link_libraries(lammps PUBLIC LAMMPS::PLUMED)
185+
endif()
172186
endif()
173187
endif()
174188

175-
target_link_libraries(lammps PRIVATE LAMMPS::PLUMED)

doc/src/Build_extras.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,11 @@ in lib/pace or somewhere else, which must be done before building
15171517
LAMMPS with this package. The code for the library can be found
15181518
at: `https://github.com/ICAMS/lammps-user-pace/ <https://github.com/ICAMS/lammps-user-pace/>`_
15191519

1520+
Instead of including the ML-PACE package directly into LAMMPS, it
1521+
is also possible to skip this step and build the ML-PACE package as
1522+
a plugin using the CMake script files in the ``examples/PACKAGE/pace/plugin``
1523+
folder and then load this plugin at runtime with the :doc:`plugin command <plugin>`.
1524+
15201525
.. tabs::
15211526

15221527
.. tab:: CMake build
@@ -1701,6 +1706,11 @@ try a different one, switch to a different build system, consider a
17011706
global PLUMED installation or consider downloading PLUMED during the
17021707
LAMMPS build.
17031708

1709+
Instead of including the PLUMED package directly into LAMMPS, it
1710+
is also possible to skip this step and build the PLUMED package as
1711+
a plugin using the CMake script files in the ``examples/PACKAGE/plumed/plugin``
1712+
folder and then load this plugin at runtime with the :doc:`plugin command <plugin>`.
1713+
17041714
.. tabs::
17051715

17061716
.. tab:: CMake build

doc/src/Developer_plugins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ in the ``examples/kim/plugin`` folder. No changes to the sources of the
283283
KIM package themselves are needed; only the plugin interface and loader
284284
code needs to be added. This example only supports building with CMake,
285285
but is probably a more typical example. To compile you need to run CMake
286-
with -DLAMMPS_SOURCE_DIR=<path/to/lammps/src/folder>. Other
286+
with ``-DLAMMPS_SOURCE_DIR=<path/to/lammps/src/folder>``. Other
287287
configuration setting are identical to those for compiling LAMMPS.
288288

289289
A second example for a plugin from a package is in the

doc/src/Packages_details.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,8 @@ Aidan Thompson^3, Gabor Csanyi^2, Christoph Ortner^4, Ralf Drautz^1.
18231823
**Install:**
18241824

18251825
This package has :ref:`specific installation instructions <ml-pace>` on the
1826-
:doc:`Build extras <Build_extras>` page.
1826+
:doc:`Build extras <Build_extras>` page. This package may also be compiled
1827+
as a plugin to avoid licensing conflicts when distributing binaries.
18271828

18281829
**Supporting info:**
18291830

@@ -2344,7 +2345,9 @@ and Gareth Tribello.
23442345

23452346
**Install:**
23462347

2347-
This package has :ref:`specific installation instructions <plumed>` on the :doc:`Build extras <Build_extras>` page.
2348+
This package has :ref:`specific installation instructions <plumed>` on the
2349+
:doc:`Build extras <Build_extras>` page. This package may also be compiled
2350+
as a plugin to avoid licensing conflicts when distributing binaries.
23482351

23492352
**Supporting info:**
23502353

examples/PACKAGES/pace/plugin/paceplugin.nsis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ InstallDir "$LOCALAPPDATA\${PACEPLUGIN}"
3939

4040
ShowInstDetails show
4141
ShowUninstDetails show
42-
SetCompressor lzma
42+
SetCompressor zlib
4343

4444
!define MUI_ABORTWARNING
4545

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- CMake -*- build system for plugin examples.
2+
# The is meant to be used as a template for plugins that are
3+
# distributed independent from the LAMMPS package.
4+
##########################################
5+
6+
cmake_minimum_required(VERSION 3.16)
7+
8+
project(plumedplugin VERSION 1.0 LANGUAGES CXX)
9+
10+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
11+
include(CheckIncludeFileCXX)
12+
include(LAMMPSInterfacePlugin)
13+
include(PLUMED)
14+
15+
##########################
16+
# building the plugins
17+
18+
add_library(plumedplugin MODULE plumedplugin.cpp ${LAMMPS_SOURCE_DIR}/PLUMED/fix_plumed.cpp)
19+
target_link_libraries(plumedplugin PRIVATE LAMMPS::PLUMED)
20+
target_link_libraries(plumedplugin PRIVATE lammps)
21+
target_include_directories(plumedplugin PRIVATE ${LAMMPS_SOURCE_DIR}/PLUMED)
22+
set_target_properties(plumedplugin PROPERTIES PREFIX "" SUFFIX ".so")
23+
24+
# MacOS seems to need this
25+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
26+
set_target_properties(plumedplugin PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
27+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
28+
# tell CMake to export all symbols to a .dll on Windows with special case for MinGW cross-compilers
29+
set_target_properties(plumedplugin PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
30+
if(CMAKE_CROSSCOMPILING)
31+
set_target_properties(plumedplugin PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols")
32+
endif()
33+
34+
get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION)
35+
find_program(MAKENSIS_PATH makensis)
36+
if(MAKENSIS_PATH)
37+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/lammps.ico
38+
${CMAKE_SOURCE_DIR}/lammps-text-logo-wide.bmp ${CMAKE_SOURCE_DIR}/plumedplugin.nsis
39+
${CMAKE_BINARY_DIR})
40+
if(BUILD_MPI)
41+
if(USE_MSMPI)
42+
add_custom_target(package ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION}-MSMPI plumedplugin.nsis
43+
DEPENDS plumedplugin plumed_copy lammps.ico lammps-text-logo-wide.bmp plumedplugin.nsis
44+
BYPRODUCTS LAMMPS-PLUMED-plugin-${LAMMPS_VERSION}-MSMPI.exe)
45+
else()
46+
add_custom_target(package ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION}-MPI plumedplugin.nsis
47+
DEPENDS plumedplugin plumed_copy lammps.ico lammps-text-logo-wide.bmp plumedplugin.nsis
48+
BYPRODUCTS LAMMPS-PLUMED-plugin-${LAMMPS_VERSION}-MPI.exe)
49+
endif()
50+
else()
51+
add_custom_target(package ${MAKENSIS_PATH} -V1 -DVERSION=${LAMMPS_VERSION} plumedplugin.nsis
52+
COMMAND ${CMAKE_COMMAND} -E echo ${PWD}
53+
DEPENDS plumedplugin plumed_copy lammps.ico lammps-text-logo-wide.bmp plumedplugin.nsis
54+
BYPRODUCTS LAMMPS-PLUMED-plugin-${LAMMPS_VERSION}.exe)
55+
endif()
56+
endif()
57+
else()
58+
set_target_properties(plumedplugin PROPERTIES LINK_FLAGS "-rdynamic")
59+
endif()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../cmake/Modules/LAMMPSInterfacePlugin.cmake
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../cmake/Modules/Packages/PLUMED.cmake

0 commit comments

Comments
 (0)