COMPILE_ONLY: Genex now stops object libraries from linking
Previously we didn't properly exclude $<COMPILE_ONLY:OBJECT lib>
from the right hand side of `target_link_libraries`.
Fix the update that commit 73337cb383
(LINK_LIBRARIES: Evaluate
separately for linking and usage requirements, 2022-03-22,
v3.24.0-rc1~404^2~2) made to `AddObjectEntries`.
Fixes: #26642
This commit is contained in:
parent
7210f2d8c3
commit
c87004fdc3
@ -51,7 +51,7 @@ void AddObjectEntries(cmGeneratorTarget const* headTarget,
|
||||
EvaluatedTargetPropertyEntries& entries)
|
||||
{
|
||||
if (cmLinkImplementationLibraries const* impl =
|
||||
headTarget->GetLinkImplementationLibraries(config, UseTo::Compile)) {
|
||||
headTarget->GetLinkImplementationLibraries(config, UseTo::Link)) {
|
||||
entries.HadContextSensitiveCondition = impl->HadContextSensitiveCondition;
|
||||
for (cmLinkImplItem const& lib : impl->Libraries) {
|
||||
if (lib.Target &&
|
||||
|
@ -157,7 +157,7 @@ cmake_policy(POP)
|
||||
# Test $<COMPILE_ONLY:> genex.
|
||||
cmake_policy(SET CMP0099 NEW)
|
||||
add_library(dont_link_too SHARED compile_only.cpp)
|
||||
target_compile_definitions(dont_link_too PUBLIC USE_EXAMPLE)
|
||||
target_compile_definitions(dont_link_too PUBLIC USE_EXAMPLE PRIVATE HAVE_FUNCTION)
|
||||
target_link_options(dont_link_too INTERFACE invalid_link_option)
|
||||
target_link_libraries(dont_link_too INTERFACE invalid_link_library)
|
||||
|
||||
@ -168,3 +168,15 @@ add_library(uses_compile_only_genex_static STATIC compile_only.cpp)
|
||||
target_link_libraries(uses_compile_only_genex_static PRIVATE $<COMPILE_ONLY:dont_link_too>)
|
||||
add_executable(uses_via_static_linking main.cxx)
|
||||
target_link_libraries(uses_via_static_linking PRIVATE uses_compile_only_genex_static)
|
||||
|
||||
add_library(uses_compile_only_genex_obj SHARED compile_only.cpp)
|
||||
target_compile_definitions(uses_compile_only_genex_obj PRIVATE HAVE_FUNCTION)
|
||||
target_link_libraries(uses_compile_only_genex_obj PRIVATE $<COMPILE_ONLY:dont_link_too>)
|
||||
|
||||
cmake_policy(SET CMP0131 NEW)
|
||||
add_library(only_link_too OBJECT link_only.cpp)
|
||||
target_compile_options(only_link_too INTERFACE INVALID_COMPILER_FLAG_ARRRRGH)
|
||||
|
||||
add_executable(uses_link_only_genex_obj compile_only.cpp)
|
||||
target_compile_definitions(uses_link_only_genex_obj PUBLIC USE_EXAMPLE)
|
||||
target_link_libraries(uses_link_only_genex_obj PRIVATE $<LINK_ONLY:only_link_too>)
|
||||
|
@ -3,6 +3,13 @@
|
||||
# error "Missing propagated define"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FUNCTION
|
||||
int non_duplicate_function()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Solaris needs non-empty content so ensure
|
||||
// we have at least one symbol
|
||||
int Solaris_requires_a_symbol_here = 0;
|
||||
|
4
Tests/CMakeCommands/target_link_libraries/link_only.cpp
Normal file
4
Tests/CMakeCommands/target_link_libraries/link_only.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user