| 1 |
find_package(Qt${QT_VERSION} COMPONENTS Widgets Network Concurrent REQUIRED) |
| 2 |
if(QT_VERSION EQUAL 6) |
| 3 |
find_package(Qt6 COMPONENTS OpenGLWidgets REQUIRED) |
| 4 |
endif() |
| 5 |
|
| 6 |
if(WIN32) |
| 7 |
# used for HTTPS (e.g., PQR, downloads, etc.) |
| 8 |
find_package(OpenSSL REQUIRED) |
| 9 |
endif() |
| 10 |
|
| 11 |
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 12 |
|
| 13 |
# Modify the output directory for the build tree. |
| 14 |
set(original_library_output_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") |
| 15 |
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY |
| 16 |
"${original_library_output_dir}/avogadro2/plugins") |
| 17 |
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY |
| 18 |
"${original_library_output_dir}/avogadro2/staticplugins") |
| 19 |
|
| 20 |
# Optionally build all plugins statically. |
| 21 |
option(BUILD_STATIC_PLUGINS "Build static plugins by default" ON) |
| 22 |
|
| 23 |
# Allow GPL plugins to be disabled. |
| 24 |
option(BUILD_GPL_PLUGINS |
| 25 |
"Build plugins that are licensed under the GNU Public License." OFF) |
| 26 |
|
| 27 |
# Create a plugin for Avogadro. |
| 28 |
# name is the name of the plugin, this will be the name of the target created. |
| 29 |
# description Free text description of the plugin. |
| 30 |
# type The base class of the plugin. |
| 31 |
# header is the header(s) for the class to be instantiated for the plugin. |
| 32 |
# pluginClass is the class to be instantiated for the plugin. |
| 33 |
# sources is the list of source files for the plugin. |
| 34 |
# uis is the list of UI files that need to be compiled (optional). |
| 35 |
# rcs is the list of qrc files that need to be compiled (optional). |
| 36 |
function(avogadro_plugin name description type header pluginClass sources) |
| 37 |
set(uis "") |
| 38 |
set(rcs "") |
| 39 |
if(${ARGC} GREATER 6) |
| 40 |
set(uis ${ARGV6}) |
| 41 |
endif() |
| 42 |
if(${ARGC} GREATER 7) |
| 43 |
set(rcs ${ARGV7}) |
| 44 |
endif() |
| 45 |
qt_wrap_ui(ui_srcs ${uis}) |
| 46 |
qt_add_resources(rc_srcs ${rcs}) |
| 47 |
unset(PluginIncludes) |
| 48 |
foreach(_header ${header}) |
| 49 |
set(PluginIncludes |
| 50 |
"${PluginIncludes}#include \"${CMAKE_CURRENT_SOURCE_DIR}/${_header}\"\n") |
| 51 |
endforeach() |
| 52 |
set(PluginName "${name}") |
| 53 |
set(PluginDescription "${description}") |
| 54 |
set(PluginType "${type}") |
| 55 |
set(PluginClass "${pluginClass}") |
| 56 |
configure_file("${AvogadroLibs_SOURCE_DIR}/cmake/avogadroplugin.cpp.in" |
| 57 |
"${CMAKE_CURRENT_BINARY_DIR}/${name}Plugin.cpp") |
| 58 |
|
| 59 |
# Figure out which type of plugin is being added, and put it in the right list |
| 60 |
if(BUILD_STATIC_PLUGINS) |
| 61 |
set(_plugin_object "STATIC") |
| 62 |
set_property(GLOBAL APPEND PROPERTY AvogadroLibs_STATIC_PLUGINS ${name}) |
| 63 |
if(rcs) |
| 64 |
get_filename_component(_name_we ${rcs} NAME_WE) |
| 65 |
set_property(GLOBAL APPEND PROPERTY AvogadroLibs_STATIC_RCS ${_name_we}) |
| 66 |
endif() |
| 67 |
else() |
| 68 |
set(_plugin_object "MODULE") |
| 69 |
set_property(GLOBAL APPEND PROPERTY AvogadroLibs_PLUGINS ${name}) |
| 70 |
endif() |
| 71 |
|
| 72 |
add_library(${name} |
| 73 |
${_plugin_object} |
| 74 |
${sources} |
| 75 |
${ui_srcs} |
| 76 |
${rc_srcs} |
| 77 |
${name}Plugin.cpp |
| 78 |
) |
| 79 |
target_link_libraries(${name} PRIVATE Avogadro::QtGui) |
| 80 |
|
| 81 |
if("${_plugin_object}" STREQUAL "STATIC") |
| 82 |
set_target_properties(${name} PROPERTIES COMPILE_DEFINITIONS |
| 83 |
"QT_STATICPLUGIN") |
| 84 |
if(UNIX) |
| 85 |
set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 86 |
endif() |
| 87 |
endif() |
| 88 |
|
| 89 |
set_target_properties(${name} PROPERTIES AUTOMOC TRUE PREFIX "") |
| 90 |
install(TARGETS ${name} |
| 91 |
EXPORT "AvogadroLibsTargets" |
| 92 |
RUNTIME DESTINATION "${INSTALL_RUNTIME_DIR}" |
| 93 |
LIBRARY DESTINATION "${INSTALL_LIBRARY_DIR}/avogadro2/plugins" |
| 94 |
ARCHIVE DESTINATION "${INSTALL_ARCHIVE_DIR}/avogadro2/staticplugins") |
| 95 |
endfunction() |
| 96 |
|
| 97 |
# Now to make the plugins. |
| 98 |
add_subdirectory(3dmol) |
| 99 |
add_subdirectory(alchemy) |
| 100 |
add_subdirectory(aligntool) |
| 101 |
add_subdirectory(apbs) |
| 102 |
add_subdirectory(applycolors) |
| 103 |
add_subdirectory(autoopt) |
| 104 |
add_subdirectory(bondcentrictool) |
| 105 |
add_subdirectory(bonding) |
| 106 |
add_subdirectory(centroid) |
| 107 |
add_subdirectory(configurepython) |
| 108 |
add_subdirectory(constraints) |
| 109 |
add_subdirectory(coordinateeditor) |
| 110 |
add_subdirectory(copypaste) |
| 111 |
add_subdirectory(cp2kinput) |
| 112 |
add_subdirectory(crystal) |
| 113 |
add_subdirectory(customelements) |
| 114 |
add_subdirectory(dipole) |
| 115 |
add_subdirectory(editor) |
| 116 |
add_subdirectory(fetchpdb) |
| 117 |
add_subdirectory(focus) |
| 118 |
add_subdirectory(forcefield) |
| 119 |
add_subdirectory(gamessinput) |
| 120 |
add_subdirectory(hydrogens) |
| 121 |
add_subdirectory(importpqr) |
| 122 |
add_subdirectory(insertdna) |
| 123 |
add_subdirectory(insertfragment) |
| 124 |
add_subdirectory(insertpeptide) |
| 125 |
add_subdirectory(label) |
| 126 |
add_subdirectory(lammpsinput) |
| 127 |
add_subdirectory(lineformatinput) |
| 128 |
add_subdirectory(manipulator) |
| 129 |
add_subdirectory(measuretool) |
| 130 |
add_subdirectory(molecularproperties) |
| 131 |
add_subdirectory(navigator) |
| 132 |
add_subdirectory(networkdatabases) |
| 133 |
add_subdirectory(openbabel) |
| 134 |
add_subdirectory(openmminput) |
| 135 |
add_subdirectory(playertool) |
| 136 |
add_subdirectory(ply) |
| 137 |
add_subdirectory(povray) |
| 138 |
add_subdirectory(propertytables) |
| 139 |
add_subdirectory(resetview) |
| 140 |
add_subdirectory(select) |
| 141 |
add_subdirectory(selectiontool) |
| 142 |
if(USE_SPGLIB) |
| 143 |
add_subdirectory(spacegroup) |
| 144 |
endif() |
| 145 |
add_subdirectory(surfaces) |
| 146 |
add_subdirectory(svg) |
| 147 |
add_subdirectory(templatetool) |
| 148 |
add_subdirectory(vibrations) |
| 149 |
add_subdirectory(vrml) |
| 150 |
|
| 151 |
# Plugins that require plotting (JKQTPlotter) |
| 152 |
if(USE_PLOTTER) |
| 153 |
add_subdirectory(spectra) |
| 154 |
add_subdirectory(plotconformer) |
| 155 |
add_subdirectory(plotpdf) |
| 156 |
add_subdirectory(plotxrd) |
| 157 |
if(USE_SPGLIB) |
| 158 |
add_subdirectory(yaehmop) |
| 159 |
endif() |
| 160 |
endif() |
| 161 |
|
| 162 |
# script plugins (input generators, etc.) |
| 163 |
add_subdirectory(commandscripts) |
| 164 |
add_subdirectory(quantuminput) |
| 165 |
add_subdirectory(scriptcharges) |
| 166 |
add_subdirectory(scriptfileformats) |
| 167 |
|
| 168 |
if(USE_LIBARCHIVE) |
| 169 |
add_subdirectory(packageinstaller) |
| 170 |
endif() |
| 171 |
|
| 172 |
if(USE_LIBMSYM) |
| 173 |
add_subdirectory(symmetry) |
| 174 |
endif() |
| 175 |
|
| 176 |
# The scene plugins |
| 177 |
add_subdirectory(ballandstick) |
| 178 |
add_subdirectory(cartoons) |
| 179 |
add_subdirectory(closecontacts) |
| 180 |
add_subdirectory(force) |
| 181 |
add_subdirectory(licorice) |
| 182 |
add_subdirectory(surfacerender) |
| 183 |
add_subdirectory(noncovalent) |
| 184 |
add_subdirectory(vanderwaals) |
| 185 |
add_subdirectory(wireframe) |
| 186 |
if (USE_OPENGL) |
| 187 |
# needs some raw OpenGL code |
| 188 |
add_subdirectory(overlayaxes) |
| 189 |
endif() |
| 190 |
|
| 191 |
# other optional plugins |
| 192 |
if(BUILD_GPL_PLUGINS) |
| 193 |
# qtaimcurvature.h/cpp contains GPL licensed code: |
| 194 |
add_subdirectory(qtaim) |
| 195 |
endif() |
| 196 |
|
| 197 |
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${original_library_output_dir}") |
| 198 |
|
| 199 |
# Add all of the static plugins to the initialization file. |
| 200 |
get_property(AvogadroLibs_STATIC_PLUGINS GLOBAL |
| 201 |
PROPERTY AvogadroLibs_STATIC_PLUGINS) |
| 202 |
get_property(AvogadroLibs_STATIC_RCS GLOBAL |
| 203 |
PROPERTY AvogadroLibs_STATIC_RCS) |
| 204 |
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 205 |
"// Automatically generated file. Do not edit. |
| 206 |
#ifndef AVOGADRO_STATIC_QTPLUGINS_H |
| 207 |
#define AVOGADRO_STATIC_QTPLUGINS_H |
| 208 |
#include <QtCore/QtPlugin>\n\n") |
| 209 |
|
| 210 |
foreach(_plugin ${AvogadroLibs_STATIC_PLUGINS}) |
| 211 |
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 212 |
"Q_IMPORT_PLUGIN(${_plugin}Factory)\n") |
| 213 |
endforeach() |
| 214 |
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 215 |
"\nvoid initAvogadroPluginResources() {\n") |
| 216 |
foreach(_rcs ${AvogadroLibs_STATIC_RCS}) |
| 217 |
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 218 |
" Q_INIT_RESOURCE(${_rcs});\n") |
| 219 |
endforeach() |
| 220 |
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 221 |
"}\n\n") |
| 222 |
|
| 223 |
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 224 |
"\n#endif // AVOGADRO_STATIC_QTPLUGINS_H\n") |
| 225 |
|
| 226 |
# Configure the static plugin header, ensuring it only changes if the contents |
| 227 |
# are modified - otherwise the original timestamp will be maintained. |
| 228 |
configure_file("${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h.in" |
| 229 |
"${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h") |
| 230 |
|
| 231 |
# Now to build the plugin library, which can also statically link plugins |
| 232 |
# and initialize them for the application. If Avogadro is built statically |
| 233 |
# then the static plugin header must be included by the application. |
| 234 |
add_library(QtPlugins) |
| 235 |
avogadro_headers(QtPlugins |
| 236 |
pluginmanager.h |
| 237 |
pluginfactory.h |
| 238 |
"${CMAKE_CURRENT_BINARY_DIR}/avogadrostaticqtplugins.h" |
| 239 |
) |
| 240 |
|
| 241 |
target_sources(QtPlugins PRIVATE |
| 242 |
pluginmanager.cpp |
| 243 |
) |
| 244 |
|
| 245 |
avogadro_add_library(QtPlugins ${HEADERS} ${SOURCES}) |
| 246 |
target_link_libraries(QtPlugins PUBLIC Qt::Core |
| 247 |
PRIVATE ${AvogadroLibs_STATIC_PLUGINS} Avogadro::QtGui Avogadro::Calc) |
| 248 |
|
| 249 |
if(QT_VERSION EQUAL 6) |
| 250 |
target_link_libraries(QtPlugins PRIVATE Qt6::OpenGLWidgets Qt6::Network) |
| 251 |
endif() |