Fix mdrun-only build
[gromacs.git] / src / programs / CMakeLists.txt
blob56a21bd394fa2b85aab7faa9a50b08c1acfebe90
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)
44 target_link_libraries(mdrun_objlib PRIVATE common)
45 target_link_libraries(mdrun_objlib PRIVATE legacy_api)
46 # TODO: Explicitly link specific modules.
47 target_link_libraries(mdrun_objlib PRIVATE legacy_modules)
49 if(GMX_FAHCORE)
50     # The lack of a real source file here alongside the object library
51     # may break some generators, according to CMake documentation. If
52     # so, we can consider adding some dummy file to make it work.
53     add_library(fahcore $<TARGET_OBJECTS:mdrun_objlib>)
54     target_link_libraries(fahcore PRIVATE ${GMX_COMMON_LIBRARIES} legacy_api)
55 elseif(GMX_BUILD_MDRUN_ONLY)
56     add_executable(mdrun-only $<TARGET_OBJECTS:mdrun_objlib> mdrun_main.cpp)
57     gmx_target_compile_options(mdrun-only)
58     target_include_directories(mdrun-only SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
59     target_compile_definitions(mdrun-only PRIVATE HAVE_CONFIG_H)
60     target_link_libraries(mdrun-only PRIVATE
61                           common
62                           legacy_modules
63                           libgromacs
64                           ${GMX_COMMON_LIBRARIES}
65                           ${GMX_EXE_LINKER_FLAGS}
66                           )
67     set(BINARY_NAME "mdrun${GMX_BINARY_SUFFIX}")
68     set_target_properties(mdrun-only PROPERTIES
69         OUTPUT_NAME "${BINARY_NAME}")
70     install(TARGETS mdrun-only DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT mdrun-only)
71     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
72          "complete -o nospace -F _gmx_mdrun_compl ${BINARY_NAME}")
73     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
74             DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime)
75 else()
76     file(GLOB GMX_MAIN_SOURCES gmx.cpp legacymodules.cpp)
77     if(GMX_X11)
78         file(GLOB VIEW_SOURCES view/*.cpp)
79     else()
80         file(GLOB VIEW_SOURCES view/view.cpp)
81     endif()
82     add_library(view_objlib OBJECT ${VIEW_SOURCES})
83     gmx_target_compile_options(view_objlib)
84     target_compile_definitions(view_objlib PRIVATE HAVE_CONFIG_H)
85     target_include_directories(view_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
86     target_link_libraries(view_objlib PRIVATE common legacy_api)
87     # TODO: Explicitly link specific modules.
88     target_link_libraries(view_objlib PRIVATE legacy_modules)
89     add_library(gmx_objlib OBJECT ${GMX_MAIN_SOURCES})
90     target_link_libraries(gmx_objlib PRIVATE common legacy_api)
91     # TODO: Explicitly link specific modules.
92     target_link_libraries(gmx_objlib PRIVATE legacy_modules)
93     target_include_directories(gmx_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
94     target_include_directories(gmx_objlib SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
95     add_executable(gmx
96         $<TARGET_OBJECTS:gmx_objlib>
97         $<TARGET_OBJECTS:mdrun_objlib>
98         $<TARGET_OBJECTS:view_objlib>)
99     add_executable(Gromacs::gmx ALIAS gmx)
100     gmx_target_compile_options(gmx)
101     target_compile_definitions(gmx PRIVATE HAVE_CONFIG_H)
102     target_link_libraries(gmx PRIVATE
103                           common
104                           libgromacs
105                           ${GMX_COMMON_LIBRARIES}
106                           ${GMX_EXE_LINKER_FLAGS})
107     if(GMX_X11)
108         target_link_libraries(gmx ${X11_LIBRARIES})
109     endif()
110     set(BINARY_NAME "gmx${GMX_BINARY_SUFFIX}")
111     set_target_properties(gmx PROPERTIES
112         OUTPUT_NAME "${BINARY_NAME}")
113     # Add the executable to the INSTALL target and to the libgromacs EXPORT configuration.
114     # The GROMACS installation then provides an importable (e.g. find_package(GROMACS))
115     # Gromacs::gmx target, which may be used as the executable COMMAND argument for functions like
116     # add_custom_command() or add_test(). The full path to the installed binary may retrieved
117     # from the LOCATION property or with a $<TARGET_FILE:Gromacs:gmx> generator expression
118     # (where generator expressions are allowed).
119     install(TARGETS gmx
120             EXPORT libgromacs
121             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
123     ########################
124     # Completion generation
126     include(gmxCustomCommandUtilities)
128     set(COMPLETION_DIR ${CMAKE_CURRENT_SOURCE_DIR}/completion)
129     # Using GMX_BUILD_HELP here is somewhat confusing, but the conditions when
130     # this can be done are exactly the same (ability to run the compiled
131     # binaries).
132     if (GMX_BUILD_HELP)
133         gmx_add_custom_output_target(completion OUTPUT STAMP
134             COMMAND ${CMAKE_COMMAND}
135                 -D GMX_EXECUTABLE=$<TARGET_FILE:gmx>
136                 -D ERRORS_ARE_FATAL=${GMX_BUILD_HELP_FORCE}
137                 -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
138             WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
139             DEPENDS gmx ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
140             COMMENT "Generating command-line completions for programs")
141         set_target_properties(completion PROPERTIES EXCLUDE_FROM_ALL OFF)
142         set_directory_properties(PROPERTIES
143             ADDITIONAL_MAKE_CLEAN_FILES "completion")
144         set(COMPLETION_DIR ${CMAKE_CURRENT_BINARY_DIR}/completion)
145     endif()
146     if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
147         install(DIRECTORY ${COMPLETION_DIR}/
148                 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime OPTIONAL)
149         file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
150              "complete -o nospace -F _gmx_compl ${BINARY_NAME}")
151         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
152                 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime)
153     endif()
154     gmx_cpack_add_generated_source_directory(completion)
156     if(BUILD_TESTING)
157         add_subdirectory(mdrun/tests)
158     endif()
159 endif()