2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team.
5 # Copyright (c) 2015,2016,2018,2019,2020, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
36 file(GLOB MDRUN_SOURCES mdrun/*.cpp)
37 # make an "object library" that we can re-use for multiple targets
38 add_library(mdrun_objlib OBJECT ${MDRUN_SOURCES})
39 gmx_target_compile_options(mdrun_objlib)
40 target_compile_definitions(mdrun_objlib PRIVATE HAVE_CONFIG_H)
41 target_include_directories(mdrun_objlib SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
42 # Should be possible to remove this when resolving #3290
43 target_include_directories(mdrun_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
46 # The lack of a real source file here alongside the object library
47 # may break some generators, according to CMake documentation. If
48 # so, we can consider adding some dummy file to make it work.
49 add_library(fahcore $<TARGET_OBJECTS:mdrun_objlib>)
50 target_link_libraries(fahcore PRIVATE ${GMX_COMMON_LIBRARIES})
51 elseif(GMX_BUILD_MDRUN_ONLY)
52 message(STATUS "The mdrun-only build is deprecated")
53 add_executable(mdrun $<TARGET_OBJECTS:mdrun_objlib> mdrun_main.cpp)
54 gmx_target_compile_options(mdrun)
55 target_include_directories(mdrun SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
56 target_compile_definitions(mdrun PRIVATE HAVE_CONFIG_H)
57 target_link_libraries(mdrun libgromacs
58 ${GMX_COMMON_LIBRARIES}
59 ${GMX_EXE_LINKER_FLAGS})
60 set(BINARY_NAME "mdrun${GMX_BINARY_SUFFIX}")
61 set_target_properties(mdrun PROPERTIES
62 OUTPUT_NAME "${BINARY_NAME}")
63 install(TARGETS mdrun DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT mdrun)
64 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
65 "complete -o nospace -F _gmx_mdrun_compl ${BINARY_NAME}")
66 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
67 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime)
69 file(GLOB GMX_MAIN_SOURCES gmx.cpp legacymodules.cpp)
71 file(GLOB VIEW_SOURCES view/*.cpp)
73 file(GLOB VIEW_SOURCES view/view.cpp)
75 add_library(view_objlib OBJECT ${VIEW_SOURCES})
76 gmx_target_compile_options(view_objlib)
77 target_compile_definitions(view_objlib PRIVATE HAVE_CONFIG_H)
78 target_include_directories(view_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
79 add_library(gmx_objlib OBJECT ${GMX_MAIN_SOURCES})
80 target_include_directories(gmx_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
81 target_include_directories(gmx_objlib SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
83 $<TARGET_OBJECTS:gmx_objlib>
84 $<TARGET_OBJECTS:mdrun_objlib>
85 $<TARGET_OBJECTS:view_objlib>)
86 add_executable(Gromacs::gmx ALIAS gmx)
87 gmx_target_compile_options(gmx)
88 target_compile_definitions(gmx PRIVATE HAVE_CONFIG_H)
89 target_link_libraries(gmx libgromacs
90 ${GMX_COMMON_LIBRARIES}
91 ${GMX_EXE_LINKER_FLAGS})
93 target_link_libraries(gmx ${X11_LIBRARIES})
95 set(BINARY_NAME "gmx${GMX_BINARY_SUFFIX}")
96 set_target_properties(gmx PROPERTIES
97 OUTPUT_NAME "${BINARY_NAME}")
98 # Add the executable to the INSTALL target and to the libgromacs EXPORT configuration.
99 # The GROMACS installation then provides an importable (e.g. find_package(GROMACS))
100 # Gromacs::gmx target, which may be used as the executable COMMAND argument for functions like
101 # add_custom_command() or add_test(). The full path to the installed binary may retrieved
102 # from the LOCATION property or with a $<TARGET_FILE:Gromacs:gmx> generator expression
103 # (where generator expressions are allowed).
106 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
108 ########################
109 # Completion generation
111 include(gmxCustomCommandUtilities)
113 set(COMPLETION_DIR ${CMAKE_CURRENT_SOURCE_DIR}/completion)
114 # Using GMX_BUILD_HELP here is somewhat confusing, but the conditions when
115 # this can be done are exactly the same (ability to run the compiled
118 gmx_add_custom_output_target(completion OUTPUT STAMP
119 COMMAND ${CMAKE_COMMAND}
120 -D GMX_EXECUTABLE=$<TARGET_FILE:gmx>
121 -D ERRORS_ARE_FATAL=${GMX_BUILD_HELP_FORCE}
122 -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
123 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
124 DEPENDS gmx ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
125 COMMENT "Generating command-line completions for programs")
126 set_target_properties(completion PROPERTIES EXCLUDE_FROM_ALL OFF)
127 set_directory_properties(PROPERTIES
128 ADDITIONAL_MAKE_CLEAN_FILES "completion")
129 set(COMPLETION_DIR ${CMAKE_CURRENT_BINARY_DIR}/completion)
131 if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
132 install(DIRECTORY ${COMPLETION_DIR}/
133 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime OPTIONAL)
134 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
135 "complete -o nospace -F _gmx_compl ${BINARY_NAME}")
136 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
137 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime)
139 gmx_cpack_add_generated_source_directory(completion)
142 add_subdirectory(mdrun/tests)