geodynamics / aspect

A parallel, extensible finite element code to simulate convection in both 2D and 3D models.
https://aspect.geodynamics.org/
Other
217 stars 232 forks source link

Improve the way we describe the way to create plugin libraries. #5926

Open bangerth opened 1 week ago

bangerth commented 1 week ago

Working on #5836 shows that we create plugins in, let's say, an awkward way. In the user's CMakeLists.txt, we do

ADD_LIBRARY(${TARGET} SHARED prescribed_velocity_ascii_data.cc)
ASPECT_SETUP_PLUGIN(${TARGET})

and then (after #5836) we have to wire up the so-created library a second time in AspectConfig.cmake:

  # We create lib${_target}.debug.so, lib${_target}.release.so, or both
  # depending on the compilation mode of ASPECT. Note that the user already
  # created the target under the name ${_target}, so we only need to create
  # a second target in the third case above.
  # Note that you can not rename a target or change its filename, but you can
  # modify the suffix. :-)

  if(${ASPECT_BUILD_DEBUG} MATCHES "ON")
    message(STATUS "  setting up DEBUG variant")
    deal_ii_setup_target(${_target} DEBUG)
    set_target_properties(${_target} PROPERTIES SUFFIX ".debug.so")

    list(APPEND _target_libs ${_target})
  endif()

  if(${ASPECT_BUILD_RELEASE} MATCHES "ON")
    message(STATUS "  setting up RELEASE variant")
    add_library(${_target}.release SHARED $<TARGET_PROPERTY:${_target},SOURCES>)      # ***************
    deal_ii_setup_target(${_target}.release RELEASE)
    set_target_properties(${_target}.release PROPERTIES SUFFIX ".so")

    list(APPEND _target_libs ${_target}.release)
  endif()

  ... much more...

The issue is with the marked line: We have to create a second library, having previously assumed that the first library created in user space is actually the debug one. That may not be true with CMAKE_BUILD_TYPE=Release when called in the user directory.

A much better approach would have been to create a macro ASPECT_SETUP_PLUGIN_LIBRARY(_target _source_files) that automatically decides what the library (or libraries) should be called, what its (their) properties should be, etc.