diff options
author | Brad King <brad.king@kitware.com> | 2020-12-08 15:16:43 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-12-08 15:17:33 (GMT) |
commit | d00d5ac0cdf14c9622c1db01e37958dc075bd67e (patch) | |
tree | c3114477e7795b309428e08b5cbe5d26d36e00a4 | |
parent | 6aa3c3206e3c38d94e5c25f2d8fa726163944d01 (diff) | |
parent | 9af93fef11e9ea23d7d87a1c217254c482555262 (diff) | |
download | CMake-d00d5ac0cdf14c9622c1db01e37958dc075bd67e.zip CMake-d00d5ac0cdf14c9622c1db01e37958dc075bd67e.tar.gz CMake-d00d5ac0cdf14c9622c1db01e37958dc075bd67e.tar.bz2 |
Merge topic 'correct_ispc_path_computation' into release-3.19
9af93fef11 ISPC: Handle OBJECT sources in different directories
72ae15ebcb ISPC: Ninja properly compute ISPC_HEADER_DIRECTORY location
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5581
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 7 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 23 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 15 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/ISPC/ObjectLibrary/subdir/extra.ispc (renamed from Tests/ISPC/ObjectLibrary/extra.ispc) | 0 |
5 files changed, 32 insertions, 15 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index e735897..c299dad 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -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); } } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 61e7857..368f278 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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); } } @@ -4076,15 +4077,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; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 76df9f2..662399e 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1375,15 +1375,16 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( std::string ispcSource = cmSystemTools::GetFilenameWithoutLastExtension(objectName); - std::string ispcDirectory = objectFileDir; + std::string ispcHeaderDirectory = + this->GeneratorTarget->GetObjectDirectory(config); if (cmProp prop = this->GeneratorTarget->GetProperty("ISPC_HEADER_DIRECTORY")) { - ispcDirectory = *prop; + ispcHeaderDirectory = + cmStrCat(this->LocalGenerator->GetBinaryDirectory(), '/', *prop); } - ispcDirectory = - cmStrCat(this->LocalGenerator->GetBinaryDirectory(), '/', ispcDirectory); - std::string ispcHeader = cmStrCat(ispcDirectory, '/', ispcSource, ".h"); + std::string ispcHeader = + cmStrCat(ispcHeaderDirectory, '/', ispcSource, ".h"); ispcHeader = this->ConvertToNinjaPath(ispcHeader); // Make sure ninja knows what command generates the header @@ -1395,8 +1396,10 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( auto ispcSuffixes = detail::ComputeISPCObjectSuffixes(this->GeneratorTarget); if (ispcSuffixes.size() > 1) { + std::string rootObjectDir = + this->GeneratorTarget->GetObjectDirectory(config); auto ispcSideEfffectObjects = detail::ComputeISPCExtraObjects( - objectName, ispcDirectory, ispcSuffixes); + objectName, rootObjectDir, ispcSuffixes); for (auto sideEffect : ispcSideEfffectObjects) { sideEffect = this->ConvertToNinjaPath(sideEffect); diff --git a/Tests/ISPC/ObjectLibrary/CMakeLists.txt b/Tests/ISPC/ObjectLibrary/CMakeLists.txt index 4767d7e..a4c81a9 100644 --- a/Tests/ISPC/ObjectLibrary/CMakeLists.txt +++ b/Tests/ISPC/ObjectLibrary/CMakeLists.txt @@ -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") diff --git a/Tests/ISPC/ObjectLibrary/extra.ispc b/Tests/ISPC/ObjectLibrary/subdir/extra.ispc index 5a4a442..5a4a442 100644 --- a/Tests/ISPC/ObjectLibrary/extra.ispc +++ b/Tests/ISPC/ObjectLibrary/subdir/extra.ispc |