Xcode: Do not append per-config suffixes to library search paths

Add policy `CMP0142` to remove the automatic addition of the
`$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)` suffix in a compatible way.

Fixes: #21757
This commit is contained in:
Mikko Sivulainen 2022-09-14 14:30:41 +03:00 committed by Brad King
parent c3e68020d6
commit d4cc39842e
8 changed files with 74 additions and 4 deletions

View File

@ -58,6 +58,7 @@ Policies Introduced by CMake 3.25
.. toctree::
:maxdepth: 1
CMP0142: The Xcode generator does not append per-config suffixes to library search paths. </policy/CMP0142>
CMP0141: MSVC debug information format flags are selected by an abstraction. </policy/CMP0141>
CMP0140: The return() command checks its arguments. </policy/CMP0140>

27
Help/policy/CMP0142.rst Normal file
View File

@ -0,0 +1,27 @@
CMP0142
-------
.. versionadded:: 3.25
The :generator:`Xcode` generator does not append per-config suffixes to
library search paths.
In CMake 3.24 and below, the :generator:`Xcode` generator preceded each
entry of a library search path with a copy of itself appended with
``$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)``. This was left from
very early versions of CMake in which per-config directories were not well
modeled. Such paths often do not exist, resulting in warnings from the
toolchain. CMake 3.25 and above prefer to not add such library search
paths. This policy provides compatibility for projects that may have been
accidentally relying on the old behavior.
The ``OLD`` behavior for this policy is to append
``$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)`` to all library search paths.
The ``NEW`` behavior is to not modify library search paths.
This policy was introduced in CMake version 3.25. Use the
:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
Unlike many policies, CMake version |release| does *not* warn
when this policy is not set and simply uses ``OLD`` behavior.
.. include:: DEPRECATED.txt

View File

@ -0,0 +1,6 @@
xcode-lib-dirs
--------------
* The :generator:`Xcode` generator no longer adds the per-config suffix
``$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)`` to library search paths.
See policy :policy:`CMP0142`.

View File

@ -3776,14 +3776,20 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
// add the library search paths
{
BuildObjectListOrString libSearchPaths(this, true);
std::string linkDirs;
for (auto const& libDir : cli->GetDirectories()) {
if (!libDir.empty() && libDir != "/usr/lib") {
libSearchPaths.Add(this->XCodeEscapePath(
libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"));
cmPolicies::PolicyStatus cmp0142 =
target->GetTarget()->GetPolicyStatusCMP0142();
if (cmp0142 == cmPolicies::OLD || cmp0142 == cmPolicies::WARN) {
libSearchPaths.Add(this->XCodeEscapePath(
libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"));
}
libSearchPaths.Add(this->XCodeEscapePath(libDir));
}
}
// Add previously collected paths where to look for libraries
// that were added to "Link Binary With Libraries"
for (auto& libDir : linkSearchPaths) {

View File

@ -427,7 +427,11 @@ class cmMakefile;
SELECT( \
POLICY, CMP0141, \
"MSVC debug information format flags are selected by an abstraction.", 3, \
25, 0, cmPolicies::WARN)
25, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0142, \
"The Xcode generator does not append per-config suffixes to " \
"library search paths.", \
3, 25, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@ -464,7 +468,8 @@ class cmMakefile;
F(CMP0112) \
F(CMP0113) \
F(CMP0119) \
F(CMP0131)
F(CMP0131) \
F(CMP0142)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies

View File

@ -36,6 +36,7 @@
\* CMP0113
\* CMP0119
\* CMP0131
\* CMP0142
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -12,6 +12,8 @@ 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_target_cmp0142old_LIBRARY_SEARCH_PATHS 0)
set(found_target_cmp0142new_LIBRARY_SEARCH_PATHS 0)
set(found_inherited_LIBRARY_SEARCH_PATHS 0)
file(STRINGS "${xcProjectFile}" lines)
foreach(line IN LISTS lines)
@ -42,6 +44,12 @@ foreach(line IN LISTS lines)
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 = \("(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathCMP0142OLD/\$\(CONFIGURATION\)\$\(EFFECTIVE_PLATFORM_NAME\)(\\")?","(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathCMP0142OLD(\\")?","\$\(inherited\)"\);]])
set(found_target_cmp0142old_LIBRARY_SEARCH_PATHS 1)
endif()
if(line MATCHES [[LIBRARY_SEARCH_PATHS = \("(\\")?[^"]*/Tests/RunCMake/XcodeProject/SearchPaths-build/TargetSearchPathCMP0142NEW(\\")?","\$\(inherited\)"\);]])
set(found_target_cmp0142new_LIBRARY_SEARCH_PATHS 1)
endif()
if(line MATCHES [[LIBRARY_SEARCH_PATHS = \("\$\(inherited\)"\);]])
set(found_inherited_LIBRARY_SEARCH_PATHS 1)
endif()
@ -68,6 +76,12 @@ 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(NOT found_target_cmp0142old_LIBRARY_SEARCH_PATHS)
string(APPEND RunCMake_TEST_FAILED "Did not find expected LIBRARY_SEARCH_PATHS for target 'cmp0142old' in\n ${xcProjectFile}\n")
endif()
if(NOT found_target_cmp0142new_LIBRARY_SEARCH_PATHS)
string(APPEND RunCMake_TEST_FAILED "Did not find expected LIBRARY_SEARCH_PATHS for target 'cmp0142new' 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()

View File

@ -3,6 +3,8 @@ 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")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathCMP0142OLD")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathCMP0142NEW")
set(CMAKE_XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "${CMAKE_CURRENT_BINARY_DIR}/ProjectSearchPath")
set(CMAKE_XCODE_ATTRIBUTE_LIBRARY_SEARCH_PATHS "${CMAKE_CURRENT_BINARY_DIR}/ProjectSearchPath")
@ -19,3 +21,11 @@ target_include_directories(include PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSe
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")
cmake_policy(SET CMP0142 OLD)
add_executable(cmp0142old main.c)
target_link_directories(cmp0142old PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathCMP0142OLD")
cmake_policy(SET CMP0142 NEW)
add_executable(cmp0142new main.c)
target_link_directories(cmp0142new PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TargetSearchPathCMP0142NEW")