Add EXPORT_NAME property.
This allows for example, the buildsystem to use names like 'boost_any' instead of the overly generic 'any', and still be able to generate IMPORTED targets called 'boost::any'.
This commit is contained in:
parent
edeabd18e6
commit
b5d6f5dd5b
|
@ -30,7 +30,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
|
|||
tei = this->Exports->begin();
|
||||
tei != this->Exports->end(); ++tei)
|
||||
{
|
||||
expectedTargets += sep + this->Namespace + (*tei)->GetName();
|
||||
expectedTargets += sep + this->Namespace + (*tei)->GetExportName();
|
||||
sep = " ";
|
||||
cmTarget* te = *tei;
|
||||
if(this->ExportedTargets.insert(te).second)
|
||||
|
@ -189,7 +189,7 @@ cmExportBuildFileGenerator::HandleMissingTarget(
|
|||
// Assume the target will be exported by another command.
|
||||
// Append it with the export namespace.
|
||||
link_libs += this->Namespace;
|
||||
link_libs += dependee->GetName();
|
||||
link_libs += dependee->GetExportName();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -376,7 +376,7 @@ void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget *target,
|
|||
if (!properties.empty())
|
||||
{
|
||||
std::string targetName = this->Namespace;
|
||||
targetName += target->GetName();
|
||||
targetName += target->GetExportName();
|
||||
os << "set_target_properties(" << targetName << " PROPERTIES\n";
|
||||
for(ImportPropertyMap::const_iterator pi = properties.begin();
|
||||
pi != properties.end(); ++pi)
|
||||
|
@ -407,7 +407,7 @@ cmExportFileGenerator::AddTargetNamespace(std::string &input,
|
|||
}
|
||||
if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end())
|
||||
{
|
||||
input = this->Namespace + input;
|
||||
input = this->Namespace + tgt->GetExportName();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -772,7 +772,8 @@ cmExportFileGenerator
|
|||
{
|
||||
// Construct the imported target name.
|
||||
std::string targetName = this->Namespace;
|
||||
targetName += target->GetName();
|
||||
|
||||
targetName += target->GetExportName();
|
||||
|
||||
// Create the imported target.
|
||||
os << "# Create imported target " << targetName << "\n";
|
||||
|
@ -835,7 +836,8 @@ cmExportFileGenerator
|
|||
{
|
||||
// Construct the imported target name.
|
||||
std::string targetName = this->Namespace;
|
||||
targetName += target->GetName();
|
||||
|
||||
targetName += target->GetExportName();
|
||||
|
||||
// Set the import properties.
|
||||
os << "# Import target \"" << targetName << "\" for configuration \""
|
||||
|
@ -954,7 +956,7 @@ cmExportFileGenerator
|
|||
{
|
||||
// Construct the imported target name.
|
||||
std::string targetName = this->Namespace;
|
||||
targetName += target->GetName();
|
||||
targetName += target->GetExportName();
|
||||
|
||||
os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n"
|
||||
"list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " ";
|
||||
|
|
|
@ -47,7 +47,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
|
|||
tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
|
||||
tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei)
|
||||
{
|
||||
expectedTargets += sep + this->Namespace + (*tei)->Target->GetName();
|
||||
expectedTargets += sep + this->Namespace + (*tei)->Target->GetExportName();
|
||||
sep = " ";
|
||||
cmTargetExport const* te = *tei;
|
||||
if(this->ExportedTargets.insert(te->Target).second)
|
||||
|
@ -395,13 +395,14 @@ cmExportInstallFileGenerator::HandleMissingTarget(
|
|||
std::string& link_libs, std::vector<std::string>& missingTargets,
|
||||
cmMakefile* mf, cmTarget* depender, cmTarget* dependee)
|
||||
{
|
||||
std::string name = dependee->GetName();
|
||||
const std::string name = dependee->GetName();
|
||||
std::vector<std::string> namespaces = this->FindNamespaces(mf, name);
|
||||
int targetOccurrences = (int)namespaces.size();
|
||||
if (targetOccurrences == 1)
|
||||
{
|
||||
std::string missingTarget = namespaces[0];
|
||||
missingTarget += name;
|
||||
|
||||
missingTarget += dependee->GetExportName();
|
||||
link_libs += missingTarget;
|
||||
missingTargets.push_back(missingTarget);
|
||||
}
|
||||
|
|
|
@ -866,6 +866,13 @@ void cmTarget::DefineProperties(cmake *cm)
|
|||
"This property is the configuration-specific version of "
|
||||
"OSX_ARCHITECTURES.");
|
||||
|
||||
cm->DefineProperty
|
||||
("EXPORT_NAME", cmProperty::TARGET,
|
||||
"Exported name for target files.",
|
||||
"This sets the name for the IMPORTED target generated when it this "
|
||||
"target is is exported. "
|
||||
"If not set, the logical target name is used by default.");
|
||||
|
||||
cm->DefineProperty
|
||||
("OUTPUT_NAME", cmProperty::TARGET,
|
||||
"Output name for target files.",
|
||||
|
@ -2719,6 +2726,14 @@ void cmTarget::SetProperty(const char* prop, const char* value)
|
|||
new cmTargetInternals::IncludeDirectoriesEntry(cge));
|
||||
return;
|
||||
}
|
||||
if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported())
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "EXPORT_NAME property can't be set on imported targets (\""
|
||||
<< this->Name << "\")\n";
|
||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
|
||||
return;
|
||||
}
|
||||
if (strcmp(prop, "LINK_LIBRARIES") == 0)
|
||||
{
|
||||
this->Internal->LinkInterfaceIncludeDirectoriesEntries.clear();
|
||||
|
@ -2753,6 +2768,14 @@ void cmTarget::AppendProperty(const char* prop, const char* value,
|
|||
new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(value)));
|
||||
return;
|
||||
}
|
||||
if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported())
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "EXPORT_NAME property can't be set on imported targets (\""
|
||||
<< this->Name << "\")\n";
|
||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
|
||||
return;
|
||||
}
|
||||
if (strcmp(prop, "LINK_LIBRARIES") == 0)
|
||||
{
|
||||
if (cmGeneratorExpression::IsValidTargetName(value)
|
||||
|
@ -2769,6 +2792,26 @@ void cmTarget::AppendProperty(const char* prop, const char* value,
|
|||
this->MaybeInvalidatePropertyCache(prop);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const char* cmTarget::GetExportName()
|
||||
{
|
||||
const char *exportName = this->GetProperty("EXPORT_NAME");
|
||||
|
||||
if (exportName && *exportName)
|
||||
{
|
||||
if (!cmGeneratorExpression::IsValidTargetName(exportName))
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "EXPORT_NAME property \"" << exportName << "\" for \""
|
||||
<< this->GetName() << "\": is not valid.";
|
||||
cmSystemTools::Error(e.str().c_str());
|
||||
return "";
|
||||
}
|
||||
return exportName;
|
||||
}
|
||||
return this->GetName();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmTarget::AppendBuildInterfaceIncludes()
|
||||
{
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
|
||||
///! Set/Get the name of the target
|
||||
const char* GetName() const {return this->Name.c_str();}
|
||||
const char* GetExportName();
|
||||
|
||||
///! Set the cmMakefile that owns this target
|
||||
void SetMakefile(cmMakefile *mf);
|
||||
|
|
|
@ -165,6 +165,8 @@ set_property(TARGET testLibRequired APPEND PROPERTY
|
|||
|
||||
include(GenerateExportHeader)
|
||||
|
||||
add_subdirectory(renamed)
|
||||
|
||||
add_library(testSharedLibRequired SHARED testSharedLibRequired.cpp)
|
||||
generate_export_header(testSharedLibRequired)
|
||||
set_property(TARGET testSharedLibRequired
|
||||
|
@ -219,13 +221,12 @@ set_property(TARGET testSharedLibDepends APPEND PROPERTY
|
|||
INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/testSharedLibDepends>"
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||
)
|
||||
set_property(TARGET testSharedLibDepends APPEND PROPERTY
|
||||
LINK_INTERFACE_LIBRARIES
|
||||
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:$<TARGET_NAME:testSharedLibRequired>>
|
||||
)
|
||||
|
||||
# LINK_PRIVATE because the LINK_INTERFACE_LIBRARIES is specified above.
|
||||
target_link_libraries(testSharedLibDepends LINK_PRIVATE testSharedLibRequired)
|
||||
target_link_libraries(testSharedLibDepends LINK_PUBLIC renamed_on_export)
|
||||
target_link_libraries(testSharedLibDepends LINK_INTERFACE_LIBRARIES
|
||||
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:$<TARGET_NAME:testSharedLibRequired>>)
|
||||
|
||||
install(TARGETS testLibRequired
|
||||
testLibIncludeRequired1
|
||||
|
@ -310,7 +311,7 @@ add_subdirectory(sublib) # For CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE test.
|
|||
# Export from build tree.
|
||||
export(TARGETS testExe1 testLib1 testLib2 testLib3
|
||||
testExe2libImp testLib3Imp testLib3ImpDep subdirlib
|
||||
testSharedLibRequired testSharedLibDepends
|
||||
testSharedLibRequired testSharedLibDepends renamed_on_export
|
||||
NAMESPACE bld_
|
||||
FILE ExportBuildTree.cmake
|
||||
)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
add_library(renamed_on_export SHARED renamed.cxx)
|
||||
generate_export_header(renamed_on_export)
|
||||
target_include_directories(renamed_on_export
|
||||
PUBLIC "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/renamed>"
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||
)
|
||||
set_property(TARGET renamed_on_export
|
||||
PROPERTY
|
||||
EXPORT_NAME renamed
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/renamed.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/renamed_on_export_export.h"
|
||||
DESTINATION include/renamed
|
||||
)
|
||||
|
||||
install(TARGETS renamed_on_export
|
||||
EXPORT exp DESTINATION lib )
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
#include "renamed.h"
|
||||
|
||||
int Renamed::foo()
|
||||
{
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#ifndef RENAMED_H
|
||||
#define RENAMED_H
|
||||
|
||||
#include "renamed_on_export_export.h"
|
||||
|
||||
struct RENAMED_ON_EXPORT_EXPORT Renamed
|
||||
{
|
||||
int foo();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -4,5 +4,6 @@
|
|||
int TestSharedLibDepends::foo()
|
||||
{
|
||||
TestSharedLibRequired req;
|
||||
return req.foo();
|
||||
Renamed renamed;
|
||||
return req.foo() + renamed.foo();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "testsharedlibdepends_export.h"
|
||||
|
||||
#include "testSharedLibRequired.h"
|
||||
#include "renamed.h"
|
||||
|
||||
struct TESTSHAREDLIBDEPENDS_EXPORT TestSharedLibDepends
|
||||
{
|
||||
|
|
|
@ -183,6 +183,12 @@ else()
|
|||
endif()
|
||||
endif()
|
||||
|
||||
add_executable(exp_renamed_test renamed_test.cpp)
|
||||
target_link_libraries(exp_renamed_test exp_renamed)
|
||||
|
||||
add_executable(bld_renamed_test renamed_test.cpp)
|
||||
target_link_libraries(bld_renamed_test bld_renamed)
|
||||
|
||||
if (run_pic_test)
|
||||
target_compile_definitions(deps_shared_iface PRIVATE CHECK_PIC_WORKS)
|
||||
endif()
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#ifdef TEST_SUBDIR_LIB
|
||||
#include "subdir.h"
|
||||
#include "renamed.h"
|
||||
#endif
|
||||
|
||||
int main(int,char **)
|
||||
|
@ -31,11 +32,12 @@ int main(int,char **)
|
|||
|
||||
#ifdef TEST_SUBDIR_LIB
|
||||
SubDirObject sdo;
|
||||
Renamed ren;
|
||||
#endif
|
||||
|
||||
return dep.foo() + req.foo()
|
||||
#ifdef TEST_SUBDIR_LIB
|
||||
+ sdo.foo()
|
||||
+ sdo.foo() + ren.foo()
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "renamed.h"
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
Renamed ren;
|
||||
return ren.foo();
|
||||
}
|
Loading…
Reference in New Issue