diff options
author | Stephen Kelly <steveire@gmail.com> | 2011-10-07 00:41:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2011-11-22 21:52:35 (GMT) |
commit | 914382224d34cfb86a67c8191b6e7b3a3e918f88 (patch) | |
tree | f5796b3ff7095e8e0fad805fe219aead007b57d3 /Tests | |
parent | cf64218eeb7dbe8a0d71292c42df63c4cb982fed (diff) | |
download | CMake-914382224d34cfb86a67c8191b6e7b3a3e918f88.zip CMake-914382224d34cfb86a67c8191b6e7b3a3e918f88.tar.gz CMake-914382224d34cfb86a67c8191b6e7b3a3e918f88.tar.bz2 |
target_link_libraries: Add LINK_(PUBLIC|PRIVATE) options
Makes it possible to specify the link dependencies and link
interfaces in one command without repetition.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/CMakeLists.txt | 58 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/depA.cpp | 7 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/depA.h | 7 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/depB.cpp | 11 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/depB.h | 7 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/depC.cpp | 13 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/depC.h | 12 | ||||
-rw-r--r-- | Tests/CMakeCommands/target_link_libraries/targetA.cpp | 12 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 2 |
9 files changed, 129 insertions, 0 deletions
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt new file mode 100644 index 0000000..1faa888 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 2.8) + +project(target_link_libraries) + +file(WRITE + "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" + "int main() { return 0; } +" +) + +add_executable( + target_link_libraries + "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" +) + +macro(ASSERT_PROPERTY _target _property _value) + get_target_property(_out ${_target} ${_property}) + if (NOT _out) + set(_out "") + endif() + if (NOT "${_out}" STREQUAL "${_value}") + message(SEND_ERROR "Target ${_target} does not have property ${_property} with value ${_value}. Actual value: ${_out}") + endif() +endmacro() + +include(GenerateExportHeader) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_library(depA SHARED depA.cpp) +generate_export_header(depA) + +add_library(depB SHARED depB.cpp) +generate_export_header(depB) + +target_link_libraries(depB LINK_PRIVATE depA) + +add_library(depC SHARED depC.cpp) +generate_export_header(depC) + +target_link_libraries(depC LINK_PUBLIC depA) + +assert_property(depA LINK_INTERFACE_LIBRARIES "") +assert_property(depB LINK_INTERFACE_LIBRARIES "") +assert_property(depC LINK_INTERFACE_LIBRARIES "depA") + +add_executable(targetA targetA.cpp) + +target_link_libraries(targetA LINK_INTERFACE_LIBRARIES depA depB) + +assert_property(targetA LINK_INTERFACE_LIBRARIES "depA;depB") + +set_target_properties(targetA PROPERTIES LINK_INTERFACE_LIBRARIES "") + +assert_property(targetA LINK_INTERFACE_LIBRARIES "") + +target_link_libraries(targetA depB depC) + +assert_property(targetA LINK_INTERFACE_LIBRARIES "") diff --git a/Tests/CMakeCommands/target_link_libraries/depA.cpp b/Tests/CMakeCommands/target_link_libraries/depA.cpp new file mode 100644 index 0000000..c2e8e7b --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depA.cpp @@ -0,0 +1,7 @@ + +#include "depA.h" + +int DepA::foo() +{ + return 0; +} diff --git a/Tests/CMakeCommands/target_link_libraries/depA.h b/Tests/CMakeCommands/target_link_libraries/depA.h new file mode 100644 index 0000000..7a85948 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depA.h @@ -0,0 +1,7 @@ + +#include "depa_export.h" + +struct DEPA_EXPORT DepA +{ + int foo(); +}; diff --git a/Tests/CMakeCommands/target_link_libraries/depB.cpp b/Tests/CMakeCommands/target_link_libraries/depB.cpp new file mode 100644 index 0000000..97e5be2 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depB.cpp @@ -0,0 +1,11 @@ + +#include "depB.h" + +#include "depA.h" + +int DepB::foo() +{ + DepA a; + + return 0; +} diff --git a/Tests/CMakeCommands/target_link_libraries/depB.h b/Tests/CMakeCommands/target_link_libraries/depB.h new file mode 100644 index 0000000..e617813 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depB.h @@ -0,0 +1,7 @@ + +#include "depb_export.h" + +struct DEPB_EXPORT DepB +{ + int foo(); +}; diff --git a/Tests/CMakeCommands/target_link_libraries/depC.cpp b/Tests/CMakeCommands/target_link_libraries/depC.cpp new file mode 100644 index 0000000..93410a8 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depC.cpp @@ -0,0 +1,13 @@ + +#include "depC.h" + +int DepC::foo() +{ + return 0; +} + +DepA DepC::getA() +{ + DepA a; + return a; +}
\ No newline at end of file diff --git a/Tests/CMakeCommands/target_link_libraries/depC.h b/Tests/CMakeCommands/target_link_libraries/depC.h new file mode 100644 index 0000000..4d65c9e --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depC.h @@ -0,0 +1,12 @@ + +#include "depc_export.h" + +#include "depA.h" + +struct DEPC_EXPORT DepC +{ + int foo(); + + DepA getA(); + +}; diff --git a/Tests/CMakeCommands/target_link_libraries/targetA.cpp b/Tests/CMakeCommands/target_link_libraries/targetA.cpp new file mode 100644 index 0000000..3c6472e --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/targetA.cpp @@ -0,0 +1,12 @@ + +#include "depB.h" +#include "depC.h" + +int main(int argc, char **argv) +{ + DepA a; + DepB b; + DepC c; + + return a.foo() + b.foo() + c.foo(); +} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 78db39d..44ed2f5 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1574,6 +1574,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ -P "${CMake_SOURCE_DIR}/Tests/CMakeCommands/build_command/RunCMake.cmake" ) + ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries) + CONFIGURE_FILE( "${CMake_SOURCE_DIR}/Tests/CTestTestCrash/test.cmake.in" "${CMake_BINARY_DIR}/Tests/CTestTestCrash/test.cmake" |