From 3b8e56a50f7f608f7a93f8ecf23392cc2cda4868 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 9 Dec 2013 19:12:57 +0100 Subject: [PATCH] Don't search for IMPORTED_LOCATION of INTERFACE_LIBRARY (14636) The INTERFACE_LIBRARY type does not have any LOCATION at all, so return early from GetMappedConfig. GetMappedConfig is called from two locations, one of which already pre-checks the INTERFACE_LIBRARY case. Remove that pre-check and handle that case inside the method instead. --- Source/cmTarget.cxx | 12 ++++++++-- .../interface_library/RunCMakeTest.cmake | 1 + .../interface_library/genex_link-result.txt | 1 + .../interface_library/genex_link-stderr.txt | 1 + .../interface_library/genex_link.cmake | 22 +++++++++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/interface_library/genex_link-result.txt create mode 100644 Tests/RunCMake/interface_library/genex_link-stderr.txt create mode 100644 Tests/RunCMake/interface_library/genex_link.cmake diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 38fe945e08..51ee31a3c4 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4860,6 +4860,15 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config, const char** imp, std::string& suffix) const { + if (this->GetType() == INTERFACE_LIBRARY) + { + // This method attempts to find a config-specific LOCATION for the + // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no + // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate + // and valid response. + return true; + } + // Track the configuration-specific property suffix. suffix = "_"; suffix += desired_config; @@ -4992,8 +5001,7 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, const char* loc = 0; const char* imp = 0; std::string suffix; - if (this->GetType() != INTERFACE_LIBRARY && - !this->GetMappedConfig(desired_config, &loc, &imp, suffix)) + if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix)) { return; } diff --git a/Tests/RunCMake/interface_library/RunCMakeTest.cmake b/Tests/RunCMake/interface_library/RunCMakeTest.cmake index e257fb32a2..0d00b71c52 100644 --- a/Tests/RunCMake/interface_library/RunCMakeTest.cmake +++ b/Tests/RunCMake/interface_library/RunCMakeTest.cmake @@ -4,3 +4,4 @@ run_cmake(invalid_name) run_cmake(target_commands) run_cmake(no_shared_libs) run_cmake(whitelist) +run_cmake(genex_link) diff --git a/Tests/RunCMake/interface_library/genex_link-result.txt b/Tests/RunCMake/interface_library/genex_link-result.txt new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/Tests/RunCMake/interface_library/genex_link-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/interface_library/genex_link-stderr.txt b/Tests/RunCMake/interface_library/genex_link-stderr.txt new file mode 100644 index 0000000000..10f32932ee --- /dev/null +++ b/Tests/RunCMake/interface_library/genex_link-stderr.txt @@ -0,0 +1 @@ +^$ diff --git a/Tests/RunCMake/interface_library/genex_link.cmake b/Tests/RunCMake/interface_library/genex_link.cmake new file mode 100644 index 0000000000..0dbf029fea --- /dev/null +++ b/Tests/RunCMake/interface_library/genex_link.cmake @@ -0,0 +1,22 @@ + +cmake_minimum_required(VERSION 2.8.12.20131125 FATAL_ERROR) + +project(genex_link) + +set(_main_cpp ${CMAKE_CURRENT_BINARY_DIR}/main.cpp) +file(WRITE ${_main_cpp} + "int main(int argc, char** argv) { return 0; }\n" +) + +add_library(foo::bar INTERFACE IMPORTED) +set_target_properties(foo::bar + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}" + # When not using a generator expression here, no error is generated + INTERFACE_LINK_LIBRARIES "$<$>:foo_bar.lib>" +) + +add_executable(main ${_main_cpp}) +target_include_directories(main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") + +target_link_libraries(main foo::bar)