1fcf9b69ec88d1e96c6723e59890ffddbf91f8e6
[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,2021, 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 3)
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 PRIVATE MPI::MPI_CXX)
73         # If clients also need to link this target, we need to provide help in gmxapi-config.cmake
74         set(_gmxapi_find_dependencies "find_dependency(MPI COMPONENTS CXX)")
75     else()
76         message(FATAL_ERROR "Building gmxapi for MPI-enabled GROMACS, but no MPI toolchain found.")
77     endif ()
78 elseif(GMX_THREAD_MPI)
79     # GROMACS is built with its internal thread-MPI implementation.
80     set(_gmx_mpi_type "tmpi")
81 else()
82     # GROMACS is built without MPI or thread-MPI.
83     set(_gmx_mpi_type "none")
84 endif ()
85 define_property(TARGET PROPERTY MPI
86                 BRIEF_DOCS "MPI capability of the GROMACS library."
87                 FULL_DOCS "Values of 'library', 'tmpi', or 'none' indicate the configure-time options of the GROMACS
88                  library build.")
89 set_target_properties(gmxapi PROPERTIES
90                       MPI ${_gmx_mpi_type})
91 unset(_gmx_mpi_type)
92
93 ##########################
94 # Define public interface.
95 #
96 # The include directory should be mostly empty so that we can use it internally as
97 # the public interface include directory during build and testing.
98 configure_file(include/gmxapiversion.h.in include/gmxapi/version.h)
99 configure_file(include/resourceassignment.cmakein.h include/gmxapi/mpi/resourceassignment.h)
100 target_include_directories(gmxapi PUBLIC
101                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
102                            $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
103                            $<INSTALL_INTERFACE:include>
104                            )
105
106 add_subdirectory(cpp)
107
108 ###############################
109 # Install the public interface.
110 #
111 # If any item begins in a generator expression it must evaluate to a full path,
112 # so we can't just use something like $<TARGET_PROPERTIES:gmxapiPublicHeaders,SOURCES>.
113 # Instead, we use a canonical list defined in the parent scope.
114
115 # Install public header directories.
116 install(DIRECTORY include/gmxapi
117         DESTINATION include)
118
119 # Install "configured" files from the build tree.
120 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/version.h
121         DESTINATION include/gmxapi)
122 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/mpi/resourceassignment.h
123         DESTINATION include/gmxapi/mpi)
124