From ba27ecf6102b17d1f92037e488effbcad279cd77 Mon Sep 17 00:00:00 2001 From: rohskopf Date: Mon, 3 Oct 2022 11:53:41 -0600 Subject: [PATCH 01/12] Add optional full flag to pair_zero --- src/pair_zero.cpp | 30 ++++++++++++++++++++++++++++-- src/pair_zero.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/pair_zero.cpp b/src/pair_zero.cpp index 83505edd35..e253cd2aa5 100644 --- a/src/pair_zero.cpp +++ b/src/pair_zero.cpp @@ -21,6 +21,8 @@ #include "comm.h" #include "error.h" #include "memory.h" +#include "neigh_list.h" +#include "neighbor.h" #include @@ -34,6 +36,7 @@ PairZero::PairZero(LAMMPS *lmp) : Pair(lmp) writedata = 1; single_enable = 1; respa_enable = 1; + fullneighflag = 0; } /* ---------------------------------------------------------------------- */ @@ -85,12 +88,23 @@ void PairZero::allocate() void PairZero::settings(int narg, char **arg) { - if ((narg != 1) && (narg != 2)) error->all(FLERR, "Illegal pair_style command"); + if ((narg != 1) && (narg != 2) && (narg != 3)) error->all(FLERR, "Illegal pair_style command"); cut_global = utils::numeric(FLERR, arg[0], false, lmp); - if (narg == 2) { + + if (narg == 2){ if (strcmp("nocoeff", arg[1]) == 0) coeffflag = 0; + else if(strcmp("full", arg[1]) == 0) + fullneighflag = 1; + else + error->all(FLERR, "Illegal pair_style command"); + } + else if (narg == 3) { + if (strcmp("nocoeff", arg[1]) == 0 || strcmp("nocoeff", arg[2]) == 0) + coeffflag = 0; + else if(strcmp("full", arg[1]) == 0 || strcmp("full", arg[2]) == 0) + fullneighflag = 1; else error->all(FLERR, "Illegal pair_style command"); } @@ -134,6 +148,18 @@ void PairZero::coeff(int narg, char **arg) if (count == 0) error->all(FLERR, "Incorrect args for pair coefficients"); } +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairZero::init_style() +{ + if (fullneighflag == 0) + neighbor->add_request(this, NeighConst::REQ_DEFAULT); + else + neighbor->add_request(this, NeighConst::REQ_FULL); +} + /* ---------------------------------------------------------------------- init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ diff --git a/src/pair_zero.h b/src/pair_zero.h index 03b6d096a1..10102f1cad 100644 --- a/src/pair_zero.h +++ b/src/pair_zero.h @@ -42,6 +42,7 @@ class PairZero : public Pair { void compute_outer(int, int) override; void settings(int, char **) override; void coeff(int, char **) override; + void init_style() override; double init_one(int, int) override; void write_restart(FILE *) override; void read_restart(FILE *) override; @@ -55,6 +56,7 @@ class PairZero : public Pair { double cut_global; double **cut; int coeffflag; + int fullneighflag; // 0 for half list, 1 for full list virtual void allocate(); }; From c82fdd4898719dadca4ffc72746e1a5acaeefa3b Mon Sep 17 00:00:00 2001 From: rohskopf Date: Mon, 3 Oct 2022 11:57:47 -0600 Subject: [PATCH 02/12] Add docs --- doc/src/pair_zero.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/src/pair_zero.rst b/doc/src/pair_zero.rst index 062b5204f8..0e6bac643a 100644 --- a/doc/src/pair_zero.rst +++ b/doc/src/pair_zero.rst @@ -8,11 +8,12 @@ Syntax .. code-block:: LAMMPS - pair_style zero cutoff [nocoeff] + pair_style zero cutoff [nocoeff] [full] * zero = style name of this pair style * cutoff = global cutoff (distance units) * nocoeff = ignore all pair_coeff parameters (optional) +* full = build full neighbor list (optional) Examples """""""" @@ -45,6 +46,9 @@ section for any pair style. Similarly, any pair_coeff commands will only be checked for the atom type numbers and the rest ignored. In this case, only the global cutoff will be used. +The optional *full* flag builds a full neighbor list instead of the default +half neighbor list. + The following coefficients must be defined for each pair of atoms types via the :doc:`pair_coeff ` command as in the examples above, or in the data file or restart files read by the From 981f75d92fa685b25d5f2828dc3c3635910fa8c8 Mon Sep 17 00:00:00 2001 From: rohskopf Date: Mon, 3 Oct 2022 12:40:05 -0600 Subject: [PATCH 03/12] Example in docs --- doc/src/Python_neighbor.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/src/Python_neighbor.rst b/doc/src/Python_neighbor.rst index 00c4cc8996..8201955b6c 100644 --- a/doc/src/Python_neighbor.rst +++ b/doc/src/Python_neighbor.rst @@ -38,6 +38,40 @@ using the NumPy access method. for n in np.nditer(nlist): print(" atom {} with ID {}".format(n,tags[n])) +Another example for extracting a full neighbor list without evaluating a +potential is shown below. + +.. code-block:: python + + from lammps import lammps + import numpy as np + + lmp = lammps() + lmp.commands_string(""" + newton off + region box block -2 2 -2 2 -2 2 + lattice fcc 1.0 + create_box 1 box + create_atoms 1 box + mass 1 1.0 + pair_style zero 1.0 full + pair_coeff * * + run 0 post no""") + + # look up the neighbor list + nlidx = lmp.find_pair_neighlist('zero') + nl = lmp.numpy.get_neighlist(nlidx) + tags = lmp.extract_atom('id') + print("full neighbor list with {} entries".format(nl.size)) + # print neighbor list contents + for i in range(0,nl.size): + idx, nlist = nl.get(i) + print("\natom {} with ID {} has {} neighbors:".format(idx,tags[idx],nlist.size)) + if nlist.size > 0: + for n in np.nditer(nlist): + pass + print(" atom {} with ID {}".format(n,tags[n])) + **Methods:** * :py:meth:`lammps.get_neighlist() `: Get neighbor list for given index From 82bf23401f4747338eacc3d5c2d94ece012d8ab3 Mon Sep 17 00:00:00 2001 From: rohskopf Date: Mon, 3 Oct 2022 12:45:18 -0600 Subject: [PATCH 04/12] Fix whitespace --- doc/src/Python_neighbor.rst | 2 +- src/pair_zero.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/Python_neighbor.rst b/doc/src/Python_neighbor.rst index 8201955b6c..755b83da81 100644 --- a/doc/src/Python_neighbor.rst +++ b/doc/src/Python_neighbor.rst @@ -38,7 +38,7 @@ using the NumPy access method. for n in np.nditer(nlist): print(" atom {} with ID {}".format(n,tags[n])) -Another example for extracting a full neighbor list without evaluating a +Another example for extracting a full neighbor list without evaluating a potential is shown below. .. code-block:: python diff --git a/src/pair_zero.cpp b/src/pair_zero.cpp index e253cd2aa5..e4d98ad66e 100644 --- a/src/pair_zero.cpp +++ b/src/pair_zero.cpp @@ -91,7 +91,7 @@ void PairZero::settings(int narg, char **arg) if ((narg != 1) && (narg != 2) && (narg != 3)) error->all(FLERR, "Illegal pair_style command"); cut_global = utils::numeric(FLERR, arg[0], false, lmp); - + if (narg == 2){ if (strcmp("nocoeff", arg[1]) == 0) coeffflag = 0; From 21aded5e4ee6139e9ddefecf8f729f210251cc5b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 15:14:54 -0400 Subject: [PATCH 05/12] silence compiler warning --- src/fix_ave_time.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 3eeed90e2f..bd8ed1468d 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -895,7 +895,7 @@ void FixAveTime::invoke_vector(bigint ntimestep) int FixAveTime::column_length(int dynamic) { - int m,length,lengthone; + int length,lengthone; // determine nrows for static values From 840e3398b8b99aadb5cbe104c1c7a6ce2b323956 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 15:36:19 -0400 Subject: [PATCH 06/12] silence warning with CMake 3.24 and later --- cmake/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 28c3d6c027..8267a9bf91 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -12,6 +12,11 @@ endif() if(POLICY CMP0109) cmake_policy(SET CMP0109 OLD) endif() +# set policy to silence warnings about timestamps of downloaded files. review occasionally if it may be set to NEW +if(POLICY CMP0135) + cmake_policy(SET CMP0135 OLD) +endif() + ######################################## project(lammps CXX) From 2d3e4fdd9a601868cb4e77db4073ac374b9392b1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 15:24:05 -0400 Subject: [PATCH 07/12] make MDI package cmake config compatible with multi-config builders --- cmake/Modules/Packages/MDI.cmake | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmake/Modules/Packages/MDI.cmake b/cmake/Modules/Packages/MDI.cmake index edae4ffcbd..82b036a583 100644 --- a/cmake/Modules/Packages/MDI.cmake +++ b/cmake/Modules/Packages/MDI.cmake @@ -70,23 +70,22 @@ if(DOWNLOAD_MDI) -Dplugins=ON -Dpython_plugins=${MDI_USE_PYTHON_PLUGINS} UPDATE_COMMAND "" - INSTALL_COMMAND "" - BUILD_BYPRODUCTS "/MDI_Library/libmdi.a" + BUILD_BYPRODUCTS "/${CMAKE_INSTALL_LIBDIR}/mdi/${CMAKE_STATIC_LIBRARY_PREFIX}mdi${CMAKE_STATIC_LIBRARY_SUFFIX}" ) # where is the compiled library? - ExternalProject_get_property(mdi_build BINARY_DIR) - set(MDI_BINARY_DIR "${BINARY_DIR}/MDI_Library") + ExternalProject_get_property(mdi_build INSTALL_DIR) # workaround for older CMake versions - file(MAKE_DIRECTORY ${MDI_BINARY_DIR}) + file(MAKE_DIRECTORY ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/mdi) + file(MAKE_DIRECTORY ${INSTALL_DIR}/include/mdi) # create imported target for the MDI library add_library(LAMMPS::MDI UNKNOWN IMPORTED) add_dependencies(LAMMPS::MDI mdi_build) set_target_properties(LAMMPS::MDI PROPERTIES - IMPORTED_LOCATION "${MDI_BINARY_DIR}/libmdi.a" - INTERFACE_INCLUDE_DIRECTORIES ${MDI_BINARY_DIR} - ) + IMPORTED_LOCATION "${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/mdi/${CMAKE_STATIC_LIBRARY_PREFIX}mdi${CMAKE_STATIC_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include/mdi + ) set(MDI_DEP_LIBS "") # if compiling with python plugins we need From bb6a1180067e6de2639120ff5742ff9dfb492f96 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 16:31:23 -0400 Subject: [PATCH 08/12] refactor for simpler flow of control. apply clang-format. --- src/pair_zero.cpp | 33 ++++++++++++++++----------------- src/pair_zero.h | 4 +--- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/pair_zero.cpp b/src/pair_zero.cpp index e4d98ad66e..b554f78b7f 100644 --- a/src/pair_zero.cpp +++ b/src/pair_zero.cpp @@ -88,25 +88,24 @@ void PairZero::allocate() void PairZero::settings(int narg, char **arg) { - if ((narg != 1) && (narg != 2) && (narg != 3)) error->all(FLERR, "Illegal pair_style command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "pair_style zero", error); cut_global = utils::numeric(FLERR, arg[0], false, lmp); - if (narg == 2){ - if (strcmp("nocoeff", arg[1]) == 0) + // reset to defaults + coeffflag = 1; + fullneighflag = 0; + + int iarg = 1; + while (iarg < narg) { + if (strcmp("nocoeff", arg[iarg]) == 0) { coeffflag = 0; - else if(strcmp("full", arg[1]) == 0) + ++iarg; + } else if (strcmp("full", arg[iarg]) == 0) { fullneighflag = 1; - else - error->all(FLERR, "Illegal pair_style command"); - } - else if (narg == 3) { - if (strcmp("nocoeff", arg[1]) == 0 || strcmp("nocoeff", arg[2]) == 0) - coeffflag = 0; - else if(strcmp("full", arg[1]) == 0 || strcmp("full", arg[2]) == 0) - fullneighflag = 1; - else - error->all(FLERR, "Illegal pair_style command"); + ++iarg; + } else + error->all(FLERR, "Unknown pair style zero option {}", arg[iarg]); } // reset cutoffs that have been explicitly set @@ -154,10 +153,10 @@ void PairZero::coeff(int narg, char **arg) void PairZero::init_style() { - if (fullneighflag == 0) - neighbor->add_request(this, NeighConst::REQ_DEFAULT); - else + if (fullneighflag) neighbor->add_request(this, NeighConst::REQ_FULL); + else + neighbor->add_request(this, NeighConst::REQ_DEFAULT); } /* ---------------------------------------------------------------------- diff --git a/src/pair_zero.h b/src/pair_zero.h index 10102f1cad..06d7b2ab72 100644 --- a/src/pair_zero.h +++ b/src/pair_zero.h @@ -56,12 +56,10 @@ class PairZero : public Pair { double cut_global; double **cut; int coeffflag; - int fullneighflag; // 0 for half list, 1 for full list + int fullneighflag; // 0 for half list, 1 for full list virtual void allocate(); }; - } // namespace LAMMPS_NS - #endif #endif From ef3b01f3402cb92ec20902c7c469fdbde2e8b2e9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 18:14:08 -0400 Subject: [PATCH 09/12] add neighbor list access tests. now we can always test for a full list. --- unittest/python/python-commands.py | 69 ++++++++++++++++++++++++++++++ unittest/python/python-numpy.py | 68 +++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index cd77fa21a1..13be27f067 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -209,6 +209,75 @@ create_atoms 1 single & self.assertEqual(idx,i) self.assertEqual(num,nlocal-1) + def testNeighborListZeroHalf(self): + self.lmp.commands_string(""" + boundary f f f + units real + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 + pair_coeff 1 1 + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, num, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(num,nlocal-1-i) + + # look up neighbor list by atom index + num, neighs = nlist.find(2) + self.assertEqual(num,4) + self.assertIsNotNone(neighs,None) + # this one will fail + num, neighs = nlist.find(10) + self.assertEqual(num,-1) + self.assertIsNone(neighs,None) + + def testNeighborListZeroFull(self): + self.lmp.commands_string(""" + boundary f f f + units metal + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 full + pair_coeff * * + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, num, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(num,nlocal-1) + @unittest.skipIf(not has_manybody,"Hybrid neighbor list test for manybody potential") def testNeighborListHybrid(self): self.lmp.commands_string(""" diff --git a/unittest/python/python-numpy.py b/unittest/python/python-numpy.py index 7cbae8e48d..3306aba1cd 100644 --- a/unittest/python/python-numpy.py +++ b/unittest/python/python-numpy.py @@ -412,6 +412,74 @@ class PythonNumpy(unittest.TestCase): idx, neighs = nlist.get(i) self.assertEqual(neighs.size,nlocal-1-i) + def testNeighborListZeroHalf(self): + self.lmp.commands_string(""" + boundary f f f + units real + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 + pair_coeff 1 1 + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.numpy.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(neighs.size,nlocal-1-i) + + # look up neighbor list by atom index + neighs = nlist.find(2) + self.assertEqual(neighs.size,4) + self.assertIsNotNone(neighs,None) + # this one will fail + neighs = nlist.find(10) + self.assertIsNone(neighs,None) + + def testNeighborListZeroFull(self): + self.lmp.commands_string(""" + boundary f f f + units metal + region box block -5 5 -5 5 -5 5 + create_box 1 box + mass 1 1.0 + pair_style zero 4.0 full + pair_coeff * * + """) + x = [ 0.0, 0.0, 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, -1.1, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.1, + 0.0, 0.0, 1.0 ] + tags = [1, 2, 3, 4, 5, 6, 7] + types = [1, 1, 1, 1, 1, 1, 1] + + self.assertEqual(self.lmp.create_atoms(7, id=tags, type=types, x=x), 7) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 7) + + self.lmp.command("run 0 post no") + + self.assertEqual(self.lmp.find_pair_neighlist("zero"),0) + nlist = self.lmp.numpy.get_neighlist(0) + self.assertEqual(nlist.size, 7) + for i in range(0,nlist.size): + idx, neighs = nlist.get(i) + self.assertEqual(idx,i) + self.assertEqual(neighs.size,nlocal-1) + def testNeighborListCompute(self): self.lmp.commands_string(""" boundary f f f From bca8e6b85a06bc62b29b5712bd99cc1189db8898 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Oct 2022 00:14:06 -0400 Subject: [PATCH 10/12] store squared cutoff as documented --- src/MISC/pair_list.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MISC/pair_list.cpp b/src/MISC/pair_list.cpp index f6ac2e3190..be4e2cf92b 100644 --- a/src/MISC/pair_list.cpp +++ b/src/MISC/pair_list.cpp @@ -22,6 +22,7 @@ #include "comm.h" #include "error.h" #include "force.h" +#include "math_special.h" #include "memory.h" #include "text_file_reader.h" @@ -31,6 +32,7 @@ #include using namespace LAMMPS_NS; +using MathSpecial::square; enum { NONE = 0, HARM, MORSE, LJ126 }; @@ -265,7 +267,7 @@ void PairList::settings(int narg, char **arg) break; } if (values.has_next()) - oneparam.cutsq = values.next_double(); + oneparam.cutsq = square(values.next_double()); else oneparam.cutsq = cut_global*cut_global; From 7f90e43d0a31f8ad403d3d5712a760b0e93a158d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Oct 2022 14:34:52 -0400 Subject: [PATCH 11/12] must skip test for pair style list, if MISC package is not available --- unittest/force-styles/test_pair_list.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/force-styles/test_pair_list.cpp b/unittest/force-styles/test_pair_list.cpp index 32a38d8708..9e249613f3 100644 --- a/unittest/force-styles/test_pair_list.cpp +++ b/unittest/force-styles/test_pair_list.cpp @@ -52,6 +52,7 @@ namespace LAMMPS_NS { TEST(PairList, ListVsPairBond) { if (!lammps_config_has_package("MOLECULE")) GTEST_SKIP(); + if (!lammps_config_has_package("MISC")) GTEST_SKIP(); const char *lmpargv[] = {"melt", "-log", "none", "-nocite"}; int lmpargc = sizeof(lmpargv) / sizeof(const char *); From 82d6c1de9927ebb481f15256b8f46fe8317445c3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Oct 2022 15:48:01 -0400 Subject: [PATCH 12/12] recover MDI library build with windows cross-compilation --- cmake/Modules/Packages/MDI.cmake | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/cmake/Modules/Packages/MDI.cmake b/cmake/Modules/Packages/MDI.cmake index 82b036a583..c1e25347af 100644 --- a/cmake/Modules/Packages/MDI.cmake +++ b/cmake/Modules/Packages/MDI.cmake @@ -49,6 +49,14 @@ if(DOWNLOAD_MDI) set(MDI_USE_PYTHON_PLUGINS ON) endif() endif() + # python plugins are not supported and thus must be always off on Windows + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + unset(Python_Development_FOUND) + set(MDI_USE_PYTHON_PLUGINS OFF) + if(CMAKE_CROSSCOMPILING) + set(CMAKE_INSTALL_LIBDIR lib) + endif() + endif() # download/ build MDI library # always build static library with -fpic @@ -57,8 +65,9 @@ if(DOWNLOAD_MDI) ExternalProject_Add(mdi_build URL ${MDI_URL} URL_MD5 ${MDI_MD5} + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/mdi_build_ext CMAKE_ARGS - -DCMAKE_INSTALL_PREFIX= + -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/mdi_build_ext -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} @@ -70,21 +79,22 @@ if(DOWNLOAD_MDI) -Dplugins=ON -Dpython_plugins=${MDI_USE_PYTHON_PLUGINS} UPDATE_COMMAND "" - BUILD_BYPRODUCTS "/${CMAKE_INSTALL_LIBDIR}/mdi/${CMAKE_STATIC_LIBRARY_PREFIX}mdi${CMAKE_STATIC_LIBRARY_SUFFIX}" + INSTALL_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/mdi_build_ext/src/mdi_build-build --target install + BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/mdi_build_ext/${CMAKE_INSTALL_LIBDIR}/mdi/${CMAKE_STATIC_LIBRARY_PREFIX}mdi${CMAKE_STATIC_LIBRARY_SUFFIX}" ) # where is the compiled library? - ExternalProject_get_property(mdi_build INSTALL_DIR) + ExternalProject_get_property(mdi_build PREFIX) # workaround for older CMake versions - file(MAKE_DIRECTORY ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/mdi) - file(MAKE_DIRECTORY ${INSTALL_DIR}/include/mdi) + file(MAKE_DIRECTORY ${PREFIX}/${CMAKE_INSTALL_LIBDIR}/mdi) + file(MAKE_DIRECTORY ${PREFIX}/include/mdi) # create imported target for the MDI library add_library(LAMMPS::MDI UNKNOWN IMPORTED) add_dependencies(LAMMPS::MDI mdi_build) set_target_properties(LAMMPS::MDI PROPERTIES - IMPORTED_LOCATION "${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/mdi/${CMAKE_STATIC_LIBRARY_PREFIX}mdi${CMAKE_STATIC_LIBRARY_SUFFIX}" - INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include/mdi + IMPORTED_LOCATION "${PREFIX}/${CMAKE_INSTALL_LIBDIR}/mdi/${CMAKE_STATIC_LIBRARY_PREFIX}mdi${CMAKE_STATIC_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES ${PREFIX}/include/mdi ) set(MDI_DEP_LIBS "")