Add GROMACS library dependency to gmxapi package.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Fri, 15 Mar 2019 11:24:53 +0000 (14:24 +0300)
committerEric Irrgang <ericirrgang@gmail.com>
Wed, 10 Apr 2019 14:13:05 +0000 (16:13 +0200)
The `gmxapi` Python package has a C++ extension module configured and
built through CMake. This change links the C++ extension module to the
GROMACS library external interface.

No new code is introduced. This change just establishes that a Python
package can be built, installed, and imported with dynamic linking to
an installed GROMACS library.

Ref: #2912

Change-Id: I1c992c30132df25cf6a91902611cb201962649af

python_packaging/src/CMakeLists.txt

index 1e86e78d10e38c58bde86299b8756630e1ef2905..28660bcaadf80177ac33399ba333668e6940666a 100644 (file)
@@ -63,6 +63,22 @@ cmake_policy(SET CMP0054 NEW)
 # honor the language standard settings for try_compile()
 cmake_policy(SET CMP0067 NEW)
 
+find_package(gmxapi 0.0.8 REQUIRED
+             HINTS "$ENV{GROMACS_DIR}"
+             )
+if(gmxapi_FOUND)
+    set(_suffix "")
+    # GROMACS master branch and development branches may have divergent
+    # pre-release APIs. This check allows us to distinguish them and behave
+    # differently if needed. github.com/kassonlab/gromacs-gmxapi devel branch
+    # sets gmxapi_EXPERIMENTAL=TRUE. Upstream GROMACS master branch does not.
+    # Ref: https://github.com/kassonlab/gmxapi/issues/166
+    if(gmxapi_EXPERIMENTAL)
+        set(_suffix " (unofficial)")
+    endif()
+    message(STATUS "Found gmxapi version ${gmxapi_VERSION}${_suffix}")
+endif()
+
 # TODO: Account for externally-provided pybind headers where recommended by packaging system.
 # Reference https://redmine.gromacs.org/issues/2896
 add_subdirectory(external/pybind)
@@ -80,6 +96,13 @@ target_include_directories(_gmxapi PRIVATE
                            ${CMAKE_CURRENT_BINARY_DIR}/gmxapi
                            )
 
+# RPATH management: make sure build artifacts can find GROMACS library.
+set_target_properties(_gmxapi PROPERTIES SKIP_BUILD_RPATH FALSE)
+set_target_properties(_gmxapi PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
+set_target_properties(_gmxapi PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+target_link_libraries(_gmxapi PRIVATE Gromacs::gmxapi)
+
 install(TARGETS _gmxapi LIBRARY DESTINATION gmxapi)
 
 if(NOT SKBUILD)