Cmake generated Xcode project - working with release-build but archiver crash on linker errors

Using Xcode 6.3.1, CMake 3.2.2

I have a project that links to a library. This library is included in the xcode project as code, compiled and then linked to the main executable.

The project is built using cmake. Some excerpts from CMakeLists.txt:

add_library(mylib ${mylib_HEADERS} pch.cpp source/mylib/xxx.cpp)
...
add_executable(${MAIN_BINARY_NAME} MACOSX_BUNDLE ${MAIN_HEADERS} ${MAIN_CODE_FILES} ${MAIN_ICON_FILES} ${MAIN_DYLIBS} )
target_link_libraries (${MAIN_BINARY_NAME} mylib)

      

After generating my xcodeproj, I create a normal version (cmd + B) that compiles and links (and runs) without issue. When I try to archive but it fails on linker error.

Using the xcodebuild command line I've been comparing both versions, some excerpts:

release build

Libtool /Users/username/dev/MyProject/cmake-master/libs/mylib/RelWithDebInfo/libmylib.a normal x86_64

      

archive-assembly

Libtool /Users/username/Library/Developer/Xcode/DerivedData/MyProject-facomnlcdbuduqeohionewjyectq/ArchiveIntermediates/MyProject/IntermediateBuildFilesPath/UninstalledProducts/libmylib.a normal x86_64
...
Ld /Users/username/Library/Developer/Xcode/DerivedData/MyProject-facomnlcdbuduqeohionewjyectq/ArchiveIntermediates/MyProject/InstallationBuildProductsLocation/Applications/MyProject.app/Contents/MacOS/MyProject normal x86_64
...
clang: error: no such file or directory: '/Users/username/dev/myproject/cmake-master/libs/mylib/RelWithDebInfo/libmylib.a'

      

So, for build releases, it correctly uses the build path given by cmake. For archive builds, it ignores the build path and instead compiles and puts the resulting library in the default staging folder, but then when linking to the exe, it looks again at the cmake-specified build path and then cannot find the library.

Looks like a bug in xcode that comes up because cmake overrides the build path ...?

+3


source to share


1 answer


In the meantime, I found a workaround, so at least it archives without linker errors. Specify the "config build path" in the cmakelists.txt file as follows:

set_target_properties(mylib PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/library)

      



And the archive will compile the library - and find it later when linked

+2


source







All Articles