e287816034cea6a983d500728abc24e3bca1c917
[alexxy/gromacs.git] / api / gmxapi / 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 module.
36
37 ##########################
38 # Set up public interface.
39
40 # Note: GROMACS releases have a single-integer monotonic version in GMX_API_VERSION
41 # and LIBRARY_VERSION annotates the shared object for libgromacs. GMXAPI versioning
42 # is not synchronized to releases and may increment faster or slower.
43 #
44 # Prior to 0.1, GMXAPI patch levels are used to mark short term development cycles
45 # and allow compatibility checks for client software of the early releases.
46 #
47 # gmxapi 0.2 will be the first release candidate for gmxapi 1.0 and will attempt
48 # to establish compatibility guarantees consistent with semantic versioning.
49 # (https://semver.org). When the API is deemed suitably stable, gmxapi 1.0 should
50 # be tagged. Official GROMACS releases should be mappable to a distinct gmxapi
51 # release string. For roadmap details, see https://gitlab.com/gromacs/gromacs/-/issues/2585
52 set(GMXAPI_MAJOR 0)
53 set(GMXAPI_MINOR 2)
54 set(GMXAPI_PATCH 0)
55 set(GMXAPI_RELEASE ${GMXAPI_MAJOR}.${GMXAPI_MINOR}.${GMXAPI_PATCH})
56
57 add_library(gmxapi)
58 set_target_properties(gmxapi PROPERTIES
59                       VERSION_MAJOR ${GMXAPI_MAJOR}
60                       VERSION_MINOR ${GMXAPI_MINOR}
61                       VERSION_PATCH ${GMXAPI_PATCH}
62                       RELEASE ${GMXAPI_RELEASE})
63
64
65 if (GMX_LIB_MPI)
66     # GROMACS is built against an MPI library.
67     # Clarification should be possible with resolution of #3672.
68     set(_gmx_mpi_type "library")
69     # Ref https://cmake.org/cmake/help/v3.13/module/FindMPI.html#variables-for-using-mpi
70     find_package(MPI COMPONENTS CXX)
71     if (MPI_CXX_FOUND)
72         target_link_libraries(gmxapi PUBLIC MPI::MPI_CXX)
73     else()
74         message(FATAL_ERROR "Building gmxapi for MPI-enabled GROMACS, but no MPI toolchain found.")
75     endif ()
76 elseif(GMX_THREAD_MPI)
77     # GROMACS is built with its internal thread-MPI implementation.
78     set(_gmx_mpi_type "tmpi")
79 else()
80     # GROMACS is built without MPI or thread-MPI.
81     set(_gmx_mpi_type "none")
82 endif ()
83 define_property(TARGET PROPERTY MPI
84                 BRIEF_DOCS "MPI capability of the GROMACS library."
85                 FULL_DOCS "Values of 'library', 'tmpi', or 'none' indicate the configure-time options of the GROMACS
86                  library build.")
87 set_target_properties(gmxapi PROPERTIES
88                       MPI ${_gmx_mpi_type})
89 unset(_gmx_mpi_type)
90
91 ##########################
92 # Define public interface.
93 #
94 # The include directory should be mostly empty so that we can use it internally as
95 # the public interface include directory during build and testing.
96 configure_file(include/gmxapiversion.h.in include/gmxapi/version.h)
97 configure_file(include/resourceassignment.cmakein.h include/gmxapi/mpi/resourceassignment.h)
98 target_include_directories(gmxapi PUBLIC
99                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
100                            $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
101                            $<INSTALL_INTERFACE:include>
102                            )
103
104 add_subdirectory(cpp)
105
106 ###############################
107 # Install the public interface.
108 #
109 # If any item begins in a generator expression it must evaluate to a full path,
110 # so we can't just use something like $<TARGET_PROPERTIES:gmxapiPublicHeaders,SOURCES>.
111 # Instead, we use a canonical list defined in the parent scope.
112
113 # Install public header directories.
114 install(DIRECTORY include/gmxapi
115         DESTINATION include)
116
117 # Install "configured" files from the build tree.
118 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/version.h
119         DESTINATION include/gmxapi)
120 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/mpi/resourceassignment.h
121         DESTINATION include/gmxapi/mpi)
122