Makefiles: support shortened object filenames

This commit is contained in:
John Parent
2025-05-21 23:14:17 +02:00
committed by Ben Boeckel
parent b121adaa04
commit 3f33a5387a
18 changed files with 75 additions and 3 deletions

View File

@@ -8,3 +8,6 @@ short-object-names
is supported for the following generators:
- :ref:`Ninja Generators`
- :ref:`Makefile Generators`
Note that the strategy implementation may differ between generators.

View File

@@ -80,6 +80,11 @@ cmGlobalBorlandMakefileGenerator::GenerateBuildCommand(
cmake::NO_BUILD_PARALLEL_LEVEL, verbose, buildOptions, makeOptions);
}
std::string cmGlobalBorlandMakefileGenerator::GetShortBinaryOutputDir() const
{
return "_o";
}
void cmGlobalBorlandMakefileGenerator::PrintBuildCommandAdvice(
std::ostream& os, int jobs) const
{

View File

@@ -56,6 +56,8 @@ public:
bool IsGNUMakeJobServerAware() const override { return false; }
std::string GetShortBinaryOutputDir() const override;
protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
std::string const& makeProgram, std::string const& projectName,

View File

@@ -77,6 +77,11 @@ cmDocumentationEntry cmGlobalUnixMakefileGenerator3::GetDocumentation()
"Generates standard UNIX makefiles." };
}
bool cmGlobalUnixMakefileGenerator3::SupportsShortObjectNames() const
{
return true;
}
void cmGlobalUnixMakefileGenerator3::ComputeTargetObjectDirectory(
cmGeneratorTarget* gt) const
{

View File

@@ -195,6 +195,7 @@ public:
bool IsIPOSupported() const override { return true; }
bool SupportsShortObjectNames() const override;
void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
std::string IncludeDirective;

View File

@@ -75,6 +75,11 @@ cmGlobalWatcomWMakeGenerator::GenerateBuildCommand(
cmake::NO_BUILD_PARALLEL_LEVEL, verbose, buildOptions, makeOptions);
}
std::string cmGlobalWatcomWMakeGenerator::GetShortBinaryOutputDir() const
{
return "_o";
}
void cmGlobalWatcomWMakeGenerator::PrintBuildCommandAdvice(std::ostream& os,
int jobs) const
{

View File

@@ -55,6 +55,8 @@ public:
bool IsGNUMakeJobServerAware() const override { return false; }
std::string GetShortBinaryOutputDir() const override;
protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
std::string const& makeProgram, std::string const& projectName,

View File

@@ -201,6 +201,15 @@ void cmLocalUnixMakefileGenerator3::Generate()
this->WriteDirectoryInformationFile();
}
std::string cmLocalUnixMakefileGenerator3::GetObjectOutputRoot() const
{
if (this->UseShortObjectNames()) {
return cmStrCat(this->GetCurrentBinaryDirectory(), '/',
this->GetGlobalGenerator()->GetShortBinaryOutputDir());
}
return cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles");
}
void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
{
// Compute the path to use when referencing the current output

View File

@@ -43,6 +43,8 @@ public:
*/
void Generate() override;
std::string GetObjectOutputRoot() const override;
// this returns the relative path between the HomeOutputDirectory and this
// local generators StartOutputDirectory
std::string const& GetHomeRelativeOutputPath();

View File

@@ -39,6 +39,29 @@ function(run_VerboseBuild)
endfunction()
run_VerboseBuild()
function(run_VerboseBuildShort)
run_cmake(VerboseBuildShort)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VerboseBuildShort-build)
if(RunCMake_GENERATOR STREQUAL "Watcom WMake")
# wmake does not actually show the verbose output.
set(RunCMake-stdout-file VerboseBuildShort-build-watcom-stdout.txt)
endif()
run_cmake_command(VerboseBuildShort-build ${CMAKE_COMMAND} --build . -v --clean-first)
unset(RunCMake-stdout-file)
set(_backup_lang "$ENV{LANG}")
set(_backup_lc_Messages "$ENV{LC_MESSAGES}")
if(MAKE_IS_GNU)
set(RunCMake-stdout-file VerboseBuildShort-nowork-gnu-stdout.txt)
set(ENV{LANG} "C")
set(ENV{LC_MESSAGES} "C")
endif()
run_cmake_command(VerboseBuildShort-nowork ${CMAKE_COMMAND} --build . --verbose)
set(ENV{LANG} "${_backup_lang}")
set(ENV{LC_MESSAGES} "${_backup_lc_messages}")
endfunction()
run_VerboseBuildShort()
run_cmake(IncludeRegexSubdir)
function(run_MakefileConflict)

View File

@@ -1,3 +1,5 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
enable_language(C)
# Make sure compile command is not hidden in a temp file.

View File

@@ -0,0 +1 @@
DEFINE_FOR_VERBOSE_DETECTION.*.o[\\/]75d5d702[\\/]4efa03e1

View File

@@ -0,0 +1 @@
Building C object _o/75d5d702/4efa03e1.obj

View File

@@ -0,0 +1 @@
.*Nothing to be done for.*hello.*

View File

@@ -0,0 +1,10 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY SHORT CACHE STRING "" FORCE)
enable_language(C)
# Make sure compile command is not hidden in a temp file.
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
add_executable(hello hello.c)
target_compile_definitions(hello PRIVATE "DEFINE_FOR_VERBOSE_DETECTION")

View File

@@ -91,6 +91,6 @@ function(run_Dependencies suffix)
endfunction()
run_Dependencies("")
if (CMAKE_GENERATOR MATCHES "Ninja")
if (CMAKE_GENERATOR MATCHES "(Ninja|Makefiles)")
run_Dependencies(Short)
endif ()

View File

@@ -18,7 +18,7 @@ endfunction()
run_cmake(DisabledPch)
run_cmake(PchDebugGenex)
run_test(PchInterface)
if (CMAKE_GENERATOR MATCHES "Ninja")
if (CMAKE_GENERATOR MATCHES "(Ninja|Makefiles)")
run_test(PchInterfaceShort)
endif ()
run_test(PchInterfaceUnity)

View File

@@ -72,6 +72,6 @@ endfunction()
run_test(unitybuild_runtest)
run_test(unitybuild_object_library)
if (CMAKE_GENERATOR MATCHES "Ninja")
if (CMAKE_GENERATOR MATCHES "(Ninja|Makefiles)")
run_build(unitybuild_cxx_short)
endif ()