objlib: Allow OBJECT libraries to link to OBJECT libraries.

Note: This still does not link the object-files of the `OBJECT` library
from the right-hand side of `target_link_libraries` to the target on the
left-hand side. (In this particular case of another `OBJECT` library on
the left-hand side this would not make any sense anyway. The target on
the left-hand side has no link-step.)

Issue: #14778
This commit is contained in:
Deniz Bahadir authored and Brad King committed 2018-03-01 09:24:25 -05:00
1 parent dfb6e84082
commit 9a7f039ee7
13 files changed
+40 -35

No files matched your search

-3
View File
@@ -1054,9 +1054,6 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
kind = SourceKindHeader;
} else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
kind = SourceKindExternalObject;
if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
badObjLib.push_back(sf);
}
} else if (!sf->GetLanguage().empty()) {
kind = SourceKindObjectSource;
} else if (ext == "def") {
@@ -1 +0,0 @@
1
@@ -1,9 +0,0 @@
CMake Error at BadObjSource2.cmake:1 \(add_library\):
OBJECT library "A" contains:
bad.obj
but may contain only sources that compile, header files, and other files
that would not affect linking of a normal library.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
@@ -0,0 +1 @@
[1-9][0-9]*
@@ -0,0 +1 @@
REQUIRED needs to be defined
@@ -0,0 +1,12 @@
cmake_policy(SET CMP0022 NEW)
enable_language(C)
add_library(AnObjLib OBJECT a.c)
target_compile_definitions(AnObjLib INTERFACE REQUIRED)
add_library(AnotherObjLib OBJECT b.c)
target_link_libraries(AnotherObjLib PRIVATE AnObjLib)
add_executable(exe exe.c)
target_link_libraries(exe AnotherObjLib)
@@ -0,0 +1 @@
[1-9][0-9]*
@@ -0,0 +1,12 @@
cmake_policy(SET CMP0022 NEW)
enable_language(C)
add_library(AnObjLib OBJECT a.c)
target_compile_definitions(AnObjLib INTERFACE REQUIRED)
add_library(AnotherObjLib OBJECT b.c)
target_link_libraries(AnotherObjLib PUBLIC AnObjLib)
add_executable(exe exe.c)
target_link_libraries(exe AnotherObjLib)
@@ -1 +0,0 @@
1
@@ -1,10 +0,0 @@
^CMake Error at ObjWithObj.cmake:[0-9]+ \(add_library\):
OBJECT library \"B\" contains:
[^
]*a(\.c)?\.o(bj)?
but may contain only sources that compile, header files, and other files
that would not affect linking of a normal library.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$
@@ -24,10 +24,23 @@ function (run_object_lib_build name)
run_cmake_command(${name}-build ${CMAKE_COMMAND} --build .)
endfunction ()
function (run_object_lib_build2 name)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(${name})
set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_command(${name}-build ${CMAKE_COMMAND} --build .)
endfunction ()
run_object_lib_build(LinkObjLHSShared)
run_object_lib_build(LinkObjLHSStatic)
run_object_lib_build(LinkObjRHSShared)
run_object_lib_build(LinkObjRHSStatic)
run_object_lib_build2(LinkObjRHSObject)
run_object_lib_build2(LinkObjRHSObject2)
run_cmake(MissingSource)
run_cmake(ObjWithObj)
@@ -1,10 +0,0 @@
^CMake Error at OBJECTwithOnlyObjectSources.cmake:[0-9]+ \(add_library\):
OBJECT library \"TestObjectLibWithoutSources\" contains:
[^
]*test(\.cpp)?\.o(bj)?
but may contain only sources that compile, header files, and other files
that would not affect linking of a normal library.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$