Remove mdrun-only build configuration
[alexxy/gromacs.git] / src / programs / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team.
5 # Copyright (c) 2015,2016,2018,2019,2020,2021, 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.
9 #
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.
14 #
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.
19 #
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.
24 #
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.
32 #
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.
35
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)
48
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 else()
56     file(GLOB GMX_MAIN_SOURCES gmx.cpp legacymodules.cpp)
57     if(GMX_X11)
58         file(GLOB VIEW_SOURCES view/*.cpp)
59     else()
60         file(GLOB VIEW_SOURCES view/view.cpp)
61     endif()
62     add_library(view_objlib OBJECT ${VIEW_SOURCES})
63     gmx_target_compile_options(view_objlib)
64     target_compile_definitions(view_objlib PRIVATE HAVE_CONFIG_H)
65     target_include_directories(view_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
66     target_link_libraries(view_objlib PRIVATE common legacy_api)
67     # TODO: Explicitly link specific modules.
68     target_link_libraries(view_objlib PRIVATE legacy_modules)
69     add_library(gmx_objlib OBJECT ${GMX_MAIN_SOURCES})
70     target_link_libraries(gmx_objlib PRIVATE common legacy_api)
71     # TODO: Explicitly link specific modules.
72     target_link_libraries(gmx_objlib PRIVATE legacy_modules)
73     target_include_directories(gmx_objlib SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
74     target_include_directories(gmx_objlib SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
75     add_executable(gmx
76         $<TARGET_OBJECTS:gmx_objlib>
77         $<TARGET_OBJECTS:mdrun_objlib>
78         $<TARGET_OBJECTS:view_objlib>)
79     add_executable(Gromacs::gmx ALIAS gmx)
80     gmx_target_compile_options(gmx)
81     target_compile_definitions(gmx PRIVATE HAVE_CONFIG_H)
82     target_link_libraries(gmx PRIVATE
83                           common
84                           libgromacs
85                           ${GMX_COMMON_LIBRARIES}
86                           ${GMX_EXE_LINKER_FLAGS})
87     if(GMX_X11)
88         target_link_libraries(gmx ${X11_LIBRARIES})
89     endif()
90     set(BINARY_NAME "gmx${GMX_BINARY_SUFFIX}")
91     set_target_properties(gmx PROPERTIES
92         OUTPUT_NAME "${BINARY_NAME}")
93     # Add the executable to the INSTALL target and to the libgromacs EXPORT configuration.
94     # The GROMACS installation then provides an importable (e.g. find_package(GROMACS))
95     # Gromacs::gmx target, which may be used as the executable COMMAND argument for functions like
96     # add_custom_command() or add_test(). The full path to the installed binary may retrieved
97     # from the LOCATION property or with a $<TARGET_FILE:Gromacs:gmx> generator expression
98     # (where generator expressions are allowed).
99     install(TARGETS gmx
100             EXPORT libgromacs
101             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
102
103     ########################
104     # Completion generation
105
106     include(gmxCustomCommandUtilities)
107
108     set(COMPLETION_DIR ${CMAKE_CURRENT_SOURCE_DIR}/completion)
109     # Using GMX_BUILD_HELP here is somewhat confusing, but the conditions when
110     # this can be done are exactly the same (ability to run the compiled
111     # binaries).
112     if (GMX_BUILD_HELP)
113         gmx_add_custom_output_target(completion OUTPUT STAMP
114             COMMAND ${CMAKE_COMMAND}
115                 -D GMX_EXECUTABLE=$<TARGET_FILE:gmx>
116                 -D ERRORS_ARE_FATAL=${GMX_BUILD_HELP_FORCE}
117                 -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
118             WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
119             DEPENDS gmx ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
120             COMMENT "Generating command-line completions for programs")
121         set_target_properties(completion PROPERTIES EXCLUDE_FROM_ALL OFF)
122         set_directory_properties(PROPERTIES
123             ADDITIONAL_MAKE_CLEAN_FILES "completion")
124         set(COMPLETION_DIR ${CMAKE_CURRENT_BINARY_DIR}/completion)
125     endif()
126     if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
127         install(DIRECTORY ${COMPLETION_DIR}/
128                 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime OPTIONAL)
129         file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
130              "complete -o nospace -F _gmx_compl ${BINARY_NAME}")
131         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
132                 DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime)
133     endif()
134     gmx_cpack_add_generated_source_directory(completion)
135
136     if(BUILD_TESTING)
137         add_subdirectory(mdrun/tests)
138     endif()
139 endif()