1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-17 15:32:10 +08:00

Pass EXCLUDE_FROM_ALL from directory to targets

When a target is created it now inherits the EXCLUDE_FROM_ALL property
from its directory. This change makes it possible to include a target
in "all", even if its directory has been marked as EXCLUDE_FROM_ALL.
This commit is contained in:
Zack Galbreath
2019-01-15 17:26:02 -06:00
parent bd3685b6cf
commit dc6888573d
14 changed files with 92 additions and 29 deletions

View File

@@ -7,3 +7,9 @@ A property on a directory that indicates if its targets are excluded
from the default build target. If it is not, then with a Makefile for from the default build target. If it is not, then with a Makefile for
example typing make will cause the targets to be built. The same example typing make will cause the targets to be built. The same
concept applies to the default build of other generators. concept applies to the default build of other generators.
Targets inherit the :prop_tgt:`EXCLUDE_FROM_ALL` property from the directory
that they are created in. When a directory is excluded, all of its targets will
have :prop_tgt:`EXCLUDE_FROM_ALL` set to ``TRUE``. After creating such a target
you can change its :prop_tgt:`EXCLUDE_FROM_ALL` property to ``FALSE``. This
will cause the target to be included in the default build target.

View File

@@ -8,3 +8,6 @@ the default build target. If it is not, then with a Makefile for
example typing make will cause this target to be built. The same example typing make will cause this target to be built. The same
concept applies to the default build of other generators. Installing concept applies to the default build of other generators. Installing
a target with EXCLUDE_FROM_ALL set to true has undefined behavior. a target with EXCLUDE_FROM_ALL set to true has undefined behavior.
This property is enabled by default for targets that are created in
directories that have :prop_dir:`EXCLUDE_FROM_ALL` set to ``TRUE``.

View File

@@ -0,0 +1,7 @@
EXCLUDE_FROM_ALL
----------------
* A target's :prop_tgt:`EXCLUDE_FROM_ALL` property can now override the
setting of its directory. A target will now be built as part of "all"
if its :prop_tgt:`EXCLUDE_FROM_ALL` property is set to ``OFF``, even if its
containing directory is marked as :prop_dir:`EXCLUDE_FROM_ALL`.

View File

@@ -2034,17 +2034,10 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
return this->IsExcluded(rootSnp, snp); return this->IsExcluded(rootSnp, snp);
} }
bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, bool cmGlobalGenerator::IsExcluded(cmGeneratorTarget* target) const
cmGeneratorTarget* target) const
{ {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY || return target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
target->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { target->GetPropertyAsBool("EXCLUDE_FROM_ALL");
// This target is excluded from its directory.
return true;
}
// This target is included in its directory. Check whether the
// directory is excluded.
return this->IsExcluded(root, target->GetLocalGenerator());
} }
void cmGlobalGenerator::GetEnabledLanguages( void cmGlobalGenerator::GetEnabledLanguages(

View File

@@ -468,7 +468,7 @@ protected:
bool IsExcluded(cmStateSnapshot const& root, bool IsExcluded(cmStateSnapshot const& root,
cmStateSnapshot const& snp) const; cmStateSnapshot const& snp) const;
bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const; bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const;
bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) const; bool IsExcluded(cmGeneratorTarget* target) const;
virtual void InitializeProgressMarks() {} virtual void InitializeProgressMarks() {}
struct GlobalTargetInfo struct GlobalTargetInfo

View File

@@ -331,9 +331,9 @@ public:
return LocalGenerators; return LocalGenerators;
} }
bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) bool IsExcluded(cmGeneratorTarget* target)
{ {
return cmGlobalGenerator::IsExcluded(root, target); return cmGlobalGenerator::IsExcluded(target);
} }
int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; } int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; }

View File

@@ -702,7 +702,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
localName, depends, commands, true); localName, depends, commands, true);
// add the all/all dependency // add the all/all dependency
if (!this->IsExcluded(this->LocalGenerators[0], gtarget)) { if (!this->IsExcluded(gtarget)) {
depends.clear(); depends.clear();
depends.push_back(localName); depends.push_back(localName);
commands.clear(); commands.clear();
@@ -767,7 +767,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
"Pre-install relink rule for target.", localName, "Pre-install relink rule for target.", localName,
depends, commands, true); depends, commands, true);
if (!this->IsExcluded(this->LocalGenerators[0], gtarget)) { if (!this->IsExcluded(gtarget)) {
depends.clear(); depends.clear();
depends.push_back(localName); depends.push_back(localName);
commands.clear(); commands.clear();

View File

@@ -201,7 +201,7 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
tgt->IsImported()) { tgt->IsImported()) {
continue; continue;
} }
if (!this->IsExcluded(gen[0], tgt)) { if (!this->IsExcluded(tgt)) {
allBuild->AddUtility(tgt->GetName()); allBuild->AddUtility(tgt->GetName());
} }
} }

View File

