try_compile: Extract IMPORTED targets from LINK_DEPENDENT_LIBRARIES

This commit is contained in:
Stephen Kelly 2013-08-19 11:57:13 +02:00 committed by Brad King
parent d7c9d60d9f
commit fd4fb9ef04
5 changed files with 45 additions and 8 deletions

View File

@ -93,7 +93,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)
{ {
const std::string libs = i->second.GetValue(); const std::string libs = i->second.GetValue();

View File

@ -213,6 +213,19 @@ set_property(TARGET testSharedLibRequired APPEND PROPERTY
$<$<CXX_COMPILER_ID:GNU>:-DCUSTOM_COMPILE_OPTION> $<$<CXX_COMPILER_ID:GNU>:-DCUSTOM_COMPILE_OPTION>
) )
add_library(testSharedLibRequiredUser SHARED testSharedLibRequiredUser.cpp)
generate_export_header(testSharedLibRequiredUser)
# LINK_PRIVATE so that it appears in the LINK_DEPENDENT_LIBRARIES, but not
# the INTERFACE_LINK_LIBRARIES.
set_property(TARGET testSharedLibRequiredUser APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
)
target_link_libraries(testSharedLibRequiredUser LINK_PRIVATE testSharedLibRequired)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/testSharedLibRequiredUser.h"
"${CMAKE_CURRENT_BINARY_DIR}/testsharedlibrequireduser_export.h"
DESTINATION include/testSharedLibRequiredUser
)
add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp) add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp)
set_property(TARGET testSharedLibDepends APPEND PROPERTY set_property(TARGET testSharedLibDepends APPEND PROPERTY
@ -284,6 +297,7 @@ install(TARGETS
testLibIncludeRequired5 testLibIncludeRequired5
testLibIncludeRequired6 testLibIncludeRequired6
testSharedLibRequired testSharedLibRequired
testSharedLibRequiredUser
noIncludesInterface noIncludesInterface
EXPORT RequiredExp DESTINATION lib EXPORT RequiredExp DESTINATION lib
INCLUDES DESTINATION INCLUDES DESTINATION
@ -384,7 +398,7 @@ 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 testSharedLibDepends renamed_on_export testSharedLibRequired testSharedLibRequiredUser testSharedLibDepends renamed_on_export
cmp0022NEW cmp0022OLD cmp0022NEW cmp0022OLD
NAMESPACE bld_ NAMESPACE bld_
FILE ExportBuildTree.cmake FILE ExportBuildTree.cmake

View File

@ -0,0 +1,10 @@
#include "testSharedLibRequiredUser.h"
#include "testSharedLibRequired.h"
int TestSharedLibRequiredUser::foo()
{
TestSharedLibRequired req;
return req.foo();
}

View File

@ -0,0 +1,12 @@
#ifndef TESTSHAREDLIBREQUIREDUSER_H
#define TESTSHAREDLIBREQUIREDUSER_H
#include "testsharedlibrequireduser_export.h"
struct TESTSHAREDLIBREQUIREDUSER_EXPORT TestSharedLibRequiredUser
{
int foo();
};
#endif

View File

@ -5,17 +5,17 @@ find_package(testLibRequired 2.5 REQUIRED)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_LIBRARIES Req::testSharedLibRequired) set(CMAKE_REQUIRED_LIBRARIES Req::testSharedLibRequiredUser)
check_cxx_source_compiles( check_cxx_source_compiles(
" "
#include \"testSharedLibRequired.h\" #include \"testSharedLibRequiredUser.h\"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
TestSharedLibRequired req; TestSharedLibRequiredUser user;
return req.foo(); return user.foo();
} }
" SHARED_LIB_REQUIRED) " SHARED_LIB_DEPENDS)
if(NOT SHARED_LIB_REQUIRED) 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()