Commit 0a122393 authored by Brad King's avatar Brad King
Browse files

Merge branch 'backport-fix-explicit-CMakeLists.txt'

parents 07604a76 8480c2af
...@@ -841,6 +841,19 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( ...@@ -841,6 +841,19 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
return buildFile; return buildFile;
} }
void cmGlobalXCodeGenerator::AddXCodeProjBuildRule(
cmGeneratorTarget* target, std::vector<cmSourceFile*>& sources) const
{
std::string listfile =
target->GetLocalGenerator()->GetCurrentSourceDirectory();
listfile += "/CMakeLists.txt";
cmSourceFile* srcCMakeLists = target->Makefile->GetOrCreateSource(listfile);
if (std::find(sources.begin(), sources.end(), srcCMakeLists) ==
sources.end()) {
sources.push_back(srcCMakeLists);
}
}
std::string GetSourcecodeValueFromFileExtension(const std::string& _ext, std::string GetSourcecodeValueFromFileExtension(const std::string& _ext,
const std::string& lang, const std::string& lang,
bool& keepLastKnownFileType) bool& keepLastKnownFileType)
...@@ -1063,10 +1076,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( ...@@ -1063,10 +1076,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
} }
// Add CMakeLists.txt file for user convenience. // Add CMakeLists.txt file for user convenience.
std::string listfile = this->AddXCodeProjBuildRule(gtgt, classes);
gtgt->GetLocalGenerator()->GetCurrentSourceDirectory();
listfile += "/CMakeLists.txt";
classes.push_back(gtgt->Makefile->GetOrCreateSource(listfile));
std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare()); std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
...@@ -2359,10 +2369,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget( ...@@ -2359,10 +2369,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget(
} }
// Add CMakeLists.txt file for user convenience. // Add CMakeLists.txt file for user convenience.
std::string listfile = this->AddXCodeProjBuildRule(gtgt, sources);
gtgt->GetLocalGenerator()->GetCurrentSourceDirectory();
listfile += "/CMakeLists.txt";
sources.push_back(gtgt->Makefile->GetOrCreateSource(listfile));
for (auto sourceFile : sources) { for (auto sourceFile : sources) {
if (!sourceFile->GetPropertyAsBool("GENERATED")) { if (!sourceFile->GetPropertyAsBool("GENERATED")) {
......
...@@ -198,6 +198,8 @@ private: ...@@ -198,6 +198,8 @@ private:
cmGeneratorTarget* target); cmGeneratorTarget* target);
cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, cmSourceFile* sf, cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, cmSourceFile* sf,
cmGeneratorTarget* gtgt); cmGeneratorTarget* gtgt);
void AddXCodeProjBuildRule(cmGeneratorTarget* target,
std::vector<cmSourceFile*>& sources) const;
bool CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&); bool CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
bool IsHeaderFile(cmSourceFile*); bool IsHeaderFile(cmSourceFile*);
void AddDependTarget(cmXCodeObject* target, cmXCodeObject* dependTarget); void AddDependTarget(cmXCodeObject* target, cmXCodeObject* dependTarget);
......
...@@ -1364,7 +1364,18 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, ...@@ -1364,7 +1364,18 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
for (size_t ci = 0; ci < configs.size(); ++ci) { for (size_t ci = 0; ci < configs.size(); ++ci) {
acs.Configs.push_back(ci); acs.Configs.push_back(ci);
} }
sources.Sources.emplace_back(std::move(acs)); bool haveCMakeLists = false;
for (cmGeneratorTarget::AllConfigSource& si : sources.Sources) {
if (si.Source == sf) {
haveCMakeLists = true;
// Replace the explicit source reference with our generated one.
si = acs;
break;
}
}
if (!haveCMakeLists) {
sources.Sources.emplace_back(std::move(acs));
}
} }
} }
......
...@@ -1894,7 +1894,14 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() ...@@ -1894,7 +1894,14 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
std::vector<cmGeneratorTarget::AllConfigSource> const& sources = std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
this->GeneratorTarget->GetAllConfigSources(); this->GeneratorTarget->GetAllConfigSources();
cmSourceFile const* srcCMakeLists =
this->LocalGenerator->CreateVCProjBuildRule();
for (cmGeneratorTarget::AllConfigSource const& si : sources) { for (cmGeneratorTarget::AllConfigSource const& si : sources) {
if (si.Source == srcCMakeLists) {
// Skip explicit reference to CMakeLists.txt source.
continue;
}
const char* tool = nullptr; const char* tool = nullptr;
switch (si.Kind) { switch (si.Kind) {
case cmGeneratorTarget::SourceKindAppManifest: case cmGeneratorTarget::SourceKindAppManifest:
......
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
if(NOT EXISTS "${vcProjectFile}")
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
return()
endif()
set(foundCMakeLists 0)
file(STRINGS "${vcProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "<([A-Za-z0-9_]+) +Include=.*CMakeLists.txt")
set(rule "${CMAKE_MATCH_1}")
if(NOT rule STREQUAL "CustomBuild")
set(RunCMake_TEST_FAILED "CMakeLists.txt referenced as ${rule} instead of CustomBuild")
return()
endif()
if(foundCMakeLists)
set(RunCMake_TEST_FAILED "CMakeLists.txt referenced multiple times")
return()
endif()
set(foundCMakeLists 1)
endif()
endforeach()
if(NOT foundCMakeLists)
set(RunCMake_TEST_FAILED "CMakeLists.txt not referenced")
endif()
set(CMAKE_CONFIGURATION_TYPES Debug)
enable_language(CXX)
add_executable(foo foo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
include(RunCMake) include(RunCMake)
run_cmake(ExplicitCMakeLists)
run_cmake(VsConfigurationType) run_cmake(VsConfigurationType)
run_cmake(VsTargetsFileReferences) run_cmake(VsTargetsFileReferences)
run_cmake(VsCustomProps) run_cmake(VsCustomProps)
......
set(xcProjectFile "${RunCMake_TEST_BINARY_DIR}/ExplicitCMakeLists.xcodeproj/project.pbxproj")
if(NOT EXISTS "${xcProjectFile}")
set(RunCMake_TEST_FAILED "Project file ${xcProjectFile} does not exist.")
return()
endif()
set(foundCMakeLists 0)
file(STRINGS "${xcProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "PBXBuildFile.*fileRef.*CMakeLists.txt")
if(foundCMakeLists)
set(RunCMake_TEST_FAILED "CMakeLists.txt referenced multiple times")
return()
endif()
set(foundCMakeLists 1)
endif()
endforeach()
if(NOT foundCMakeLists)
set(RunCMake_TEST_FAILED "CMakeLists.txt not referenced")
endif()
enable_language(CXX)
add_executable(foo foo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
...@@ -4,6 +4,8 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 9) ...@@ -4,6 +4,8 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 9)
set(IOS_DEPLOYMENT_TARGET "-DCMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET=10") set(IOS_DEPLOYMENT_TARGET "-DCMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET=10")
endif() endif()
run_cmake(ExplicitCMakeLists)
run_cmake(XcodeFileType) run_cmake(XcodeFileType)
run_cmake(XcodeAttributeLocation) run_cmake(XcodeAttributeLocation)
run_cmake(XcodeAttributeGenex) run_cmake(XcodeAttributeGenex)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment