diff options
author | Stephen Kelly <steveire@gmail.com> | 2012-11-20 09:58:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-10-08 00:07:27 (GMT) |
commit | 435c912848b08333e03c74439f725c9b96890d80 (patch) | |
tree | ef1aaad7af3149558792db8209feef24e31f509a /Tests | |
parent | fe732264e9abb6249d1d112b24ce36b226590105 (diff) | |
download | CMake-435c912848b08333e03c74439f725c9b96890d80.zip CMake-435c912848b08333e03c74439f725c9b96890d80.tar.gz CMake-435c912848b08333e03c74439f725c9b96890d80.tar.bz2 |
export: Add support for INTERFACE_LIBRARY targets
Diffstat (limited to 'Tests')
11 files changed, 142 insertions, 0 deletions
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 72ae78f..62aa86c 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -426,3 +426,5 @@ export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake ) + +add_subdirectory(Interface) diff --git a/Tests/ExportImport/Export/Interface/CMakeLists.txt b/Tests/ExportImport/Export/Interface/CMakeLists.txt new file mode 100644 index 0000000..01e89ef --- /dev/null +++ b/Tests/ExportImport/Export/Interface/CMakeLists.txt @@ -0,0 +1,29 @@ + +add_library(headeronly INTERFACE) +set_property(TARGET headeronly PROPERTY INTERFACE_INCLUDE_DIRECTORIES + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headeronly>" + "$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/headeronly>" +) +set_property(TARGET headeronly PROPERTY INTERFACE_COMPILE_DEFINITIONS "HEADERONLY_DEFINE") + +include(GenerateExportHeader) +add_library(sharedlib SHARED sharedlib.cpp) +generate_export_header(sharedlib) +set_property(TARGET sharedlib PROPERTY INCLUDE_DIRECTORIES + "${CMAKE_CURRENT_SOURCE_DIR}/sharedlib" + "${CMAKE_CURRENT_BINARY_DIR}" +) +set_property(TARGET sharedlib PROPERTY INTERFACE_INCLUDE_DIRECTORIES + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sharedlib;${CMAKE_CURRENT_BINARY_DIR}>" + "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/sharedlib>" +) + +set_property(TARGET sharedlib PROPERTY INTERFACE_COMPILE_DEFINITIONS "SHAREDLIB_DEFINE") + +add_library(sharediface INTERFACE) +target_link_libraries(sharediface INTERFACE sharedlib) + +export(TARGETS sharediface sharedlib headeronly + NAMESPACE bld_ + FILE ../ExportInterfaceBuildTree.cmake +) diff --git a/Tests/ExportImport/Export/Interface/headeronly/headeronly.h b/Tests/ExportImport/Export/Interface/headeronly/headeronly.h new file mode 100644 index 0000000..3673c21 --- /dev/null +++ b/Tests/ExportImport/Export/Interface/headeronly/headeronly.h @@ -0,0 +1,7 @@ + +enum { one }; + +struct HeaderOnly +{ + int foo() const { return 0; } +}; diff --git a/Tests/ExportImport/Export/Interface/sharedlib.cpp b/Tests/ExportImport/Export/Interface/sharedlib.cpp new file mode 100644 index 0000000..88ca713 --- /dev/null +++ b/Tests/ExportImport/Export/Interface/sharedlib.cpp @@ -0,0 +1,7 @@ + +#include "sharedlib.h" + +int SharedLibObject::foo() const +{ + return 0; +} diff --git a/Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h b/Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h new file mode 100644 index 0000000..aad9ef3 --- /dev/null +++ b/Tests/ExportImport/Export/Interface/sharedlib/sharedlib.h @@ -0,0 +1,7 @@ + +#include "sharedlib_export.h" + +struct SHAREDLIB_EXPORT SharedLibObject +{ + int foo() const; +}; diff --git a/Tests/ExportImport/Import/CMakeLists.txt b/Tests/ExportImport/Import/CMakeLists.txt index 9c2d597..5e809a2 100644 --- a/Tests/ExportImport/Import/CMakeLists.txt +++ b/Tests/ExportImport/Import/CMakeLists.txt @@ -19,3 +19,6 @@ add_executable(imp_testTransExe1b imp_testTransExe1.c) target_link_libraries(imp_testTransExe1b imp_lib1b) add_subdirectory(try_compile) + +# Test package INTERFACE controls +add_subdirectory(Interface) diff --git a/Tests/ExportImport/Import/Interface/CMakeLists.txt b/Tests/ExportImport/Import/Interface/CMakeLists.txt new file mode 100644 index 0000000..c8c8401 --- /dev/null +++ b/Tests/ExportImport/Import/Interface/CMakeLists.txt @@ -0,0 +1,42 @@ + +# Import targets from the exported build tree. +include(${Import_BINARY_DIR}/../Export/ExportInterfaceBuildTree.cmake) + +add_library(define_iface INTERFACE) +set_property(TARGET define_iface PROPERTY + INTERFACE_COMPILE_DEFINITIONS DEFINE_IFACE_DEFINE) + +add_executable(headeronlytest_bld headeronlytest.cpp) +target_link_libraries(headeronlytest_bld bld_headeronly) + +set_property(TARGET bld_sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface) + +add_executable(interfacetest_bld interfacetest.cpp) +target_link_libraries(interfacetest_bld bld_sharediface) + +include(CheckCXXSourceCompiles) + +macro(do_try_compile prefix) + + set(CMAKE_REQUIRED_LIBRARIES ${prefix}headeronly) + check_cxx_source_compiles( + " + #include \"headeronly.h\" + + #ifndef HEADERONLY_DEFINE + #error Expected HEADERONLY_DEFINE + #endif + + int main(int,char**) + { + HeaderOnly ho; + return ho.foo(); + } + " ${prefix}IFACE_TRY_COMPILE) + + if(NOT ${prefix}IFACE_TRY_COMPILE) + message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}") + endif() +endmacro() + +do_try_compile(bld_) diff --git a/Tests/ExportImport/Import/Interface/headeronlytest.cpp b/Tests/ExportImport/Import/Interface/headeronlytest.cpp new file mode 100644 index 0000000..20674a7 --- /dev/null +++ b/Tests/ExportImport/Import/Interface/headeronlytest.cpp @@ -0,0 +1,17 @@ + +#include "headeronly.h" + +#ifndef HEADERONLY_DEFINE +#error Expected HEADERONLY_DEFINE +#endif + +#ifdef SHAREDLIB_DEFINE +#error Unexpected SHAREDLIB_DEFINE +#endif + + +int main(int,char**) +{ + HeaderOnly ho; + return ho.foo(); +} diff --git a/Tests/ExportImport/Import/Interface/interfacetest.cpp b/Tests/ExportImport/Import/Interface/interfacetest.cpp new file mode 100644 index 0000000..786458d --- /dev/null +++ b/Tests/ExportImport/Import/Interface/interfacetest.cpp @@ -0,0 +1,20 @@ + +#include "sharedlib.h" + +#ifndef SHAREDLIB_DEFINE +#error Expected SHAREDLIB_DEFINE +#endif + +#ifdef HEADERONLY_DEFINE +#error Unexpected HEADERONLY_DEFINE +#endif + +#ifndef DEFINE_IFACE_DEFINE +#error Expected DEFINE_IFACE_DEFINE +#endif + +int main(int,char**) +{ + SharedLibObject slo; + return slo.foo(); +} diff --git a/Tests/RunCMake/interface_library/invalid_name-stderr.txt b/Tests/RunCMake/interface_library/invalid_name-stderr.txt index c66e080..e14fcde 100644 --- a/Tests/RunCMake/interface_library/invalid_name-stderr.txt +++ b/Tests/RunCMake/interface_library/invalid_name-stderr.txt @@ -7,3 +7,9 @@ CMake Error at invalid_name.cmake:4 \(add_library\): add_library Invalid name for INTERFACE library target: iface::target Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) ++ +CMake Error at invalid_name.cmake:6 \(add_library\): + add_library Invalid name for IMPORTED INTERFACE library target: + if\$target_imported +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/interface_library/invalid_name.cmake b/Tests/RunCMake/interface_library/invalid_name.cmake index 51a109d..9a965aa 100644 --- a/Tests/RunCMake/interface_library/invalid_name.cmake +++ b/Tests/RunCMake/interface_library/invalid_name.cmake @@ -2,3 +2,5 @@ add_library(if$ace INTERFACE) add_library(iface::target INTERFACE) + +add_library(if$target_imported INTERFACE IMPORTED) |