cmake-cookbook icon indicating copy to clipboard operation
cmake-cookbook copied to clipboard

chapter-01/recipe-03/cxx-example doesn't work with Xcode generator

Open ragfield opened this issue 5 years ago • 3 comments

I can build chapter-01/recipe-03/cxx-example fine with Unix Makefiles or Ninja generator on macOS Catalina with Xcode 11.6. When I use the Xcode generator the hello-world target fails to build properly. Is this a bug in CMake's Xcode generator or can something be done differently in the CMakeLists.txt file to work around the problem?

Your Environment

  • macOS Catalina
  • Xcode 11.6

ragfield avatar Aug 25 '20 18:08 ragfield

Hi, This is difficult to say without knowing how hello-world target fails to build properly? Could explain that part or show some logs? Which version of CMake do you use?

In any case the https://github.com/dev-cafe/cmake-cookbook/blob/master/chapter-01/recipe-03/cxx-example/CMakeLists.txt is really basic and simple so I would bet for a Xcode generator bug

TheErk avatar Aug 26 '20 08:08 TheErk

Here's the output from the Unix Makefiles build:

➜ build git:(master) ✗ cmake -G Unix\ Makefiles .. -- The CXX compiler identification is AppleClang 11.0.3.11030032 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build ➜ build git:(master) ✗ make Scanning dependencies of target message-objs [ 20%] Building CXX object CMakeFiles/message-objs.dir/Message.cpp.o [ 20%] Built target message-objs Scanning dependencies of target message-static [ 40%] Linking CXX static library libmessage-static.a [ 40%] Built target message-static Scanning dependencies of target hello-world [ 60%] Building CXX object CMakeFiles/hello-world.dir/hello-world.cpp.o [ 80%] Linking CXX executable hello-world [ 80%] Built target hello-world Scanning dependencies of target message-shared [100%] Linking CXX shared library libmessage-shared.dylib [100%] Built target message-shared


Here's the output from the Ninja build:

➜ build git:(master) ✗ cmake -G Ninja .. -- The CXX compiler identification is AppleClang 11.0.3.11030032 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build ➜ build git:(master) ✗ ninja [5/5] Linking CXX executable hello-world


Here's the output from the Xcode build:

➜ build git:(master) ✗ cmake -G Xcode .. -- The CXX compiler identification is AppleClang 11.0.3.11030032 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build ➜ build git:(master) ✗ xcodebuild Command line invocation: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild

Prepare build note: Using legacy build system === BUILD AGGREGATE TARGET ZERO_CHECK OF PROJECT recipe-03 WITH THE DEFAULT CONFIGURATION (Debug) ===

Check dependencies

Write auxiliary files write-file /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/ZERO_CHECK.build/Script-406544BC807847CAA30B7235.sh chmod 0755 /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/ZERO_CHECK.build/Script-406544BC807847CAA30B7235.sh

PhaseScriptExecution CMake\ Rules build/recipe-03.build/Debug/ZERO_CHECK.build/Script-406544BC807847CAA30B7235.sh cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example /bin/sh -c /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/ZERO_CHECK.build/Script-406544BC807847CAA30B7235.sh echo ""

make -f /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/CMakeScripts/ReRunCMake.make make[1]: `/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/CMakeFiles/cmake.check_cache' is up to date.

=== BUILD TARGET message-objs OF PROJECT recipe-03 WITH THE DEFAULT CONFIGURATION (Debug) ===

Check dependencies

Write auxiliary files /bin/mkdir -p /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64 write-file /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64/message-objs.LinkFileList write-file /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Script-657800514D4B4277B20A6F97.sh chmod 0755 /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Script-657800514D4B4277B20A6F97.sh

CompileC build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64/Message.o Message.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example export LANG=en_US.US-ASCII /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target x86_64-apple-macos10.15 -fmessage-length=167 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR="Debug" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/include -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/DerivedSources-normal/x86_64 -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/DerivedSources/x86_64 -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/DerivedSources -F/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build -fPIC -MMD -MT dependencies -MF /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64/Message.d --serialize-diagnostics /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64/Message.dia -c /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/Message.cpp -o /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64/Message.o

Libtool build/recipe-03.build/Debug/message-objs.build/libmessage-objs.a normal x86_64 cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example export MACOSX_DEPLOYMENT_TARGET=10.15 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -D -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build -filelist /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Objects-normal/x86_64/message-objs.LinkFileList -o /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/libmessage-objs.a

PhaseScriptExecution CMake\ PostBuild\ Rules build/recipe-03.build/Debug/message-objs.build/Script-657800514D4B4277B20A6F97.sh cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example /bin/sh -c /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/message-objs.build/Script-657800514D4B4277B20A6F97.sh echo "Depend check for xcode" Depend check for xcode cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build && make -C /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build -f /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/CMakeScripts/XCODE_DEPEND_HELPER.make OBJDIR=Objects-normal PostBuild.message-objs.Debug /bin/rm -f /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/libmessage-shared.dylib /bin/rm -f /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/libmessage-static.a

=== BUILD TARGET message-static OF PROJECT recipe-03 WITH THE DEFAULT CONFIGURATION (Debug) ===

Check dependencies

=== BUILD TARGET hello-world OF PROJECT recipe-03 WITH THE DEFAULT CONFIGURATION (Debug) ===

Check dependencies

Write auxiliary files /bin/mkdir -p /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64 write-file /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world.LinkFileList

CompileC build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world.o hello-world.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example export LANG=en_US.US-ASCII /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target x86_64-apple-macos10.15 -fmessage-length=167 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR="Debug" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/include -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/DerivedSources-normal/x86_64 -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/DerivedSources/x86_64 -I/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/DerivedSources -F/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug -MMD -MT dependencies -MF /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world.d --serialize-diagnostics /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world.dia -c /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/hello-world.cpp -o /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world.o

Ld build/Debug/hello-world normal x86_64 cd /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug -F/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug -filelist /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world_lto.o -Xlinker -no_deduplicate -Wl,-search_paths_first -Wl,-headerpad_max_install_names /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/libmessage-static.a -Xlinker -dependency_info -Xlinker /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/recipe-03.build/Debug/hello-world.build/Objects-normal/x86_64/hello-world_dependency_info.dat -o /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/hello-world clang: error: no such file or directory: '/Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/libmessage-static.a'

** BUILD FAILED **

The following build commands failed: Ld build/Debug/hello-world normal x86_64 (1 failure)


It appears as if the 'message-static' target doesn't actually do anything.

ragfield avatar Aug 26 '20 14:08 ragfield

Looks like a bug in Xcode generator. What happen if you suppress "STATIC" in CMakeLists.txt ?

Note that the final message from the build of the library is suspicious:

/bin/rm -f /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/libmessage-shared.dylib
/bin/rm -f /Users/schofield/Files/projects/cmake-cookbook/chapter-01/recipe-03/cxx-example/build/Debug/libmessage-static.a

You should report this to CMake project, really looks like a bug of the generator to me.

TheErk avatar Aug 28 '20 10:08 TheErk