ISPC: Handle OBJECT sources in different directories

This commit is contained in:
Robert Maynard 2020-12-07 09:14:54 -05:00
parent 72ae15ebcb
commit 9af93fef11
4 changed files with 23 additions and 9 deletions

View File

@ -5107,9 +5107,14 @@ void cmGeneratorTarget::GetTargetObjectNames(
objects.push_back(map_it->second);
}
// We need to compute the relative path from the root of
// of the object directory to handle subdirectory paths
std::string rootObjectDir = this->GetObjectDirectory(config);
rootObjectDir = cmSystemTools::CollapseFullPath(rootObjectDir);
auto ispcObjects = this->GetGeneratedISPCObjects(config);
for (std::string const& output : ispcObjects) {
objects.push_back(cmSystemTools::GetFilenameName(output));
auto relativePathFromObjectDir = output.substr(rootObjectDir.size());
objects.push_back(relativePathFromObjectDir);
}
}

View File

@ -2434,9 +2434,10 @@ void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target)
this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
for (std::string const& config : configsList) {
std::string perConfigDir = target->GetObjectDirectory(config);
std::string rootObjectDir = target->GetObjectDirectory(config);
std::string headerDir = rootObjectDir;
if (cmProp prop = target->GetProperty("ISPC_HEADER_DIRECTORY")) {
perConfigDir = cmSystemTools::CollapseFullPath(
headerDir = cmSystemTools::CollapseFullPath(
cmStrCat(this->GetBinaryDirectory(), '/', *prop));
}
@ -2453,11 +2454,11 @@ void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target)
std::string ispcSource =
cmSystemTools::GetFilenameWithoutLastExtension(objectName);
auto headerPath = cmStrCat(perConfigDir, '/', ispcSource, ".h");
auto headerPath = cmStrCat(headerDir, '/', ispcSource, ".h");
target->AddISPCGeneratedHeader(headerPath, config);
if (extra_objects) {
std::vector<std::string> objs = detail::ComputeISPCExtraObjects(
objectName, perConfigDir, ispcSuffixes);
objectName, rootObjectDir, ispcSuffixes);
target->AddISPCGeneratedObject(std::move(objs), config);
}
}
@ -4074,15 +4075,23 @@ std::vector<std::string> ComputeISPCExtraObjects(
std::string const& objectName, std::string const& buildDirectory,
std::vector<std::string> const& ispcSuffixes)
{
auto normalizedDir = cmSystemTools::CollapseFullPath(buildDirectory);
std::vector<std::string> computedObjects;
computedObjects.reserve(ispcSuffixes.size());
auto extension = cmSystemTools::GetFilenameLastExtension(objectName);
auto objNameNoExt =
cmSystemTools::GetFilenameWithoutLastExtension(objectName);
// We can't use cmSystemTools::GetFilenameWithoutLastExtension as it
// drops any directories in objectName
auto objNameNoExt = objectName;
std::string::size_type dot_pos = objectName.rfind('.');
if (dot_pos != std::string::npos) {
objNameNoExt.resize(dot_pos);
}
for (const auto& ispcTarget : ispcSuffixes) {
computedObjects.emplace_back(
cmStrCat(buildDirectory, "/", objNameNoExt, "_", ispcTarget, extension));
cmStrCat(normalizedDir, "/", objNameNoExt, "_", ispcTarget, extension));
}
return computedObjects;

View File

@ -8,7 +8,7 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()
add_library(ispc_objects OBJECT simple.ispc extra.ispc)
add_library(ispc_objects OBJECT simple.ispc subdir/extra.ispc)
set_target_properties(ispc_objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(ispc_objects PROPERTIES ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i8x16")