cmake: fix exported target
authorChristoph Junghans <junghans@votca.org>
Sat, 4 Apr 2020 01:27:14 +0000 (19:27 -0600)
committerPaul Bauer <paul.bauer.q@gmail.com>
Fri, 10 Apr 2020 05:00:53 +0000 (05:00 +0000)
docs/doxygen/user/usinglibrary.md
docs/release-notes/2021/major/bugs-fixed.rst
src/gromacs/CMakeLists.txt
src/gromacs/InstallLibInfo.cmake
src/gromacs/gromacs-config.cmake.cmakein

index 14bd9ca100134d07b3f66f6b00bf92e0e379accd..2241e680efe3c0692f2071fb80c713fff8a46059 100644 (file)
@@ -173,6 +173,9 @@ compile the \Gromacs headers.</dd>
 <dd>Required compiler flags.</dd>
 </dl>
 
+Additionally an imported target named `Gromacs::libgromacs` is provided and can
+be used with `target_link_libraries(foo PRIVATE Gromacs::libgromacs)`.
+
 Declared macros/functions that can be used for checking for correctness of some
 settings:
 
index 32793b8aaffed66dfd7129fcb5f05f04709d8062..0828fe124620465b0b6d4ebde45570fb43fa2b19 100644 (file)
@@ -7,3 +7,11 @@ Bugs fixed
    Also, please use the syntax :issue:`number` to reference issues on GitLab, without the
    a space between the colon and number!
 
+Fixed exported libgromacs CMake target
+""""""""""""""""""""""""""""""""""""""
+
+Update the exported libgromacs CMake target to not depend on non-
+existing include paths and add GMX_DOUBLE define to interface
+definitions. The target now gets exported into the Gromacs namespace.
+
+:issue:`3468`
index 70ac5ac20a619eb8c8645930afaa909fe20dc2c0..8557464c059713b253b829c6510e29df2a2a1e21 100644 (file)
@@ -348,12 +348,14 @@ endif()
 # for the binary
 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
     install(TARGETS libgromacs
+            COMPONENT libraries
             EXPORT libgromacs
             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-            INCLUDES DESTINATION include
-            COMPONENT libraries)
+            INCLUDES DESTINATION include)
+    target_compile_definitions(libgromacs PUBLIC $<INSTALL_INTERFACE:GMX_DOUBLE=${GMX_DOUBLE_VALUE}>)
+    add_library(Gromacs::libgromacs ALIAS libgromacs)
 endif()
 
 if (NOT GMX_BUILD_MDRUN_ONLY)
index 67a4b5729eda46bf1b06a8c6401d1921a9329d9c..80289a4dd0780ff8dffd941adba0e60944970662 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014,2016,2018,2019, by the GROMACS development team, led by
+# Copyright (c) 2014,2016,2018,2019,2020, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -70,6 +70,7 @@ function (do_cmake_config)
     endif()
     install(EXPORT libgromacs
             FILE ${EXPORT_FILE_NAME}
+            NAMESPACE Gromacs::
             DESTINATION ${GMX_INSTALL_CMAKEPKGDIR}
             COMPONENT libraries)
 
index 98b5c6692c31207170aed6f6e7cbfd3955c7905b..cb7879d510eea7363085e9de8240a44ecac3b4c6 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014,2016,2019, by the GROMACS development team, led by
+# Copyright (c) 2014,2016,2019,2020, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -57,10 +57,14 @@ endif()
 include(${_gmx_import_file})
 unset(_gmx_import_file)
 
-get_target_property(_libs libgromacs INTERFACE_LINK_LIBRARIES)
+get_target_property(_libs Gromacs::libgromacs INTERFACE_LINK_LIBRARIES)
 if (_libs MATCHES "tng_io::tng_io")
     include(CMakeFindDependencyMacro)
-    find_dependency(TNG_IO)
+    find_dependency(TNG_IO REQUIRED)
+endif()
+if (_libs MATCHES "OpenMP::OpenMP_CXX")
+    include(CMakeFindDependencyMacro)
+    find_dependency(OpenMP REQUIRED)
 endif()
 unset(_libs)
 
@@ -73,7 +77,7 @@ foreach (_dir ${_include_dirs})
         list(APPEND GROMACS_INCLUDE_DIRS ${_gmx_root_dir}/${_dir})
     endif()
 endforeach()
-set(GROMACS_LIBRARIES libgromacs)
+set(GROMACS_LIBRARIES Gromacs::libgromacs)
 set(GROMACS_DEFINITIONS @INSTALLED_HEADER_DEFINITIONS@)
 set(GROMACS_IS_DOUBLE @GMX_DOUBLE@)
 if (DEFINED GROMACS_SUFFIX AND NOT "${GROMACS_SUFFIX}" STREQUAL "@GMX_LIBS_SUFFIX@")