[CMake] Critical Xcode problem with OBJECT libraries
Paul Smith
paul at mad-scientist.net
Wed Feb 19 15:17:57 EST 2014
Hi all. I'm using CMake 2.8.12.1 on Linux, MacOSX, and Windows.
On my system I need to build libraries in a large number of
subdirectories and link them (statically) with various executables
(different executables use different libraries). Then I also need to
take the content of all those libraries and include them into a single
shared library / DLL. I understand this is tricky for CMake and so the
special "OBJECT" library type was introduced to help with that.
Here's a repro case for the problem I see:
cmake_minimum_required(VERSION 2.8.12)
project(CMTEST CXX)
add_library(foo_OBJECTS OBJECT foo.cpp foo.h)
add_library(foo STATIC dummy.cpp $<TARGET_OBJECTS:foo_OBJECTS>)
add_dependencies(foo foo_OBJECTS)
add_executable(hello hello.cpp)
target_link_libraries(hello foo)
I needed to add the "dummy.cpp" because I previously learned that Xcode
can't handle creating a library only from OBJECTS like this. It
contains nothing but a comment.
* I run cmake -G Xcode
* I run xcodebuild build -config RelWithDebInfo
* Everything is built correctly
* Now I modify "foo.cpp"
* I run xcodebuild build -config RelWithDebInfo
For the last step I expect that:
1. foo.cpp will be recompiled
2. libfoo.a library will be updated
3. the "hello" program will be rebuilt.
As a side-effect I guess a hidden "libfoo_OBJECTS.a" will be created,
but I don't actually care about that.
This is how it works with Makefile and MSVC. With Xcode, though, what
actually happens is that the "libfoo_OBJECTS.a" is rebuild, BUT it does
NOT rebuild libfoo.a and it does NOT relink the "hello" executable!!
I've explicitly stated a dependency between the foo library target and
the foo_OBJECTS target, and it still does not rebuild on changes!
As you can imagine this is causing my Xcode-based builds to be
completely unreliable: they fail with weird link errors, or else at
runtime with strange vtable issues.
Anyone else able to reproduce this? Is it a known limitation of Xcode?
Any ideas for workarounds?
More information about the CMake
mailing list