bdfabf97e771ad124ea2f63919c9954a269da06c
[alexxy/gromacs.git] / src / api / cpp / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2018, 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 module.
36
37 ##########################
38 # Set up public interface.
39 #
40 # The parent (src/api/) CMake scope provides a variable named
41 # GMXAPI_PUBLIC_HEADERS containing the full paths to the public
42 # headers that are being installed. The headers are segregated into a
43 # subdirectory here so that their build-time include directory path
44 # does not expose lower level headers.
45
46 add_subdirectory(include)
47
48 # The include directory should be mostly empty so that we can use it internally as
49 # the public interface include directory during build and testing.
50 configure_file(include/version.h.in include/gmxapi/version.h)
51
52 add_library(gmxapi SHARED
53             context.cpp
54             exceptions.cpp
55             gmxapi.cpp
56             md.cpp
57             mdmodule.cpp
58             mdsignals.cpp
59             session.cpp
60             status.cpp
61             system.cpp
62             version.cpp
63             workflow.cpp)
64
65 # Define public interface. Make sure targets linking against `gmxapi` in the build
66 # system don't accidentally have the implementation headers (this directory))
67 # in a default include path.
68 target_include_directories(gmxapi PUBLIC
69                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
70                            $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
71                            $<INSTALL_INTERFACE:include>
72                            )
73 # Define implementation interface
74 target_include_directories(gmxapi PRIVATE
75                            ${CMAKE_CURRENT_SOURCE_DIR}
76                            )
77
78 ###############################
79 # Install the public interface.
80 #
81 # If any item begins in a generator expression it must evaluate to a full path,
82 # so we can't just use something like $<TARGET_PROPERTIES:gmxapiPublicHeaders,SOURCES>.
83 # Instead, we use a canonical list defined in the parent scope.
84 install(DIRECTORY include/gmxapi
85         DESTINATION include)
86 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/version.h
87         DESTINATION include/gmxapi)
88
89 # Ref. https://cmake.org/Wiki/CMake_RPATH_handling
90 # use, i.e. don't skip the full RPATH for the build tree
91 set_target_properties(gmxapi PROPERTIES SKIP_BUILD_RPATH FALSE)
92
93 # when building, don't use the install RPATH already
94 # (but later on when installing)
95 set_target_properties(gmxapi PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE)
96
97 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
98     set_target_properties(gmxapi PROPERTIES INSTALL_NAME_DIR "\@rpath")
99 endif()
100
101 set_target_properties(gmxapi PROPERTIES
102                       INSTALL_RPATH_USE_LINK_PATH TRUE
103                       SOVERSION ${GMXAPI_MAJOR}
104                       VERSION ${GMXAPI_RELEASE}
105                       )
106
107 target_link_libraries(gmxapi PRIVATE libgromacs)
108
109
110 ################################################
111 # Install and export gmxapi and Gromacs::gmxapi.
112 #
113 # Install the gmxapi target and simultaneously define the export target for
114 # which CMake will create a helper file. Specify the directory for clients to
115 # add to their include path to be able to `#include "gmxapi/some_header.h"`
116 install(TARGETS gmxapi
117         EXPORT gmxapi
118         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
119         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
120         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
121         INCLUDES DESTINATION include
122         )
123
124 # Create the CMake exports file to help other projects build against libgmxapi
125 # as a CMake import target Gromacs::gmxapi.
126 install(EXPORT gmxapi
127         NAMESPACE Gromacs::
128         DESTINATION share/cmake/gmxapi/
129         )
130 add_library(Gromacs::gmxapi ALIAS gmxapi )
131
132 include(CMakePackageConfigHelpers)
133
134 configure_package_config_file(
135     cmake/gmxapi-config.cmake.in
136     "${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake"
137     INSTALL_DESTINATION share/cmake/gmxapi/
138 )
139 write_basic_package_version_file(
140     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
141     VERSION ${GMXAPI_RELEASE}
142     COMPATIBILITY SameMajorVersion
143 )
144
145 install(
146     FILES
147     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
148     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake
149     DESTINATION share/cmake/gmxapi/
150 )
151
152 # We need a CMake target to provide the internal interface(s) of the gmxapi
153 # library implementation.
154 add_library(gmxapi-detail INTERFACE)
155 target_include_directories(gmxapi-detail
156                            INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
157
158 if(BUILD_TESTING)
159     add_subdirectory(tests)
160     add_subdirectory(workflow/tests)
161 endif()