Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake generated Xcode-project - release-build works but archive fails on linker errors

Using Xcode 6.3.1, CMake 3.2.2

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

The project is generated with cmake. Some extracts of the 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 build a normal version ( cmd + B ) which compiles and links (and runs) without issues. When I try to archive however it fails on a linker-error.

Using commandline xcodebuild I compared both versions, some extracts:

release-build

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

archive-build

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 release-builds, it correctly uses the build path specified by cmake. For archive-builds, it ignores the build-path and instead compiles and puts the resulting library in the default-intermediate-folder - but then when linking with the exe it does again look in the cmake-specified build-path and then fails to find the library.

It looks like a bug in xcode, which turns up because cmake overrides the build-path... ?

like image 368
kalmiya Avatar asked May 19 '15 07:05

kalmiya


1 Answers

In the meanwhile I found a work-around, so at least it Archives without linker errors. Specify a "per configuration build path" in the cmakelists.txt like this:

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

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

like image 82
kalmiya Avatar answered Oct 07 '22 00:10

kalmiya