问题
We ported our codebase to use CMake for build management some weeks ago. We realize now that there is a major problem when we are trying to Archive an application that depends on one (or several) library built in the same Xcode solution.
The linker fails because it cannot find the depended upon library (and the library is indeed not present where it is looking for it).
minimal example
Here is a minimal example producing the issue:
In CMakeLists.txt
##
## The library
##
project(library)
add_library(${PROJECT_NAME}
utils.h
utils.cpp
)
##
## The application
##
project(CocoaApp)
set(${PROJECT_NAME}_XIB
MainMenu.xib
)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
AppDelegate.h
AppDelegate.mm
${${PROJECT_NAME}_XIB}
main.mm
)
target_link_libraries(${PROJECT_NAME} library "-framework Cocoa")
set_target_properties(${PROJECT_NAME} PROPERTIES
RESOURCE "${${PROJECT_NAME}_XIB}")
When generating an Xcode project from this simple CMake scripts, if trying to call Archive command, the compilation phase itself goes fine, but the linker phase fails with this error:
clang: error: no such file or directory: '<path_to_build_tree>/Release/libLibrary.a'
And there is indeed no libLibrary.a to be found in ${build_tree}/Release/. (If the library target was first compiled in Release, the file would already be there, but it is not viable as Archive should be self contained.)
Is this a bug ? Is there a workaround ?
Edit: setting ARCHIVE_OUTPUT_DIRECTORY on the lib
If ARCHIVE_OUTPUT_DIRECTORY
is set for the Library target, then a file is indeed created in CMake's build_tree. Actually setting its value to "./" even places it where a 'normal' Release build would place the library.
The problem here is that the file that is placed in the build_tree is merely a soft link to the actual library (in ~/Library/Developer/Xcode/DerivedData/.../.../libLibrary.a). Instead, we would need that the "Archive" action builds the actual file here, exactly like a Release build would (or at least move it there when its done).
来源:https://stackoverflow.com/questions/33020245/cmakexcode-archive-fails-for-an-app-depending-on-a-library-in-the-same-solutio