Use as dependency file <objectDir/SourceName>.d if needed. #318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use as dependency file name simply <objectDir/SourceName>.d if needed
Motivation
gcov, lcov
I have a particular problem with the cmake generated output file naming
conventions (like myfile.cpp.o, myfile.cpp.gcno, ....).
These naming conventions creating trouble for me to run
gcov *.cpp
properlywith my -o /objdir option (I had to copy them in the same directory without
the .ccp extensions every time!).
see https://cmake.org/pipermail/cmake/2012-August/051628.html
Ancien cross compiler
The C compiler test fails because CMake insists on createing
testCCompiler.c.r30 and there doesn't seem to be way to tell it to not
include the source file name extension (here: .c) into the object file name.
However, the linker takes the first dot as extension (I know that this is
horribly broken) and only takes files that have ".r30" as extension. ".c.r30"
is an illegal extension.
see https://cmake.org/pipermail/cmake/2008-April/021057.html
More proprietary compilers
Ninja generator sets the name to objectpath.d::
WindRiver sets the dependency file name to objectDir/SourceName.d, so the ".obj"
in "DEP_FILE = path/BaseName.c.obj.d" must be renamed!
see https://cmake.org/pipermail/cmake/2014-October/058963.html
GHS compiler too
Wenn using the Ninja generator to build with GHS compiler for Integrity targets,
we have the same problem. We can NOT control the name of the generated
dependency ".d" file while compile step!
"DEP_FILE = path/BaseName.d" has to be used!
see https://cmake.org/pipermail/cmake-developers/2018-January/030532.html
Solution
If we really want to avoid the extension we can set the undocumented internal
implementation detail variable::
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
some time after the project() command call that enables the C and CXX
languages.
Patch needed
Change the Nina generator::
file: Source/cmNinjaTargetGenerator.cxx
function: void cmNinjaTargetGenerator::WriteObjectBuildStatement(...)
// ...
if (!this->NeedDepTypeMSVC(language)) {
bool hasExtension(false);
std::string dependFileName = this->GetLocalGenerator()->
GetObjectFileNameWithoutTarget(*source, objectDir, &hasExtension);
if(hasExtension) {
// use original code
vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
objectFileName + ".d", cmOutputConverter::SHELL);
} else {
// Replace the original source file extension with the
// depend file extension.
std::string::size_type dot_pos = objectFileName.rfind('.');
if (dot_pos != std::string::npos) {
dependFileName = objectFileName.substr(0, dot_pos) + ".d";
}
vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
dependFileName, cmOutputConverter::SHELL);
}
}
Caveat
As the variables are internal details this will not be guaranteed to work in
the future!
Question
Is it possible to make the internal CMAKE__OUTPUT_EXTENSION_REPLACE
option public and support it in future CMake releases including my patch?