Be more explicit about build-tree-only dependencies.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Fri, 13 Nov 2020 11:37:55 +0000 (14:37 +0300)
committerM. Eric Irrgang <ericirrgang@gmail.com>
Fri, 13 Nov 2020 11:37:55 +0000 (14:37 +0300)
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

src/gromacs/CMakeLists.txt

index 97aca444db2b2a2fc3e9f7e0c368e19273476f6d..65bf17387ae675284ac58cd4853d7d4b36f81064 100644 (file)
@@ -186,13 +186,13 @@ if (GMX_GPU_CUDA)
 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)
-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