[cmake-developers] Listing source-tree files encountered

Clifford Yapp cliffyapp at gmail.com
Mon Jul 20 16:01:29 EDT 2015


On Mon, Jul 20, 2015 at 9:33 AM, Brad King <brad.king at kitware.com> wrote:

> That looks good to me.  Please extend the patch to also do BINARY_DIR
> for completeness and also to update the documentation to cover the new
> properties.  The Tests/RunCMake/get_property test should be updated
> to cover both too.

I've put both in and added the man pages - progress so far attached.
Are there any other docs that list target properties, or are the rst
files the canonical sources for property docs?

For testing these properties, what would you suggest?  They're
intended to report local configure-time absolute paths, which can't be
hard coded... is it enough to check them to make sure they're not
empty or is there something more robust that could be devised?"

Thanks,
CY
-------------- next part --------------
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 1d27a64..ac893c2 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -114,6 +114,7 @@ Properties on Targets
    /prop_tgt/AUTOUIC_OPTIONS
    /prop_tgt/AUTORCC
    /prop_tgt/AUTORCC_OPTIONS
+   /prop_tgt/BINARY_DIR
    /prop_tgt/BUILD_WITH_INSTALL_RPATH
    /prop_tgt/BUNDLE_EXTENSION
    /prop_tgt/BUNDLE
@@ -244,6 +245,7 @@ Properties on Targets
    /prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG
    /prop_tgt/RUNTIME_OUTPUT_NAME
    /prop_tgt/SKIP_BUILD_RPATH
+   /prop_tgt/SOURCE_DIR
    /prop_tgt/SOURCES
    /prop_tgt/SOVERSION
    /prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG
diff --git a/Help/prop_tgt/BINARY_DIR.rst b/Help/prop_tgt/BINARY_DIR.rst
new file mode 100644
index 0000000..a6c1c12
--- /dev/null
+++ b/Help/prop_tgt/BINARY_DIR.rst
@@ -0,0 +1,4 @@
+BINARY_DIR
+----------
+
+Reports the value of CMAKE_CURRENT_BINARY_DIR in the directory in which the target was defined.
diff --git a/Help/prop_tgt/SOURCE_DIR.rst b/Help/prop_tgt/SOURCE_DIR.rst
new file mode 100644
index 0000000..de93f29
--- /dev/null
+++ b/Help/prop_tgt/SOURCE_DIR.rst
@@ -0,0 +1,4 @@
+SOURCE_DIR
+----------
+
+Reports the value of CMAKE_CURRENT_SOURCE_DIR in the directory in which the target was defined.
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 0303f1e..ff4f161 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -2959,6 +2959,8 @@ const char *cmTarget::GetProperty(const std::string& prop,
   MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
   MAKE_STATIC_PROP(IMPORTED);
   MAKE_STATIC_PROP(NAME);
+  MAKE_STATIC_PROP(BINARY_DIR);
+  MAKE_STATIC_PROP(SOURCE_DIR);
   MAKE_STATIC_PROP(SOURCES);
 #undef MAKE_STATIC_PROP
   if(specialProps.empty())
@@ -2971,6 +2973,8 @@ const char *cmTarget::GetProperty(const std::string& prop,
     specialProps.insert(propCOMPILE_DEFINITIONS);
     specialProps.insert(propIMPORTED);
     specialProps.insert(propNAME);
+    specialProps.insert(propBINARY_DIR);
+    specialProps.insert(propSOURCE_DIR);
     specialProps.insert(propSOURCES);
     }
   if(specialProps.count(prop))
@@ -3053,6 +3057,14 @@ const char *cmTarget::GetProperty(const std::string& prop,
       {
       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)
       {
       if (this->Internal->SourceEntries.empty())


More information about the cmake-developers mailing list