mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 21:59:54 -06:00
Merge topic 'xcode-inherit-paths'
5115e8b2b6Xcode: Generalize inheritance of project-level search paths6b6230b23bcmGlobalXCodeGenerator: Factor out helper to append attribute Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5637
This commit is contained in:
@@ -3213,39 +3213,46 @@ void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
|
||||
if (!attr) {
|
||||
settings->AddAttribute(attribute, value);
|
||||
} else {
|
||||
if (value->GetType() != cmXCodeObject::OBJECT_LIST &&
|
||||
value->GetType() != cmXCodeObject::STRING) {
|
||||
cmSystemTools::Error("Unsupported value type for appending: " +
|
||||
std::string(attribute));
|
||||
return;
|
||||
}
|
||||
if (attr->GetType() == cmXCodeObject::OBJECT_LIST) {
|
||||
if (value->GetType() == cmXCodeObject::OBJECT_LIST) {
|
||||
for (auto* obj : value->GetObjectList()) {
|
||||
attr->AddObject(obj);
|
||||
}
|
||||
} else {
|
||||
attr->AddObject(value);
|
||||
}
|
||||
} else if (attr->GetType() == cmXCodeObject::STRING) {
|
||||
if (value->GetType() == cmXCodeObject::OBJECT_LIST) {
|
||||
// Add old value as a list item to new object list
|
||||
// and replace the attribute with the new list
|
||||
value->PrependObject(attr);
|
||||
settings->AddAttribute(attribute, value);
|
||||
} else {
|
||||
std::string newValue =
|
||||
cmStrCat(attr->GetString(), ' ', value->GetString());
|
||||
attr->SetString(newValue);
|
||||
}
|
||||
} else {
|
||||
cmSystemTools::Error("Unsupported attribute type for appending: " +
|
||||
std::string(attribute));
|
||||
}
|
||||
this->AppendBuildSettingAttribute(settings, attribute, attr, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalXCodeGenerator::AppendBuildSettingAttribute(
|
||||
cmXCodeObject* settings, const char* attribute, cmXCodeObject* attr,
|
||||
cmXCodeObject* value)
|
||||
{
|
||||
if (value->GetType() != cmXCodeObject::OBJECT_LIST &&
|
||||
value->GetType() != cmXCodeObject::STRING) {
|
||||
cmSystemTools::Error("Unsupported value type for appending: " +
|
||||
std::string(attribute));
|
||||
return;
|
||||
}
|
||||
if (attr->GetType() == cmXCodeObject::OBJECT_LIST) {
|
||||
if (value->GetType() == cmXCodeObject::OBJECT_LIST) {
|
||||
for (auto* obj : value->GetObjectList()) {
|
||||
attr->AddObject(obj);
|
||||
}
|
||||
} else {
|
||||
attr->AddObject(value);
|
||||
}
|
||||
} else if (attr->GetType() == cmXCodeObject::STRING) {
|
||||
if (value->GetType() == cmXCodeObject::OBJECT_LIST) {
|
||||
// Add old value as a list item to new object list
|
||||
// and replace the attribute with the new list
|
||||
value->PrependObject(attr);
|
||||
settings->AddAttribute(attribute, value);
|
||||
} else {
|
||||
std::string newValue =
|
||||
cmStrCat(attr->GetString(), ' ', value->GetString());
|
||||
attr->SetString(newValue);
|
||||
}
|
||||
} else {
|
||||
cmSystemTools::Error("Unsupported attribute type for appending: " +
|
||||
std::string(attribute));
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalXCodeGenerator::AppendBuildSettingAttribute(
|
||||
cmXCodeObject* target, const char* attribute, cmXCodeObject* value,
|
||||
const std::string& configName)
|
||||
@@ -3265,6 +3272,24 @@ void cmGlobalXCodeGenerator::AppendBuildSettingAttribute(
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalXCodeGenerator::InheritBuildSettingAttribute(
|
||||
cmXCodeObject* target, const char* attribute)
|
||||
{
|
||||
cmXCodeObject* configurationList =
|
||||
target->GetAttribute("buildConfigurationList")->GetObject();
|
||||
cmXCodeObject* buildConfigs =
|
||||
configurationList->GetAttribute("buildConfigurations");
|
||||
for (auto obj : buildConfigs->GetObjectList()) {
|
||||
cmXCodeObject* settings = obj->GetAttribute("buildSettings");
|
||||
if (cmXCodeObject* attr = settings->GetAttribute(attribute)) {
|
||||
BuildObjectListOrString inherited(this, true);
|
||||
inherited.Add("$(inherited)");
|
||||
this->AppendBuildSettingAttribute(settings, attribute, attr,
|
||||
inherited.CreateList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
|
||||
{
|
||||
cmGeneratorTarget* gt = target->GetTarget();
|
||||
@@ -3581,11 +3606,11 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
|
||||
for (auto& libDir : linkSearchPaths) {
|
||||
libSearchPaths.Add(this->XCodeEscapePath(libDir));
|
||||
}
|
||||
// Add paths defined in project-wide build settings
|
||||
libSearchPaths.Add("$(inherited)");
|
||||
this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
|
||||
libSearchPaths.CreateList(),
|
||||
configName);
|
||||
if (!libSearchPaths.IsEmpty()) {
|
||||
this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
|
||||
libSearchPaths.CreateList(),
|
||||
configName);
|
||||
}
|
||||
}
|
||||
|
||||
// add framework search paths
|
||||
@@ -3596,11 +3621,11 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
|
||||
for (auto& fwDir : frameworkSearchPaths) {
|
||||
fwSearchPaths.Add(this->XCodeEscapePath(fwDir));
|
||||
}
|
||||
// Add paths defined in project-wide build settings
|
||||
fwSearchPaths.Add("$(inherited)");
|
||||
this->AppendBuildSettingAttribute(target, "FRAMEWORK_SEARCH_PATHS",
|
||||
fwSearchPaths.CreateList(),
|
||||
configName);
|
||||
if (!fwSearchPaths.IsEmpty()) {
|
||||
this->AppendBuildSettingAttribute(target, "FRAMEWORK_SEARCH_PATHS",
|
||||
fwSearchPaths.CreateList(),
|
||||
configName);
|
||||
}
|
||||
}
|
||||
|
||||
// now add the left-over link libraries
|
||||
@@ -4154,6 +4179,13 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
|
||||
for (auto t : targets) {
|
||||
this->AddDependAndLinkInformation(t);
|
||||
this->AddEmbeddedFrameworks(t);
|
||||
// Inherit project-wide values for any target-specific search paths.
|
||||
this->InheritBuildSettingAttribute(t, "HEADER_SEARCH_PATHS");
|
||||
this->InheritBuildSettingAttribute(t, "SYSTEM_HEADER_SEARCH_PATHS");
|
||||
this->InheritBuildSettingAttribute(t, "FRAMEWORK_SEARCH_PATHS");
|
||||
this->InheritBuildSettingAttribute(t, "SYSTEM_FRAMEWORK_SEARCH_PATHS");
|
||||
this->InheritBuildSettingAttribute(t, "LIBRARY_SEARCH_PATHS");
|
||||
this->InheritBuildSettingAttribute(t, "LD_RUNPATH_SEARCH_PATHS");
|
||||
}
|
||||
|
||||
if (this->XcodeBuildSystem == BuildSystem::One) {
|
||||
|
||||
@@ -182,9 +182,14 @@ private:
|
||||
cmGeneratorTarget* gtgt);
|
||||
void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
|
||||
cmXCodeObject* value);
|
||||
void AppendBuildSettingAttribute(cmXCodeObject* settings,
|
||||
const char* attribute, cmXCodeObject* attr,
|
||||
cmXCodeObject* value);
|
||||
void AppendBuildSettingAttribute(cmXCodeObject* target, const char* attr,
|
||||
cmXCodeObject* value,
|
||||
const std::string& configName);
|
||||
void InheritBuildSettingAttribute(cmXCodeObject* target,
|
||||
const char* attribute);
|
||||
cmXCodeObject* CreateUtilityTarget(cmGeneratorTarget* gtgt);
|
||||
void AddDependAndLinkInformation(cmXCodeObject* target);
|
||||
void AddEmbeddedFrameworks(cmXCodeObject* target);
|
||||
|
||||
@@ -3,6 +3,7 @@ include(RunCMake)
|
||||
run_cmake(ExplicitCMakeLists)
|
||||
run_cmake(ImplicitCMakeLists)
|
||||
run_cmake(InterfaceLibSources)
|
||||
run_cmake_with_options(SearchPaths -DCMAKE_CONFIGURATION_TYPES=Debug)
|
||||
|
||||
run_cmake(XcodeFileType)
|
||||
run_cmake(XcodeAttributeLocation)
|
||||
|
||||
76
Tests/RunCMake/XcodeProject/SearchPaths-check.cmake
Normal file
76
Tests/RunCMake/XcodeProject/SearchPaths-check.cmake
Normal file
@@ -0,0 +1,76 @@
|
||||
set(xcProjectFile "${RunCMake_TEST_BINARY_DIR}/SearchPaths.xcodeproj/project.pbxproj")
|
||||
if(NOT EXISTS "${xcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${xcProjectFile} does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(relevant_lines "")
|
||||
set(found_project_FRAMEWORK_SEARCH_PATHS 0)
|
||||
set(found_target_both_FRAMEWORK_SEARCH_PATHS 0)
|
||||
set(found_target_include_FRAMEWORK_SEARCH_PATHS 0)
|
||||
set(found_target_library_FRAMEWORK_SEARCH_PATHS 0)
|
||||
set(found_inherited_FRAMEWORK_SEARCH_PATHS 0)
|
||||
set(found_project_LIBRARY_SEARCH_PATHS 0)
|
||||
set(found_target_library_LIBRARY_SEARCH_PATHS 0)
|
||||
set(found_inherited_LIBRARY_SEARCH_PATHS 0)
|
||||
file(STRINGS "${xcProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES [[FRAMEWORK_SEARCH_PATHS]])
|
||||
string(APPEND relevant_lines " ${line}\n")
|
||||
if(line MATCHES [[FRAMEWORK_SEARCH_PATHS = "[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/ProjectSearchPath";]])
|
||||
set(found_project_FRAMEWORK_SEARCH_PATHS 1)
|
||||
endif()
|
||||
if(line MATCHES [[FRAMEWORK_SEARCH_PATHS = \("(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathInc(\\")?","(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathLib(\\")?","\$\(inherited\)"\);]])
|
||||
set(found_target_both_FRAMEWORK_SEARCH_PATHS 1)
|
||||
endif()
|
||||
if(line MATCHES [[FRAMEWORK_SEARCH_PATHS = \("(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathInc(\\")?","\$\(inherited\)"\);]])
|
||||
set(found_target_include_FRAMEWORK_SEARCH_PATHS 1)
|
||||
endif()
|
||||
if(line MATCHES [[FRAMEWORK_SEARCH_PATHS = \("(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathLib(\\")?","\$\(inherited\)"\);]])
|
||||
set(found_target_library_FRAMEWORK_SEARCH_PATHS 1)
|
||||
endif()
|
||||
if(line MATCHES [[FRAMEWORK_SEARCH_PATHS = \("\$\(inherited\)"\);]])
|
||||
set(found_inherited_FRAMEWORK_SEARCH_PATHS 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(line MATCHES [[LIBRARY_SEARCH_PATHS]])
|
||||
string(APPEND relevant_lines " ${line}\n")
|
||||
if(line MATCHES [[LIBRARY_SEARCH_PATHS = "[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/ProjectSearchPath";]])
|
||||
set(found_project_LIBRARY_SEARCH_PATHS 1)
|
||||
endif()
|
||||
if(line MATCHES [[LIBRARY_SEARCH_PATHS = \("(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathLib/\$\(CONFIGURATION\)\$\(EFFECTIVE_PLATFORM_NAME\)(\\")?","(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathLib(\\")?","\$\(inherited\)"\);]])
|
||||
set(found_target_library_LIBRARY_SEARCH_PATHS 1)
|
||||
endif()
|
||||
if(line MATCHES [[LIBRARY_SEARCH_PATHS = \("\$\(inherited\)"\);]])
|
||||
set(found_inherited_LIBRARY_SEARCH_PATHS 1)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if(NOT found_project_FRAMEWORK_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Did not find expected FRAMEWORK_SEARCH_PATHS for project in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(NOT found_target_both_FRAMEWORK_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Did not find expected FRAMEWORK_SEARCH_PATHS for target 'both' in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(NOT found_target_include_FRAMEWORK_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Did not find expected LIBRARY_SEARCH_PATHS for target 'include' in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(NOT found_target_library_FRAMEWORK_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Did not find expected LIBRARY_SEARCH_PATHS for target 'library' in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(found_inherited_FRAMEWORK_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Found unexpected LIBRARY_SEARCH_PATHS inherited-only value in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(NOT found_project_LIBRARY_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Did not find expected LIBRARY_SEARCH_PATHS for project in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(NOT found_target_library_LIBRARY_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Did not find expected LIBRARY_SEARCH_PATHS for target 'library' in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(found_inherited_LIBRARY_SEARCH_PATHS)
|
||||
string(APPEND RunCMake_TEST_FAILED "Found unexpected LIBRARY_SEARCH_PATHS inherited-only value in\n ${xcProjectFile}\n")
|
||||
endif()
|
||||
if(RunCMake_TEST_FAILED)
|
||||
string(APPEND RunCMake_TEST_FAILED "Relevant lines include\n${relevant_lines}")
|
||||
endif()
|
||||
21
Tests/RunCMake/XcodeProject/SearchPaths.cmake
Normal file
21
Tests/RunCMake/XcodeProject/SearchPaths.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
enable_language(C)
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ProjectSearchPath")
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathInc/TargetInc.framework")
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathLib/TargetLib.framework")
|
||||
|
||||
set(CMAKE_XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "${CMAKE_CURRENT_BINARY_DIR}/ProjectSearchPath")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_LIBRARY_SEARCH_PATHS "${CMAKE_CURRENT_BINARY_DIR}/ProjectSearchPath")
|
||||
|
||||
add_executable(neither main.c)
|
||||
|
||||
add_executable(both main.c)
|
||||
target_include_directories(both PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathInc/TargetInc.framework")
|
||||
target_link_libraries(both PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathLib/TargetLib.framework")
|
||||
|
||||
add_executable(include main.c)
|
||||
target_include_directories(include PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathInc/TargetInc.framework")
|
||||
|
||||
add_executable(library main.c)
|
||||
target_link_libraries(library PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathLib/TargetLib.framework")
|
||||
target_link_directories(library PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathLib")
|
||||
Reference in New Issue
Block a user