From 9a7f039ee7d3f40d6d041fd0d1ef43f92faf8996 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Thu, 14 Dec 2017 20:26:51 +0100 Subject: 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 --- Source/cmGeneratorTarget.cxx | 3 --- Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt | 1 - Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt | 9 --------- .../ObjectLibrary/LinkObjRHSObject-build-result.txt | 1 + .../ObjectLibrary/LinkObjRHSObject-build-stdout.txt | 1 + Tests/RunCMake/ObjectLibrary/LinkObjRHSObject.cmake | 12 ++++++++++++ .../ObjectLibrary/LinkObjRHSObject2-build-result.txt | 1 + Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2.cmake | 12 ++++++++++++ Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt | 1 - Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt | 10 ---------- Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake | 13 +++++++++++++ .../add_library/OBJECTwithOnlyObjectSources-result.txt | 1 - .../add_library/OBJECTwithOnlyObjectSources-stderr.txt | 10 ---------- 13 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt delete mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-stdout.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHSObject.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2-build-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2.cmake delete mode 100644 Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt delete mode 100644 Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt delete mode 100644 Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-result.txt delete mode 100644 Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index f6fd6d1..3aa57d2 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -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") { diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt deleted file mode 100644 index b91ffd0..0000000 --- a/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt +++ /dev/null @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-result.txt new file mode 100644 index 0000000..e27f06b --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-result.txt @@ -0,0 +1 @@ +[1-9][0-9]* diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-stdout.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-stdout.txt new file mode 100644 index 0000000..4eeb096 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject-build-stdout.txt @@ -0,0 +1 @@ +REQUIRED needs to be defined diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject.cmake new file mode 100644 index 0000000..db571a3 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject.cmake @@ -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) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2-build-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2-build-result.txt new file mode 100644 index 0000000..e27f06b --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2-build-result.txt @@ -0,0 +1 @@ +[1-9][0-9]* diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2.cmake new file mode 100644 index 0000000..6bb8d5e --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHSObject2.cmake @@ -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) diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt deleted file mode 100644 index aadc5e0..0000000 --- a/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt +++ /dev/null @@ -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\)$ diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake index 6724da1..287331b 100644 --- a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-result.txt b/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt b/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt deleted file mode 100644 index 6183f80..0000000 --- a/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt +++ /dev/null @@ -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\)$ -- cgit v0.12