@@ -522,10 +522,6 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
// now make the allbuild depend on all the non-utility targets // now make the allbuild depend on all the non-utility targets
// in the project // in the project
for (auto& gen : gens) { for (auto& gen : gens) {
if (this->IsExcluded(root, gen)) {
continue;
}
for (auto target : gen->GetGeneratorTargets()) { for (auto target : gen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::GLOBAL_TARGET) { if (target->GetType() == cmStateEnums::GLOBAL_TARGET) {
continue; continue;
@@ -558,8 +554,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
false, "", false, cmMakefile::AcceptObjectLibraryCommands); false, "", false, cmMakefile::AcceptObjectLibraryCommands);
} }
if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY && if (!this->IsExcluded(target)) {
!target->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
allbuild->AddUtility(target->GetName()); allbuild->AddUtility(target->GetName());
} }
} }

View File

@@ -90,9 +90,7 @@ void cmLocalNinjaGenerator::Generate()
if (tg) { if (tg) {
tg->Generate(); tg->Generate();
// Add the target to "all" if required. // Add the target to "all" if required.
if (!this->GetGlobalNinjaGenerator()->IsExcluded( if (!this->GetGlobalNinjaGenerator()->IsExcluded(target)) {
this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
target)) {
this->GetGlobalNinjaGenerator()->AddDependencyToAll(target); this->GetGlobalNinjaGenerator()->AddDependencyToAll(target);
} }
delete tg; delete tg;

View File

@@ -1127,7 +1127,7 @@ cmTarget* cmMakefile::AddUtilityCommand(
// Create a target instance for this utility. // Create a target instance for this utility.
cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName); cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName);
target->SetIsGeneratorProvided(origin == TargetOrigin::Generator); target->SetIsGeneratorProvided(origin == TargetOrigin::Generator);
if (excludeFromAll) { if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
if (!comment) { if (!comment) {
@@ -1662,7 +1662,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot); cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
this->GetGlobalGenerator()->AddMakefile(subMf); this->GetGlobalGenerator()->AddMakefile(subMf);
if (excludeFromAll) { if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
@@ -1958,7 +1958,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname,
// over changes in CMakeLists.txt, making the information stale and // over changes in CMakeLists.txt, making the information stale and
// hence useless. // hence useless.
target->ClearDependencyInformation(*this); target->ClearDependencyInformation(*this);
if (excludeFromAll) { if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
target->AddSources(srcs); target->AddSources(srcs);
@@ -1971,7 +1971,7 @@ cmTarget* cmMakefile::AddExecutable(const std::string& exeName,
bool excludeFromAll) bool excludeFromAll)
{ {
cmTarget* target = this->AddNewTarget(cmStateEnums::EXECUTABLE, exeName); cmTarget* target = this->AddNewTarget(cmStateEnums::EXECUTABLE, exeName);
if (excludeFromAll) { if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
target->AddSources(srcs); target->AddSources(srcs);

View File

@@ -1,4 +1,20 @@
add_library(bar STATIC bar.cpp) add_library(bar STATIC bar.cpp)
add_library(foo STATIC foo.cpp) add_library(foo STATIC foo.cpp)
add_library(baz STATIC foo.cpp)
set_target_properties(baz PROPERTIES EXCLUDE_FROM_ALL OFF)
file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/main.txt"
CONTENT "$<TARGET_FILE_NAME:main>")
file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/bar.txt"
CONTENT "$<TARGET_FILE_NAME:bar>")
file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/baz.txt"
CONTENT "$<TARGET_FILE_NAME:baz>")
target_include_directories(foo PUBLIC .) target_include_directories(foo PUBLIC .)

View File

@@ -0,0 +1,44 @@
# Use globbing to check if exes / libs were built because determining
# exactly where these files will live inside a CMake -P script is
# pretty challenging.
file(READ "${RunCMake_TEST_BINARY_DIR}/main.txt" main_exe)
file(READ "${RunCMake_TEST_BINARY_DIR}/bar.txt" bar_lib)
file(READ "${RunCMake_TEST_BINARY_DIR}/baz.txt" baz_lib)
set(found_main FALSE)
file(GLOB_RECURSE files
LIST_DIRECTORIES FALSE
RELATIVE "${RunCMake_TEST_BINARY_DIR}"
"${RunCMake_TEST_BINARY_DIR}/*")
foreach (file IN LISTS files)
if (file MATCHES "${main_exe}")
set(found_main TRUE)
endif()
endforeach()
if (NOT found_main)
set(RunCMake_TEST_FAILED "'main' missing from ${RunCMake_TEST_BINARY_DIR}")
endif()
set(found_bar FALSE)
set(found_baz FALSE)
file(GLOB_RECURSE files
LIST_DIRECTORIES FALSE
RELATIVE "${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll"
"${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll/*")
foreach (file IN LISTS files)
if (file MATCHES "${bar_lib}")
set(found_bar TRUE)
endif()
if (file MATCHES "${baz_lib}")
set(found_baz TRUE)
endif()
endforeach()
if (found_bar)
set(RunCMake_TEST_FAILED
"'bar' was not excluded from ${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll")
endif()
if (NOT found_baz)
set(RunCMake_TEST_FAILED
"'baz' missing from ${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll")
endif()

View File

@@ -33,6 +33,7 @@ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(ExcludeFromAll) run_cmake(ExcludeFromAll)
set(RunCMake-check-file ExcludeFromAll/check.cmake)
run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .) run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_BINARY_DIR) unset(RunCMake_TEST_BINARY_DIR)