mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-03 20:29:56 -06:00
Since commitb6a5382217(Ninja: depend on language module information files directly, 2023-02-10, v3.27.0-rc1~502^2), the return value of `cmCommonTargetGenerator::GetLinkedTargetDirectories` must account for linked object libraries because they may provide modules (#25112). These were added by commitb665966933(cmComputeLinkInformation: track OBJECT library dependencies, 2023-07-22, v3.27.1~5^2). However, targets named by `$<TARGET_OBJECTS:...>` sources are also needed (#25365). The latter were added by commit22da18b995(Fortran: Restore support for TARGET_OBJECTS providing modules, 2023-10-27, v3.28.0-rc4~9^2) and commit035302b7e3(cmComputeLinkDepends: also copy the target from object link items, 2023-10-27, v3.28.0-rc4~9^2~2). However, their approach added link entries not actually specified by projects. It also incorrectly re-used `cmComputeLinkDepends::AddLinkObject` for object library targets when it is meant for their individual object files. These problems caused additional regressions (#25417). Revert the implementation parts of those commits and leave behind an assertion and comment to help avoid the mistake in the future. Instead, track targets named by `$<TARGET_OBJECTS:...>` sources with a dedicated member. Issue: #25112 Issue: #25365 Fixes: #25417 Co-authored-by: Ben Boeckel <ben.boeckel@kitware.com>
82 lines
3.3 KiB
CMake
82 lines
3.3 KiB
CMake
cmake_minimum_required(VERSION 3.5)
|
|
project(ObjectLibrary C)
|
|
|
|
add_subdirectory(A)
|
|
add_subdirectory(B)
|
|
|
|
add_library(Cstatic STATIC c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
|
|
add_executable(UseCstatic main.c)
|
|
target_link_libraries(UseCstatic Cstatic)
|
|
|
|
add_library(Cshared SHARED c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
|
|
add_executable(UseCshared main.c)
|
|
set_property(TARGET UseCshared PROPERTY COMPILE_DEFINITIONS SHARED_C)
|
|
target_link_libraries(UseCshared Cshared)
|
|
add_custom_command(TARGET UseCshared POST_BUILD COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/A/a.cmake)
|
|
|
|
add_executable(UseCinternal main.c c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
|
|
|
|
if("${CMAKE_GENERATOR}" MATCHES "Xcode")
|
|
# Xcode does not seem to support targets without sources.
|
|
set(dummy dummy.c)
|
|
endif()
|
|
|
|
# Test static library without its own sources.
|
|
add_library(ABstatic STATIC ${dummy} $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
|
|
target_include_directories(ABstatic PUBLIC $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
target_compile_definitions(ABstatic PUBLIC $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
|
|
|
|
add_executable(UseABstatic mainAB.c)
|
|
target_link_libraries(UseABstatic ABstatic)
|
|
|
|
# Test module definition file to export object library symbols in the test
|
|
# below if the platform needs and supports it.
|
|
set(ABshared_SRCS $<TARGET_OBJECTS:A>)
|
|
if(CMAKE_LINK_DEF_FILE_FLAG OR NOT WIN32)
|
|
list(APPEND ABshared_SRCS $<TARGET_OBJECTS:B> AB.def)
|
|
else()
|
|
set(NO_A NO_A)
|
|
list(APPEND ABshared_SRCS $<TARGET_OBJECTS:Bexport>)
|
|
endif()
|
|
|
|
# Test shared library without its own sources.
|
|
add_library(ABshared SHARED ${dummy} ${ABshared_SRCS})
|
|
target_include_directories(ABshared PUBLIC $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
target_compile_definitions(ABshared PUBLIC $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
|
|
|
|
add_executable(UseABshared mainAB.c)
|
|
set_property(TARGET UseABshared PROPERTY COMPILE_DEFINITIONS SHARED_B ${NO_A})
|
|
target_link_libraries(UseABshared ABshared)
|
|
|
|
# Test executable without its own sources.
|
|
add_library(ABmain OBJECT mainAB.c)
|
|
target_include_directories(ABmain PUBLIC $<TARGET_PROPERTY:B,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
target_compile_definitions(ABmain PUBLIC $<TARGET_PROPERTY:B,INTERFACE_COMPILE_DEFINITIONS>)
|
|
add_executable(UseABinternal ${dummy}
|
|
$<TARGET_OBJECTS:ABmain> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>
|
|
)
|
|
|
|
# Test target-level dependencies of executable without sources.
|
|
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/UseABinternalDep.cmake)
|
|
add_custom_target(UseABinternalDep COMMAND ${CMAKE_COMMAND} -E touch UseABinternalDep.cmake)
|
|
add_custom_command(TARGET UseABinternal POST_BUILD COMMAND ${CMAKE_COMMAND} -P UseABinternalDep.cmake)
|
|
add_dependencies(UseABinternal UseABinternalDep)
|
|
|
|
# Test a static library with sources from a different static library
|
|
add_library(UseCstaticObjs STATIC $<TARGET_OBJECTS:Cstatic> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
|
|
|
|
# Test a shared library with sources from a different shared library
|
|
add_library(UseCsharedObjs SHARED $<TARGET_OBJECTS:Cshared> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
|
|
|
|
# Test a shared executable with sources from a different executable
|
|
add_executable(UseABstaticObjs $<TARGET_OBJECTS:UseABstatic>)
|
|
target_link_libraries(UseABstaticObjs ABstatic)
|
|
|
|
add_subdirectory(ExportLanguages)
|
|
|
|
add_subdirectory(LinkObjects)
|
|
|
|
add_subdirectory(Transitive)
|
|
|
|
add_subdirectory(TransitiveLinkDeps)
|