From 354c1f5628bdc104c9b9cd0436dd4cfa585124ec Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 23 Sep 2021 17:05:03 -0400 Subject: Tests/RunCMake/Autogen: test CMP0111 behavior On Windows, imported shared libraries which only have an `IMPORTED_IMPLIB` set fail if they are depended upon by a target using automoc. Add a test for the behavior of depending upon all imported target types from an automoc-using target. --- .../Autogen/CMP0111-imported-target-full.cmake | 12 ++++++++ .../CMP0111-imported-target-implib-only.cmake | 13 +++++++++ .../Autogen/CMP0111-imported-target-libname.cmake | 14 ++++++++++ .../Autogen/CMP0111-imported-target-prelude.cmake | 32 ++++++++++++++++++++++ Tests/RunCMake/Autogen/RunCMakeTest.cmake | 4 +++ 5 files changed, 75 insertions(+) create mode 100644 Tests/RunCMake/Autogen/CMP0111-imported-target-full.cmake create mode 100644 Tests/RunCMake/Autogen/CMP0111-imported-target-implib-only.cmake create mode 100644 Tests/RunCMake/Autogen/CMP0111-imported-target-libname.cmake create mode 100644 Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake diff --git a/Tests/RunCMake/Autogen/CMP0111-imported-target-full.cmake b/Tests/RunCMake/Autogen/CMP0111-imported-target-full.cmake new file mode 100644 index 0000000..331da64 --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0111-imported-target-full.cmake @@ -0,0 +1,12 @@ +include("${CMAKE_CURRENT_LIST_DIR}/CMP0111-imported-target-prelude.cmake") + +set_location(executable LOCATION "${CMAKE_CURRENT_BINARY_DIR}/executable${CMAKE_EXECUTABLE_SUFFIX}") + +set_location(shared LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}shared${CMAKE_SHARED_LIBRARY_SUFFIX}") +if (CMAKE_IMPORT_LIBRARY_SUFFIX) + set_location(shared IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}shared${CMAKE_IMPORT_LIBRARY_SUFFIX}") +endif () + +set_location(static LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}static${CMAKE_STATIC_LIBRARY_SUFFIX}") +set_location(unknown LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}unknown${CMAKE_IMPORT_LIBRARY_SUFFIX}") +set_location(module LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_MODULE_PREFIX}module${CMAKE_SHARED_MODULE_SUFFIX}") diff --git a/Tests/RunCMake/Autogen/CMP0111-imported-target-implib-only.cmake b/Tests/RunCMake/Autogen/CMP0111-imported-target-implib-only.cmake new file mode 100644 index 0000000..8640fdc --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0111-imported-target-implib-only.cmake @@ -0,0 +1,13 @@ +include("${CMAKE_CURRENT_LIST_DIR}/CMP0111-imported-target-prelude.cmake") + +set_location(executable LOCATION "${CMAKE_CURRENT_BINARY_DIR}/executable${CMAKE_EXECUTABLE_SUFFIX}") + +if (CMAKE_IMPORT_LIBRARY_SUFFIX) + set_location(shared IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}shared${CMAKE_IMPORT_LIBRARY_SUFFIX}") +else () + set_location(shared LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}shared${CMAKE_SHARED_LIBRARY_SUFFIX}") +endif () + +set_location(static LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}static${CMAKE_STATIC_LIBRARY_SUFFIX}") +set_location(unknown LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}unknown${CMAKE_STATIC_LIBRARY_SUFFIX}") +set_location(module LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_MODULE_PREFIX}module${CMAKE_SHARED_MODULE_SUFFIX}") diff --git a/Tests/RunCMake/Autogen/CMP0111-imported-target-libname.cmake b/Tests/RunCMake/Autogen/CMP0111-imported-target-libname.cmake new file mode 100644 index 0000000..e1318c2 --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0111-imported-target-libname.cmake @@ -0,0 +1,14 @@ +include("${CMAKE_CURRENT_LIST_DIR}/CMP0111-imported-target-prelude.cmake") + +set_location(executable LOCATION "${CMAKE_CURRENT_BINARY_DIR}/executable${CMAKE_EXECUTABLE_SUFFIX}") + +set_location(shared LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}shared${CMAKE_SHARED_LIBRARY_SUFFIX}") +if (CMAKE_IMPORT_LIBRARY_SUFFIX) + set_location(shared IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}shared${CMAKE_IMPORT_LIBRARY_SUFFIX}") +endif () + +set_location(static LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}static${CMAKE_IMPORT_LIBRARY_SUFFIX}") +set_location(unknown LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}unknown${CMAKE_IMPORT_LIBRARY_SUFFIX}") +set_location(module LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_MODULE_PREFIX}module${CMAKE_SHARED_MODULE_SUFFIX}") + +set_location(interface LIBNAME "interface") diff --git a/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake b/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake new file mode 100644 index 0000000..8fa6041 --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake @@ -0,0 +1,32 @@ +enable_language(CXX) + +find_package(Qt5 REQUIRED COMPONENTS Core) + +# Detect `-NOTFOUND` libraries at generate time. +cmake_policy(SET CMP0111 NEW) + +add_executable(imported::executable IMPORTED) +add_library(imported::shared SHARED IMPORTED) +add_library(imported::static STATIC IMPORTED) +add_library(imported::unknown UNKNOWN IMPORTED) +add_library(imported::interface INTERFACE IMPORTED) +add_library(imported::module MODULE IMPORTED) + +function (set_location target name loc) + set_property(TARGET "imported::${target}" PROPERTY + "IMPORTED_${name}" "${loc}") +endfunction () + +set(CMAKE_AUTOMOC 1) + +add_library(automoc + empty.cpp) +target_link_libraries(automoc + PRIVATE + imported::shared + imported::static + imported::unknown + imported::interface) +add_dependencies(automoc + imported::executable + imported::module) diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index a31b67c..bbcbd5e 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -5,4 +5,8 @@ if (with_qt5) run_cmake(QtInFunction) run_cmake(QtInFunctionNested) run_cmake(QtInFunctionProperty) + + run_cmake(CMP0111-imported-target-full) + run_cmake(CMP0111-imported-target-libname) + run_cmake(CMP0111-imported-target-implib-only) endif () -- cgit v0.12 From 895fa3433f50b7011fa475a4696dc06fe072aa25 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 23 Sep 2021 17:05:22 -0400 Subject: cmQtAutoGenInitializer: support IMPLIB-only imported targets Instead of using the target name directly (which ends up in the `Ninja` generators querying for the `LOCATION` parameter), wrap up the target name in a `$` to avoid the query for the unset property. --- Source/cmQtAutoGenInitializer.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 4dd78e5..4e3c584 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1306,7 +1306,16 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Add additional autogen target dependencies to // '_autogen_timestamp_deps'. for (const cmTarget* t : this->AutogenTarget.DependTargets) { - dependencies.push_back(t->GetName()); + std::string depname = t->GetName(); + if (t->IsImported()) { + auto ttype = t->GetType(); + if (ttype == cmStateEnums::TargetType::STATIC_LIBRARY || + ttype == cmStateEnums::TargetType::SHARED_LIBRARY || + ttype == cmStateEnums::TargetType::UNKNOWN_LIBRARY) { + depname = cmStrCat("$GetName(), ">"); + } + } + dependencies.push_back(depname); } cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand( -- cgit v0.12