try_compile: Extract IMPORTED targets from INTERFACE_LINK_LIBRARIES

This commit is contained in:
Stephen Kelly 2013-08-21 08:55:30 +02:00 committed by Brad King
parent fd4fb9ef04
commit cc8f79670e
5 changed files with 57 additions and 2 deletions

View File

@ -94,7 +94,8 @@ cmExportTryCompileFileGenerator::PopulateProperties(cmTarget* target,
properties[i->first] = i->second.GetValue(); properties[i->first] = i->second.GetValue();
if(i->first.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 if(i->first.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
|| i->first.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0) || i->first.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
|| i->first.find("INTERFACE_LINK_LIBRARIES") == 0)
{ {
const std::string libs = i->second.GetValue(); const std::string libs = i->second.GetValue();

View File

@ -227,6 +227,21 @@ install(FILES
DESTINATION include/testSharedLibRequiredUser DESTINATION include/testSharedLibRequiredUser
) )
cmake_policy(SET CMP0022 NEW)
add_library(testSharedLibRequiredUser2 SHARED testSharedLibRequiredUser2.cpp)
generate_export_header(testSharedLibRequiredUser2)
set_property(TARGET testSharedLibRequiredUser2 APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
)
set_property(TARGET testSharedLibRequiredUser2 PROPERTY LINK_LIBRARIES testSharedLibRequired)
set_property(TARGET testSharedLibRequiredUser2 PROPERTY INTERFACE_LINK_LIBRARIES testSharedLibRequired)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/testSharedLibRequiredUser2.h"
"${CMAKE_CURRENT_BINARY_DIR}/testsharedlibrequireduser2_export.h"
DESTINATION include/testSharedLibRequiredUser2
)
cmake_policy(SET CMP0022 OLD)
add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp) add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp)
set_property(TARGET testSharedLibDepends APPEND PROPERTY set_property(TARGET testSharedLibDepends APPEND PROPERTY
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}" INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}"
@ -298,6 +313,7 @@ install(TARGETS
testLibIncludeRequired6 testLibIncludeRequired6
testSharedLibRequired testSharedLibRequired
testSharedLibRequiredUser testSharedLibRequiredUser
testSharedLibRequiredUser2
noIncludesInterface noIncludesInterface
EXPORT RequiredExp DESTINATION lib EXPORT RequiredExp DESTINATION lib
INCLUDES DESTINATION INCLUDES DESTINATION
@ -398,7 +414,8 @@ add_subdirectory(sublib) # For CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE test.
# Export from build tree. # Export from build tree.
export(TARGETS testExe1 testLib1 testLib2 testLib3 export(TARGETS testExe1 testLib1 testLib2 testLib3
testExe2libImp testLib3Imp testLib3ImpDep subdirlib testExe2libImp testLib3Imp testLib3ImpDep subdirlib
testSharedLibRequired testSharedLibRequiredUser testSharedLibDepends renamed_on_export testSharedLibRequired testSharedLibRequiredUser testSharedLibRequiredUser2
testSharedLibDepends renamed_on_export
cmp0022NEW cmp0022OLD cmp0022NEW cmp0022OLD
NAMESPACE bld_ NAMESPACE bld_
FILE ExportBuildTree.cmake FILE ExportBuildTree.cmake

View File

@ -0,0 +1,8 @@
#include "testSharedLibRequiredUser2.h"
TestSharedLibRequired TestSharedLibRequiredUser2::foo()
{
TestSharedLibRequired req;
return req;
}

View File

@ -0,0 +1,14 @@
#ifndef TESTSHAREDLIBREQUIREDUSER2_H
#define TESTSHAREDLIBREQUIREDUSER2_H
#include "testsharedlibrequireduser2_export.h"
#include "testSharedLibRequired.h"
struct TESTSHAREDLIBREQUIREDUSER2_EXPORT TestSharedLibRequiredUser2
{
TestSharedLibRequired foo();
};
#endif

View File

@ -19,3 +19,18 @@ int main(int argc, char **argv)
if(NOT SHARED_LIB_DEPENDS) if(NOT SHARED_LIB_DEPENDS)
message(SEND_ERROR "try_compile with IMPORTED targets failed!\n\n${OUTPUT}") message(SEND_ERROR "try_compile with IMPORTED targets failed!\n\n${OUTPUT}")
endif() endif()
set(CMAKE_REQUIRED_LIBRARIES Req::testSharedLibRequiredUser2)
check_cxx_source_compiles(
"
#include \"testSharedLibRequiredUser2.h\"
int main(int argc, char **argv)
{
TestSharedLibRequiredUser2 user;
return user.foo().foo();
}
" SHARED_LIB_DEPENDS2)
if(NOT SHARED_LIB_DEPENDS2)
message(SEND_ERROR "try_compile with IMPORTED targets failed!\n\n${OUTPUT}")
endif()