Add Flake8 linting to gmxapi tests.
[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,2019, 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             tpr.cpp
65             )
66 gmx_target_compile_options(gmxapi)
67 target_compile_definitions(gmxapi PRIVATE HAVE_CONFIG_H)
68 target_include_directories(gmxapi SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
69
70 # Define public interface. Make sure targets linking against `gmxapi` in the build
71 # system don't accidentally have the implementation headers (this directory))
72 # in a default include path.
73 target_include_directories(gmxapi PUBLIC
74                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
75                            $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
76                            $<INSTALL_INTERFACE:include>
77                            )
78 # Define implementation interface
79 target_include_directories(gmxapi PRIVATE
80                            ${CMAKE_CURRENT_SOURCE_DIR}
81                            )
82
83 ###############################
84 # Install the public interface.
85 #
86 # If any item begins in a generator expression it must evaluate to a full path,
87 # so we can't just use something like $<TARGET_PROPERTIES:gmxapiPublicHeaders,SOURCES>.
88 # Instead, we use a canonical list defined in the parent scope.
89 install(DIRECTORY include/gmxapi
90         DESTINATION include)
91 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/gmxapi/version.h
92         DESTINATION include/gmxapi)
93
94 # Ref. https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
95 # use, i.e. don't skip the full RPATH for the build tree
96 set_target_properties(gmxapi PROPERTIES SKIP_BUILD_RPATH FALSE)
97
98 # when building, don't use the install RPATH already
99 # (but later on when installing)
100 set_target_properties(gmxapi PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE)
101
102 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
103     # Instruct a linking client to use its RPATH to resolve the libgmxapi location.
104     set_target_properties(gmxapi PROPERTIES INSTALL_NAME_DIR "@rpath")
105 endif()
106
107 set_target_properties(gmxapi PROPERTIES
108                       INSTALL_RPATH_USE_LINK_PATH TRUE
109                       SOVERSION ${GMXAPI_MAJOR}
110                       VERSION ${GMXAPI_RELEASE}
111                       )
112
113 target_link_libraries(gmxapi PRIVATE libgromacs)
114
115
116 ################################################
117 # Install and export gmxapi and Gromacs::gmxapi.
118 #
119 # Install the gmxapi target and simultaneously define the export target for
120 # which CMake will create a helper file. Specify the directory for clients to
121 # add to their include path to be able to `#include "gmxapi/some_header.h"`
122 install(TARGETS gmxapi
123         EXPORT gmxapi
124         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
125         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
126         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
127         INCLUDES DESTINATION include
128         )
129
130 # Create the CMake exports file to help other projects build against libgmxapi
131 # as a CMake import target Gromacs::gmxapi.
132 install(EXPORT gmxapi
133         NAMESPACE Gromacs::
134         DESTINATION share/cmake/gmxapi/
135         )
136 add_library(Gromacs::gmxapi ALIAS gmxapi )
137
138 include(CMakePackageConfigHelpers)
139
140 configure_package_config_file(
141     cmake/gmxapi-config.cmake.in
142     "${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake"
143     INSTALL_DESTINATION share/cmake/gmxapi/
144 )
145 write_basic_package_version_file(
146     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
147     VERSION ${GMXAPI_RELEASE}
148     COMPATIBILITY SameMajorVersion
149 )
150
151 install(
152     FILES
153     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config-version.cmake
154     ${CMAKE_CURRENT_BINARY_DIR}/cmake/gmxapi-config.cmake
155     DESTINATION share/cmake/gmxapi/
156 )
157
158 # We need a CMake target to provide the internal interface(s) of the gmxapi
159 # library implementation.
160 add_library(gmxapi-detail INTERFACE)
161 target_include_directories(gmxapi-detail
162                            INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
163
164 if(BUILD_TESTING)
165     add_subdirectory(tests)
166     add_subdirectory(workflow/tests)
167 endif()