Add SOURCE_DIR and BINARY_DIR target properties

This will allow project code to recover the directory information about
where a target was created.
This commit is contained in:
Clifford Yapp 2015-07-21 11:57:22 -04:00 committed by Brad King
parent 265b9db7c2
commit 45c5f8cad2
7 changed files with 38 additions and 1 deletions

View File

@ -114,6 +114,7 @@ Properties on Targets
/prop_tgt/AUTOUIC_OPTIONS /prop_tgt/AUTOUIC_OPTIONS
/prop_tgt/AUTORCC /prop_tgt/AUTORCC
/prop_tgt/AUTORCC_OPTIONS /prop_tgt/AUTORCC_OPTIONS
/prop_tgt/BINARY_DIR
/prop_tgt/BUILD_WITH_INSTALL_RPATH /prop_tgt/BUILD_WITH_INSTALL_RPATH
/prop_tgt/BUNDLE_EXTENSION /prop_tgt/BUNDLE_EXTENSION
/prop_tgt/BUNDLE /prop_tgt/BUNDLE
@ -244,6 +245,7 @@ Properties on Targets
/prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG /prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG
/prop_tgt/RUNTIME_OUTPUT_NAME /prop_tgt/RUNTIME_OUTPUT_NAME
/prop_tgt/SKIP_BUILD_RPATH /prop_tgt/SKIP_BUILD_RPATH
/prop_tgt/SOURCE_DIR
/prop_tgt/SOURCES /prop_tgt/SOURCES
/prop_tgt/SOVERSION /prop_tgt/SOVERSION
/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG /prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG

View File

@ -0,0 +1,6 @@
BINARY_DIR
----------
This read-only property reports the value of the
:variable:`CMAKE_CURRENT_BINARY_DIR` variable in the directory in which
the target was defined.

View File

@ -0,0 +1,6 @@
SOURCE_DIR
----------
This read-only property reports the value of the
:variable:`CMAKE_CURRENT_SOURCE_DIR` variable in the directory in which
the target was defined.

View File

@ -0,0 +1,5 @@
target-directory-properties
---------------------------
* The :prop_tgt:`SOURCE_DIR` and :prop_tgt:`BINARY_DIR` target properties
were introduced to allow project code to query where a target is defined.

View File

@ -2959,6 +2959,8 @@ const char *cmTarget::GetProperty(const std::string& prop,
MAKE_STATIC_PROP(COMPILE_DEFINITIONS); MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
MAKE_STATIC_PROP(IMPORTED); MAKE_STATIC_PROP(IMPORTED);
MAKE_STATIC_PROP(NAME); MAKE_STATIC_PROP(NAME);
MAKE_STATIC_PROP(BINARY_DIR);
MAKE_STATIC_PROP(SOURCE_DIR);
MAKE_STATIC_PROP(SOURCES); MAKE_STATIC_PROP(SOURCES);
#undef MAKE_STATIC_PROP #undef MAKE_STATIC_PROP
if(specialProps.empty()) if(specialProps.empty())
@ -2971,6 +2973,8 @@ const char *cmTarget::GetProperty(const std::string& prop,
specialProps.insert(propCOMPILE_DEFINITIONS); specialProps.insert(propCOMPILE_DEFINITIONS);
specialProps.insert(propIMPORTED); specialProps.insert(propIMPORTED);
specialProps.insert(propNAME); specialProps.insert(propNAME);
specialProps.insert(propBINARY_DIR);
specialProps.insert(propSOURCE_DIR);
specialProps.insert(propSOURCES); specialProps.insert(propSOURCES);
} }
if(specialProps.count(prop)) if(specialProps.count(prop))
@ -3053,6 +3057,14 @@ const char *cmTarget::GetProperty(const std::string& prop,
{ {
return this->GetName().c_str(); return this->GetName().c_str();
} }
else if (prop == propBINARY_DIR)
{
return this->GetMakefile()->GetCurrentBinaryDirectory();
}
else if (prop == propSOURCE_DIR)
{
return this->GetMakefile()->GetCurrentSourceDirectory();
}
else if(prop == propSOURCES) else if(prop == propSOURCES)
{ {
if (this->Internal->SourceEntries.empty()) if (this->Internal->SourceEntries.empty())

View File

@ -3,4 +3,8 @@ get_property: --><--
get_target_property: -->value<-- get_target_property: -->value<--
get_property: -->value<-- get_property: -->value<--
get_target_property: -->gtp_val-NOTFOUND<-- get_target_property: -->gtp_val-NOTFOUND<--
get_property: --><--$ get_property: --><--
get_target_property: -->(.*)/Tests/RunCMake/get_property<--
get_property: -->(.*)/Tests/RunCMake/get_property<--
get_target_property: -->(.*)/Tests/RunCMake/get_property/target_properties-build<--
get_property: -->(.*)/Tests/RunCMake/get_property/target_properties-build<--$

View File

@ -14,3 +14,5 @@ set_target_properties(tgt PROPERTIES empty "" custom value)
check_target_property(tgt empty) check_target_property(tgt empty)
check_target_property(tgt custom) check_target_property(tgt custom)
check_target_property(tgt noexist) check_target_property(tgt noexist)
check_target_property(tgt SOURCE_DIR)
check_target_property(tgt BINARY_DIR)