diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-01-04 12:36:18 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-01-10 22:04:06 (GMT) |
commit | 77d26467848fd689fbbffbaa302d041aa2365b15 (patch) | |
tree | 5419a15d9dc585156028cf166932de83f6efa102 /Tests/CMakeCommands | |
parent | 94aeaf72c714eb184ec61bf6e7bc573bd1bc15c9 (diff) | |
download | CMake-77d26467848fd689fbbffbaa302d041aa2365b15.zip CMake-77d26467848fd689fbbffbaa302d041aa2365b15.tar.gz CMake-77d26467848fd689fbbffbaa302d041aa2365b15.tar.bz2 |
Allow generator expressions in LINK_INTERFACE_LIBRARIES.
The Config and IMPORTED_ variants may also contain generator
expressions.
If 'the implementation is the interface', then the result of
evaluating the expressions at generate time is used to populate
the IMPORTED_LINK_INTERFACE_LIBRARIES property.
1) In the case of non-static libraries, this is fine because the
user still has the option to populate the LINK_INTERFACE_LIBRARIES
with generator expressions if that is what is wanted.
2) In the case of static libraries, this prevents a footgun,
enforcing that the interface and the implementation are really
the same.
Otherwise, the LINK_LIBRARIES could contain a generator
expression which is evaluated with a different context at build
time, and when used as an imported target. That would mean that the
result of evaluating the INTERFACE_LINK_LIBRARIES property for
a static library would not necessarily be the 'link implementation'.
For example:
add_library(libone STATIC libone.cpp)
add_library(libtwo STATIC libtwo.cpp)
add_library(libthree STATIC libthree.cpp)
target_link_libraries(libtwo
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:libone>)
target_link_libraries(libthree libtwo)
If the LINK_LIBRARIES content was simply copied to the
IMPORTED_LINK_INTERFACE_LIBRARIES, then libthree links to libone, but
executables linking to libthree will not link to libone.
3) As the 'implementation is the interface' concept is to be
deprecated in the future anyway, this should be fine.
Diffstat (limited to 'Tests/CMakeCommands')
4 files changed, 44 insertions, 0 deletions
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt index 746d30c..1551c50 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -80,3 +80,13 @@ assert_property(targetA LINK_INTERFACE_LIBRARIES "") add_library(depIfaceOnly SHARED EXCLUDE_FROM_ALL depIfaceOnly.cpp) generate_export_header(depIfaceOnly) set_property(TARGET depB APPEND PROPERTY LINK_INTERFACE_LIBRARIES depIfaceOnly) + +add_library(depD SHARED depD.cpp) +generate_export_header(depD) +set_property(TARGET depD APPEND PROPERTY + LINK_INTERFACE_LIBRARIES + $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:depA> +) + +add_executable(targetB targetB.cpp) +target_link_libraries(targetB depD) diff --git a/Tests/CMakeCommands/target_link_libraries/depD.cpp b/Tests/CMakeCommands/target_link_libraries/depD.cpp new file mode 100644 index 0000000..b02c76c --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depD.cpp @@ -0,0 +1,13 @@ + +#include "depD.h" + +int DepD::foo() +{ + return 0; +} + +DepA DepD::getA() +{ + DepA a; + return a; +} diff --git a/Tests/CMakeCommands/target_link_libraries/depD.h b/Tests/CMakeCommands/target_link_libraries/depD.h new file mode 100644 index 0000000..d24ff5f --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depD.h @@ -0,0 +1,11 @@ + +#include "depd_export.h" + +#include "depA.h" + +struct DEPD_EXPORT DepD +{ + int foo(); + + DepA getA(); +}; diff --git a/Tests/CMakeCommands/target_link_libraries/targetB.cpp b/Tests/CMakeCommands/target_link_libraries/targetB.cpp new file mode 100644 index 0000000..063d63a --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/targetB.cpp @@ -0,0 +1,10 @@ + +#include "depD.h" + +int main(int argc, char **argv) +{ + DepD d; + DepA a = d.getA(); + + return d.foo() + a.foo(); +} |