diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 1d3469f7f97ce90f98438421d01dbd2bd2468783..d07645cacd036c18692d1dc3b1272537d9fd5779 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -637,6 +637,28 @@ cmPolicies::cmPolicies() "The OLD behavior for this policy is to use compiler id \"Clang\". " "The NEW behavior for this policy is to use compiler id \"AppleClang\".", 2,8,13,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0026, "CMP0026", + "Disallow use of the LOCATION target property.", + "CMake 2.8.12 and lower allowed reading the LOCATION target property to " + "determine the eventual location of build targets. This relies on the " + "assumption that all necessary information is available at " + "configure-time to determine the final location and filename of the " + "target. However, this property is not fully determined until later at " + "generate-time. At generate time, the $<TARGET_FILE> generator " + "expression can be used to determine the eventual LOCATION of a target " + "output." + "\n" + "Code which reads the LOCATION target property can be ported to use the " + "$<TARGET_FILE> generator expression together with the file(GENERATE) " + "subcommand to generate a file containing the target location." + "\n" + "The OLD behavior for this policy is to allow reading the LOCATION " + "property from build-targets. " + "The NEW behavior for this policy is to not to allow reading the " + "LOCATION property from build-targets.", + 2,8,13,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index ec8959d456cc7e948c77169cc4d5a3ecf59e25a3..e33171ba425183f469888a68aa55253db2cf68ae 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -76,6 +76,7 @@ public: CMP0023, ///< Disallow mixing keyword and plain tll signatures CMP0024, ///< Disallow including export() result. CMP0025, ///< Compiler id for Apple Clang is now AppleClang + CMP0026, ///< Disallow use of the LOCATION target property. /** \brief Always the last entry. * diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a1d9889afe7b39b69a3b48be331634edc97affba..d03ed49b413ce4ec73138efa208d473a75af7d02 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4132,6 +4132,43 @@ const char *cmTarget::GetProperty(const char* prop) return this->GetProperty(prop, cmProperty::TARGET); } +//---------------------------------------------------------------------------- +bool cmTarget::HandleLocationPropertyPolicy() +{ + if (this->IsImported()) + { + return true; + } + const char *modal = 0; + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0026)) + { + case cmPolicies::WARN: + modal = "should"; + case cmPolicies::OLD: + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: + modal = "may"; + messageType = cmake::FATAL_ERROR; + } + + if (modal) + { + cmOStringStream e; + e << (this->Makefile->GetPolicies() + ->GetPolicyWarning(cmPolicies::CMP0026)) << "\n"; + e << "The LOCATION property " << modal << " not be read from target \"" + << this->GetName() << "\". Use the target name directly with " + "add_custom_command, or use the generator expression $<TARGET_FILE>, " + "as appropriate.\n"; + this->Makefile->IssueMessage(messageType, e.str().c_str()); + } + + return messageType != cmake::FATAL_ERROR; +} + //---------------------------------------------------------------------------- const char *cmTarget::GetProperty(const char* prop, cmProperty::ScopeType scope) @@ -4157,6 +4194,11 @@ const char *cmTarget::GetProperty(const char* prop, { if(strcmp(prop,"LOCATION") == 0) { + if (!this->HandleLocationPropertyPolicy()) + { + return 0; + } + // Set the LOCATION property of the target. // // For an imported target this is the location of an arbitrary @@ -4172,6 +4214,10 @@ const char *cmTarget::GetProperty(const char* prop, // Support "LOCATION_<CONFIG>". if(strncmp(prop, "LOCATION_", 9) == 0) { + if (!this->HandleLocationPropertyPolicy()) + { + return 0; + } std::string configName = prop+9; this->SetProperty(prop, this->GetLocation(configName.c_str())); } @@ -4184,6 +4230,10 @@ const char *cmTarget::GetProperty(const char* prop, std::string configName(prop, len-9); if(configName != "IMPORTED") { + if (!this->HandleLocationPropertyPolicy()) + { + return 0; + } this->SetProperty(prop, this->GetLocation(configName.c_str())); } } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index a88c5ec310f623f39f0d67bdba2eab48d0738be2..3c36da7891dd7ee2c7e6f8712c08835e3db8308b 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -554,6 +554,8 @@ public: { return this->TargetTypeValue == STATIC_LIBRARY; } private: + bool HandleLocationPropertyPolicy(); + // The set of include directories that are marked as system include // directories. std::set<cmStdString> SystemIncludeDirectories; diff --git a/Tests/FindPackageModeMakefileTest/CMakeLists.txt b/Tests/FindPackageModeMakefileTest/CMakeLists.txt index 3674f0efe3f060f137a274201a94d579a44b70c6..5d1b3769670243dc9e60b2c57bae7ddd80404456 100644 --- a/Tests/FindPackageModeMakefileTest/CMakeLists.txt +++ b/Tests/FindPackageModeMakefileTest/CMakeLists.txt @@ -19,8 +19,16 @@ if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Makefile") configure_file(FindFoo.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindFoo.cmake @ONLY) # now set up the test: - get_target_property(cmakeExecutable cmake LOCATION) - + if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) + file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cmakeExecutable.mk" + CONTENT "CMAKE = \"$<TARGET_FILE:cmake>\"\n" + ) + else() + get_target_property(cmakeLocation cmake LOCATION) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cmakeExecutable.mk" + "CMAKE = \"${cmakeLocation}\"\n" + ) + endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Makefile.in ${CMAKE_CURRENT_BINARY_DIR}/ConfMakefile @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/main.cpp COPYONLY) diff --git a/Tests/FindPackageModeMakefileTest/Makefile.in b/Tests/FindPackageModeMakefileTest/Makefile.in index f647901e70e1293117ca37b39c4754f6ad2d9fc0..c91d8a0184ecce9a55a9c09918fb34a5f8db43c5 100644 --- a/Tests/FindPackageModeMakefileTest/Makefile.in +++ b/Tests/FindPackageModeMakefileTest/Makefile.in @@ -1,4 +1,6 @@ -CMAKE = "@cmakeExecutable@" + +include cmakeExecutable.mk + CMAKE_CURRENT_BINARY_DIR = "@CMAKE_CURRENT_BINARY_DIR@" CMAKE_CXX_COMPILER = "@CMAKE_CXX_COMPILER@" CMAKE_CXX_COMPILER_ID = "@CMAKE_CXX_COMPILER_ID@" diff --git a/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt new file mode 100644 index 0000000000000000000000000000000000000000..573541ac9702dd3969c9bc859d2b91ec1f7e6e56 --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt new file mode 100644 index 0000000000000000000000000000000000000000..10f32932ee8c02373314b10fd478bc8a99daf35e --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED-stderr.txt @@ -0,0 +1 @@ +^$ diff --git a/Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake new file mode 100644 index 0000000000000000000000000000000000000000..650c8a5c79c80b0179f50b62178da04f15f246a4 --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-IMPORTED.cmake @@ -0,0 +1,6 @@ + +enable_language(CXX) + +add_library(someimportedlib SHARED IMPORTED) + +get_target_property(_loc someimportedlib LOCATION) diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt b/Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-NEW-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt new file mode 100644 index 0000000000000000000000000000000000000000..2a05a4dd41cb23eb12163f7244c470062960793e --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at CMP0026-NEW.cmake:7 \(get_target_property\): + Policy CMP0026 is not set: Disallow use of the LOCATION target property. + Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy + command to set the policy and suppress this warning. + + The LOCATION property may not be read from target "somelib". Use the + target name directly with add_custom_command, or use the generator + expression \$<TARGET_FILE>, as appropriate. + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW.cmake b/Tests/RunCMake/CMP0026/CMP0026-NEW.cmake new file mode 100644 index 0000000000000000000000000000000000000000..1659ffc5244b9dba05e38c5ac84a709b2cf7c4a9 --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-NEW.cmake @@ -0,0 +1,7 @@ + +enable_language(CXX) + +cmake_policy(SET CMP0026 NEW) + +add_library(somelib empty.cpp) +get_target_property(_loc somelib LOCATION) diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt b/Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt new file mode 100644 index 0000000000000000000000000000000000000000..573541ac9702dd3969c9bc859d2b91ec1f7e6e56 --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-WARN-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b8819488e0859d69893422568381af0da9067ad --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt @@ -0,0 +1,12 @@ +CMake Warning \(dev\) at CMP0026-WARN.cmake:5 \(get_target_property\): + Policy CMP0026 is not set: Disallow use of the LOCATION target property. + Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy + command to set the policy and suppress this warning. + + The LOCATION property should not be read from target "somelib". Use the + target name directly with add_custom_command, or use the generator + expression \$<TARGET_FILE>, as appropriate. + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN.cmake b/Tests/RunCMake/CMP0026/CMP0026-WARN.cmake new file mode 100644 index 0000000000000000000000000000000000000000..89c5a8af790df4940c7079da7b01290da1ed4178 --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMP0026-WARN.cmake @@ -0,0 +1,5 @@ + +enable_language(CXX) + +add_library(somelib empty.cpp) +get_target_property(_loc somelib LOCATION) diff --git a/Tests/RunCMake/CMP0026/CMakeLists.txt b/Tests/RunCMake/CMP0026/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e8db6b05be2a6a51fd86a2ec769c627d458f5269 --- /dev/null +++ b/Tests/RunCMake/CMP0026/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CMP0026/RunCMakeTest.cmake b/Tests/RunCMake/CMP0026/RunCMakeTest.cmake new file mode 100644 index 0000000000000000000000000000000000000000..68000a6790be810b04b95264f3ad346525cc11ff --- /dev/null +++ b/Tests/RunCMake/CMP0026/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(CMP0026-WARN) +run_cmake(CMP0026-NEW) +run_cmake(CMP0026-IMPORTED) diff --git a/Tests/RunCMake/CMP0026/empty.cpp b/Tests/RunCMake/CMP0026/empty.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfbbddeb90564ce8dbeaf652fbcc530f25214faa --- /dev/null +++ b/Tests/RunCMake/CMP0026/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty() +{ + return 0; +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 4fbc3b0fe428147c6f0f1b3205c903094a2b7a6c..6d5b07b4964b8c0bb0c78f41bb465485255057e2 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -53,6 +53,7 @@ endif() add_RunCMake_test(CMP0019) add_RunCMake_test(CMP0022) +add_RunCMake_test(CMP0026) add_RunCMake_test(CTest) if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles") add_RunCMake_test(CompilerChange) diff --git a/Utilities/CMakeLists.txt b/Utilities/CMakeLists.txt index bad8d630e6aa542bb1e1ade626abb39585c64b43..31807eee14f99de601dfc6158a57f537edbb89a7 100644 --- a/Utilities/CMakeLists.txt +++ b/Utilities/CMakeLists.txt @@ -48,14 +48,12 @@ set(DOCBOOK_FILES ) macro(ADD_DOCS target dependency) - # Generate documentation for "ctest" executable. - get_target_property(CMD ${target} LOCATION) # only generate the documentation if the target is actually built - if(CMD) + if(${target}) add_custom_command( OUTPUT ${CMake_BINARY_DIR}/Docs/${target}.txt ${${target}-PATH} # Possibly set PATH, see below. - COMMAND ${CMD} + COMMAND $<TARGET_FILE:${target}> ARGS --help-full ${CMake_BINARY_DIR}/Docs/${target}.txt --help-full ${CMake_BINARY_DIR}/Docs/${target}.html --help-full ${CMake_BINARY_DIR}/Docs/${target}.1 @@ -92,10 +90,9 @@ ADD_DOCS(cmake-gui ${CMake_SOURCE_DIR}/Utilities/Doxygen/doxyfile.in) # add the documentation for cmake itself -get_target_property(CMD cmake LOCATION) add_custom_command( OUTPUT ${CMake_BINARY_DIR}/Docs/cmake.txt - COMMAND ${CMD} + COMMAND $<TARGET_FILE:cmake> ARGS --copyright ${CMake_BINARY_DIR}/Docs/Copyright.txt --help-full ${CMake_BINARY_DIR}/Docs/cmake.txt --help-full ${CMake_BINARY_DIR}/Docs/cmake.html