Provide common library headers through new CMake target.
[alexxy/gromacs.git] / api / gmxapi / cpp / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2018,2019,2020, 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.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34
35 # This list file provides the Gromacs::gmxapi cmake target.
36
37 target_sources(gmxapi PRIVATE
38                resourceassignment.cpp
39                context.cpp
40                exceptions.cpp
41                gmxapi.cpp
42                md.cpp
43                mdmodule.cpp
44                mdsignals.cpp
45                session.cpp
46                status.cpp
47                system.cpp
48                version.cpp
49                workflow.cpp
50                tpr.cpp
51                )
52 set_target_properties(gmxapi PROPERTIES POSITION_INDEPENDENT_CODE ON)
53 gmx_target_compile_options(gmxapi)
54 target_compile_definitions(gmxapi PRIVATE HAVE_CONFIG_H)
55 target_include_directories(gmxapi SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
56 # Should be possible to change this when resolving #3290
57 target_include_directories(gmxapi SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
58
59 # Define implementation interface
60 target_include_directories(gmxapi PRIVATE
61                            ${CMAKE_CURRENT_SOURCE_DIR}
62                            )
63
64 ###############################
65 # Install the public interface.
66 #
67
68 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
69     # Instruct a linking client to use its RPATH to resolve the libgmxapi location.
70     #
71     # Explicitly specify library "install name" so that the correct loading
72     # instruction is produced in client code. Client code should be able to find the
73     # library relative to the client code RPATH. Without explicitly specifying,
74     # INSTALL_NAME_DIR is inherited from the global CMAKE_INSTALL_NAME_DIR, which is
75     # not appropriate for libgmxapi if it uses an install name relative to the
76     # executable_path or loader_path.
77     set_target_properties(gmxapi PROPERTIES INSTALL_NAME_DIR "@rpath")
78 endif()
79
80 set_target_properties(gmxapi PROPERTIES
81                       OUTPUT_NAME "gmxapi${GMX_LIBS_SUFFIX}"
82                       SOVERSION ${GMXAPI_MAJOR}
83                       VERSION ${GMXAPI_RELEASE}
84                       )
85
86 target_link_libraries(gmxapi PRIVATE libgromacs)
87 target_link_libraries(gmxapi PRIVATE common)
88
89
90 ################################################
91 # Install and export gmxapi and Gromacs::gmxapi.
92 #
93 # Install the gmxapi target and simultaneously define the export target for
94 # which CMake will create a helper file. Specify the directory for clients to
95 # add to their include path to be able to `#include "gmxapi/some_header.h"`
96 install(TARGETS gmxapi
97         EXPORT gmxapi
98         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
99         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
100         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
101         INCLUDES DESTINATION include
102         )
103
104 # Create the CMake exports file to help other projects build against libgmxapi
105 # as a CMake import target Gromacs::gmxapi.
106 install(EXPORT gmxapi
107         NAMESPACE Gromacs::
108         DESTINATION share/cmake/gmxapi/
109         )
110 add_library(Gromacs::gmxapi ALIAS gmxapi )
111
112 include(CMakePackageConfigHelpers)
113
114 get_target_property(_mpi Gromacs::gmxapi MPI)
115 configure_package_config_file(
116     cmake/gmxapi-config.cmake.in
117     "${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake"
118     INSTALL_DESTINATION share/cmake/gmxapi/
119 )
120 unset(_mpi)
121 get_target_property(GMXAPI_RELEASE gmxapi RELEASE)
122 write_basic_package_version_file(
123     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
124     VERSION ${GMXAPI_RELEASE}
125     COMPATIBILITY SameMajorVersion
126 )
127
128 install(
129     FILES
130     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
131     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake
132     DESTINATION share/cmake/gmxapi/
133 )
134
135 # We need a CMake target to provide the internal interface(s) of the gmxapi
136 # library implementation.
137 add_library(gmxapi-detail INTERFACE)
138 target_include_directories(gmxapi-detail
139                            INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})