2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # This CMakeLists.txt allows source distributions of the gmxapi Python package
36 # to rely on scikit-build for support of various Python packaging systems. The
37 # simplest use case is to allow the `setup.py` file to invoke skbuild to
38 # configure and run CMake. CMake could be invoked directly by the user or a
39 # parent package, but the Python distribution would not be packaged automatically.
40 # Reference https://redmine.gromacs.org/issues/2896 for additional discussion.
41 cmake_minimum_required(VERSION 3.9.6)
43 # This needs to be set before project() in order to pick up toolchain files
44 #list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
46 # OS X deployment target should be >=10.9 for modern C++ compatibility.
47 # Reference https://scikit-build.readthedocs.io/en/latest/generators.html#macosx
48 # and https://github.com/MacPython/wiki/wiki/Spinning-wheels
49 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9 CACHE STRING
50 "OS X deployment target below 10.9 does not use modern standard library"
52 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
53 "OS X should build Python package for 64-bit architecture"
56 project(gmxapi VERSION 0.1.0)
58 set(CMAKE_CXX_STANDARD 14)
59 set(CMAKE_CXX_STANDARD_REQUIRED ON)
61 # Only interpret if() arguments as variables or keywords when unquoted.
62 cmake_policy(SET CMP0054 NEW)
63 # honor the language standard settings for try_compile()
64 cmake_policy(SET CMP0067 NEW)
66 find_package(gmxapi 0.0.8 REQUIRED
67 HINTS "$ENV{GROMACS_DIR}"
71 # GROMACS master branch and development branches may have divergent
72 # pre-release APIs. This check allows us to distinguish them and behave
73 # differently if needed. github.com/kassonlab/gromacs-gmxapi devel branch
74 # sets gmxapi_EXPERIMENTAL=TRUE. Upstream GROMACS master branch does not.
75 # Ref: https://github.com/kassonlab/gmxapi/issues/166
76 if(gmxapi_EXPERIMENTAL)
77 set(_suffix " (unofficial)")
79 message(STATUS "Found gmxapi version ${gmxapi_VERSION}${_suffix}")
82 # TODO: Account for externally-provided pybind headers where recommended by packaging system.
83 # Reference https://redmine.gromacs.org/issues/2896
84 add_subdirectory(external/pybind)
86 set(GMXAPI_PYTHON_EXTENSION_SOURCES
88 gmxapi/export_context.cpp
89 gmxapi/export_system.cpp
94 pybind11_add_module(_gmxapi
95 ${GMXAPI_PYTHON_EXTENSION_SOURCES}
98 target_include_directories(_gmxapi PRIVATE
99 ${CMAKE_CURRENT_SOURCE_DIR}/gmxapi
100 ${CMAKE_CURRENT_BINARY_DIR}/gmxapi
103 # RPATH management: make sure build artifacts can find GROMACS library.
104 set_target_properties(_gmxapi PROPERTIES SKIP_BUILD_RPATH FALSE)
105 set_target_properties(_gmxapi PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
106 set_target_properties(_gmxapi PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
108 target_link_libraries(_gmxapi PRIVATE Gromacs::gmxapi)
110 install(TARGETS _gmxapi LIBRARY DESTINATION gmxapi)
113 # TODO: Determine packaging and installation cases and implementation.
114 # Reference https://redmine.gromacs.org/issues/2896 for additional discussion.
115 message(WARNING "CMake should be run by scikit-build through setup.py for proper Python packaging.")
116 # Try to do something sensible. Collect Python sources as setup.py would.
117 file(GLOB_RECURSE _py_sources CONFIGURE_DEPENDS $CMAKE_CURRENT_SOURCE_DIR/gmxapi/*.py)
118 install(FILES ${_py_sources} DESTINATION gmxapi)