Browse Source

ENH: Add LOCATION to GET_TARGET_PROPERTY. Closes Bug #34 - Add to GET_TARGET_PROPERTY location of target

Andy Cedilnik 21 years ago
parent
commit
b2bddc9f0d
2 changed files with 48 additions and 4 deletions
  1. 44 3
      Source/cmGetTargetPropertyCommand.cxx
  2. 4 1
      Tests/CustomCommand/CMakeLists.txt

+ 44 - 3
Source/cmGetTargetPropertyCommand.cxx

@@ -32,12 +32,53 @@ bool cmGetTargetPropertyCommand::InitialPass(
   if ( i != targets.end())
     {
     cmTarget& target = i->second;
-    const char *prop = target.GetProperty(args[2].c_str());
-    if (prop)
+    if ( args[2] == "LOCATION" )
       {
-      m_Makefile->AddDefinition(var, prop);
+      std::string target_location;
+      switch( target.GetType() )
+        {
+      case cmTarget::STATIC_LIBRARY:
+      case cmTarget::MODULE_LIBRARY:
+      case cmTarget::SHARED_LIBRARY:
+        target_location = m_Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
+        break;
+      case cmTarget::EXECUTABLE:
+        target_location = m_Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
+        break;
+      default:
+        m_Makefile->AddDefinition(var, "NOTFOUND");
+        return true;
+        }
+      if ( target_location.size() == 0 )
+        {
+        target_location += m_Makefile->GetCurrentOutputDirectory();
+        }
+      if ( target_location.size() > 0 )
+        {
+        target_location += "/";
+        }
+      const char* cfgid = m_Makefile->GetDefinition("CMAKE_CFG_INTDIR");
+      if ( cfgid && strcmp(cfgid, ".") != 0 )
+        {
+        target_location += cfgid;
+        target_location += "/";
+        }
+
+      cmLocalGenerator* lg = m_Makefile->GetLocalGenerator();
+      target_location += lg->GetFullTargetName(targetName, target);
+      m_Makefile->AddDefinition(var, target_location.c_str());
       return true;
       }
+    else
+      {
+      const char *prop = 0;
+      prop = target.GetProperty(args[2].c_str());
+      if (prop)
+        {
+        m_Makefile->AddDefinition(var, prop);
+        return true;
+        }
+      }
     }
   m_Makefile->AddDefinition(var, "NOTFOUND");
   return true;

+ 4 - 1
Tests/CustomCommand/CMakeLists.txt

@@ -22,12 +22,15 @@ SET (EXECUTABLE_OUTPUT_PATH
 # add the executable that will generate the file
 ADD_EXECUTABLE(generator generator.cxx)
 
+GET_TARGET_PROPERTY(generator_PATH generator LOCATION)
+MESSAGE("Location ${generator_PATH}")
+
 # the folowing assumes that a cmSourceFile
 # is instantiated for the output, with GENERATED 1
 # at the end of the day this becomes a what in VS ?
 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/generated.c
   DEPENDS generator
-  COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/generator
+  COMMAND ${generator_PATH}
   ARGS ${PROJECT_BINARY_DIR}/generated.c
   )