Use the BUILD_INTERFACE CMake generator expression to improve
self-documentation and to prevent build-tree-only dependencies from
propagating to exported targets. When libgromacs is a STATIC target,
even private dependencies can affect the exported target through
transitive usage requirements (e.g. compiler/linker flags). However,
we currently only use the `common` and `legacy_modules` targets for
build time header paths.
Ref #3288
else()
add_library(libgromacs ${LIBGROMACS_SOURCES})
endif()
else()
add_library(libgromacs ${LIBGROMACS_SOURCES})
endif()
-target_link_libraries(libgromacs PRIVATE common)
+target_link_libraries(libgromacs PRIVATE $<BUILD_INTERFACE:common>)
# As long as the libgromacs target has source files that reference headers from
# modules that don't provide CMake targets, libgromacs needs to use `src/`
# amongst its include directories (to support `#include "gromacs/module/header.h"`).
add_library(legacy_modules INTERFACE)
# As long as the libgromacs target has source files that reference headers from
# modules that don't provide CMake targets, libgromacs needs to use `src/`
# amongst its include directories (to support `#include "gromacs/module/header.h"`).
add_library(legacy_modules INTERFACE)
-target_include_directories(legacy_modules INTERFACE ${CMAKE_SOURCE_DIR}/src)
-target_link_libraries(libgromacs PRIVATE legacy_modules)
+target_include_directories(legacy_modules INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>)
+target_link_libraries(libgromacs PRIVATE $<BUILD_INTERFACE:legacy_modules>)
# Add these contents first because linking their tests can take a lot
# of time, so we want lots of parallel work still available after
# Add these contents first because linking their tests can take a lot
# of time, so we want lots of parallel work still available after