[CMake] cmake 3.5.2 Xcode generator bug

Paul Smith paul at mad-scientist.net
Fri May 20 14:34:14 EDT 2016


Just discovered a bug in the Xcode generator; this works fine with
Makefile generator (on OSX or Linux) and Visual Studio, but fails on
Xcode:

  $ cat CMakeLists.txt
  cmake_minimum_required(VERSION 3.5)
  project(BadXcode)
  add_library(obj OBJECT foo.cpp)
  add_library(shared SHARED $<TARGET_OBJECTS:libobj>)

  $ touch foo.cpp

  $ mkdir obj

  $ cd obj

  $ cmake -G Xcode ..

  $ cmake --build .

The build succeeds, but it never creates the libshared.dylib file:

  $ find . -name lib\*
  ./BadXcode.build/Debug/obj.build/Objects-normal/libobj.a

I'm not sure why we're creating a .a here, when we're making an OBJECT
library, but whatever... the main thing is there's no libshared.dylib:

  $ find . -name \*.dylib

  $ find . -name \*shared\*
  ./BadXcode.build/Debug/shared.build
  ./CMakeScripts/shared_postBuildPhase.makeDebug
  ./CMakeScripts/shared_postBuildPhase.makeMinSizeRel
  ./CMakeScripts/shared_postBuildPhase.makeRelease
  ./CMakeScripts/shared_postBuildPhase.makeRelWithDebInfo

If I use the Makefile generator instead, it works as expected:

  $ rm -rf *

  $ cmake ..

  $ cmake --build .
  Scanning dependencies of target obj
  [ 50%] Building CXX object CMakeFiles/obj.dir/foo.cpp.o
  [ 50%] Built target obj
  Scanning dependencies of target shared
  [100%] Linking CXX shared library libshared.dylib
  [100%] Built target shared

  $ find . -name lib\*
  ./libshared.dylib


More information about the CMake mailing list