CMake (?) problem when adding a new library

GROMACS version: 2022
GROMACS modification: Yes

Hi, I am trying to port the flow binning code by @pjohansson (GitHub - pjohansson/gromacs-flow-field: Flow field collection and output for GROMACS) to the release version of Gromacs 2022 (src/gromacs/mdrun · release-2022 · GROMACS / GROMACS · GitLab).

The library only consists in a source and its header, respectively src/gromacs/flow/flow_field.cpp and src/gromacs/flow/flow_field.h; the header is included in /src/gromacs/mdrun/md.cpp and there some functions are called. It also comes with its CMakeList.txt:

file(GLOB FLOW_SOURCES *.cpp)
set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${FLOW_SOURCES} PARENT_SCOPE)

Now, I can easily build the code for Gromacs 2021, but when it comes to 2022 I get the following error:

../../lib/libgromacs.so.7.0.0: undefined reference to `flow_collect_or_output(FlowData&, unsigned long, t_commrec const*, t_inputrec const*, t_mdatoms const*, t_state const*, SimulationGroups const*)'
../../lib/libgromacs.so.7.0.0: undefined reference to `print_flow_collection_information(FlowData const&, double)'
../../lib/libgromacs.so.7.0.0: undefined reference to `init_flow_container(int, t_filenm const*, t_inputrec const*, SimulationGroups const*, t_state const*)'

I suspect the problem has to do with cmake. If I do a quick grep I notice that the Makefile of 2021 contains the instructions to build the library, while the one of 2022 doesn’t. Has something changed in the cmake between 2021 and 2022? Is the CMakeList.txt incorrect?

Ok, I ended up answering to my own question.
Basically, from 2022 all the subdirectories with librariers are explicitly listed in CMakeLists.txt (the one in <name of the repository>) file as add_subdirectory(<name of the directory in src/gromacs>). Hence, CMake won’t automatically look for libraries to link, but will only draw them from the list in CMakeLists.txt (or at least this is my understanding). Hence, if one wants to add another library, the folder name needs to be added in CMakeLists.txt, otherwise it won’t be linked.

I think this would be something useful to know for external developers.

Thank you for the investigation and answer, Michele!

Petter