Normalize API tests.
[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,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 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 # TODO: Explicitly link specific modules: mdlib, mdtypes, utility, commandline
89 target_link_libraries(gmxapi PRIVATE legacy_modules)
90
91
92 ################################################
93 # Install and export gmxapi and Gromacs::gmxapi.
94 #
95 # Install the gmxapi target and simultaneously define the export target for
96 # which CMake will create a helper file. Specify the directory for clients to
97 # add to their include path to be able to `#include "gmxapi/some_header.h"`
98 install(TARGETS gmxapi
99         EXPORT gmxapi
100         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
101         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
102         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
103         INCLUDES DESTINATION include
104         )
105
106 # Create the CMake exports file to help other projects build against libgmxapi
107 # as a CMake import target Gromacs::gmxapi.
108 install(EXPORT gmxapi
109         NAMESPACE Gromacs::
110         DESTINATION share/cmake/gmxapi/
111         )
112 add_library(Gromacs::gmxapi ALIAS gmxapi )
113
114 include(CMakePackageConfigHelpers)
115
116 get_target_property(_mpi Gromacs::gmxapi MPI)
117 configure_package_config_file(
118     cmake/gmxapi-config.cmake.in
119     "${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake"
120     INSTALL_DESTINATION share/cmake/gmxapi/
121 )
122 unset(_mpi)
123 get_target_property(GMXAPI_RELEASE gmxapi RELEASE)
124 write_basic_package_version_file(
125     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
126     VERSION ${GMXAPI_RELEASE}
127     COMPATIBILITY SameMajorVersion
128 )
129
130 install(
131     FILES
132     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
133     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake
134     DESTINATION share/cmake/gmxapi/
135 )
136
137 # We need a CMake target to provide the internal interface(s) of the gmxapi
138 # library implementation.
139 add_library(gmxapi-detail INTERFACE)
140 target_include_directories(gmxapi-detail
141                            INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
142
143 if (BUILD_TESTING AND GMX_BUILD_UNITTESTS)
144     add_subdirectory(tests)
145     add_subdirectory(workflow/tests)
146 endif()