CMake xib to nib compilation for iOS target - ios

I'm targeting iOS (device and simulator) and setting up CMake to add the different resources needed in the bundle. The "xib" file is giving me some problems. If I take no further action, the iPhone/iPad simulator run fails with the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Could not load NIB in bundle:
'NSBundle </Users/danieldekkers/Library/Application Support/iPhone Simulator/4.3.2/Applications/1C29638B-7593-4311-8F94-C8051AF90AD7/Discs.app>
(loaded)' with name 'MainWindow''
A missing NIB file in the bundle.
An example (http://www.vtk.org/Wiki/CMake:OSX_InterfaceBuilderFiles) shows that for OSX, you have to compile the xib files into nib files and add these to the bundle as a post-build step.
So my guess would be that something similar holds for iOS as well.
But my question is,... where do i add the compiled nib files?
I now do this in the CMakeLists.txt:
# We need to compile the interface builder *.xib files to *.nib files to add to the bundle
# Make sure we can find the 'ibtool' program. If we can NOT find it we skip generation of this project
FIND_PROGRAM( IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" )
if ( ${IBTOOL} STREQUAL "IBTOOL-NOTFOUND" )
MESSAGE( SEND_ERROR "ibtool can not be found" )
ENDIF()
# Compile the .xib files using the 'ibtool' program with the destination being the app package
FOREACH( xib ${RSRC_IOS_XIB_FILES} )
ADD_CUSTOM_COMMAND( TARGET ${RT_APP_NAME} POST_BUILD
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text
--compile
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RT_APP_NAME}.app/Contents/Resources/${xib}.nib
${RT_APP_ROOT}/rsrc/apple/ios/${xib}.xib
COMMENT "Compiling ${RT_APP_ROOT}/rsrc/apple/ios/${xib}.xib")
ENDFOREACH()
But iI don't really trust the "destination" of the compilation step, especially for the simulator.
Has anyone got this working or see what it is that I'm doing wrong?

It should "just work" with the CMake Xcode generator to add the *.xib files as sources to add_executable, and then set the RESOURCE target property to the list of *.xib files.
As shown in the CMake/Tests/iOSNavApp/CMakeLists.txt file.
This technique should work with CMake 2.8.5 and up, and Xcode 4 and up.
EDIT
Code from link copied/pasted here in case the link gets broken in the future:
cmake_minimum_required(VERSION 2.8.5)
project(NavApp3)
set(CMAKE_OSX_SYSROOT iphoneos4.3)
set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Classes
)
add_library(Functions STATIC TotalFunction.c TotalFunction.h)
set(M_SRCS main.m Classes/NavApp3AppDelegate.m Classes/RootViewController.m)
set(HEADERS Classes/NavApp3AppDelegate.h Classes/RootViewController.h)
set(RESOURCES MainWindow.xib RootViewController.xib)
add_executable(NavApp3 MACOSX_BUNDLE ${M_SRCS} ${HEADERS} ${RESOURCES})
target_link_libraries(NavApp3
Functions
"-framework CoreGraphics"
"-framework Foundation"
"-framework UIKit"
)
set_target_properties(NavApp3 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "com.yourcompany.NavApp3"
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in
RESOURCE "${RESOURCES}"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym"
XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES
XCODE_ATTRIBUTE_GCC_PREFIX_HEADER ${CMAKE_CURRENT_LIST_DIR}/NavApp3_Prefix.pch
XCODE_ATTRIBUTE_INFOPLIST_PREPROCESS YES
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 3.0
)

Related

CompileXIB com.apple.InterfaceBuilder error 2001 operation couldn’t be completed

Compiled my project code and now I receive the following error on all XIB and Storyboard files. Can someone help me solve? All IB files point to the proper deployment target (9.0).
CompileXIB App/WelcomeScreenViewController.xib
cd /Users/jried31/Downloads/zzz/v6/App
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export XCODE_DEVELOPER_USR_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin/..
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors --warnings --notices --module App --output-partial-info-plist /Users/jried31/Library/Developer/Xcode/DerivedData/App-basveboargfgfwdisbiioebismye/Build/Intermediates/App.build/Debug-iphonesimulator/App.build/WelcomeScreenViewController-PartialInfo.plist --auto-activate-custom-fonts --target-device iphone --minimum-deployment-target 9.0 --output-format human-readable-text --compile /Users/jried31/Library/Developer/Xcode/DerivedData/App-basveboargfgfwdisbiioebismye/Build/Products/Debug-iphonesimulator/Alure.Me.app/WelcomeScreenViewController.nib /Users/jried31/Downloads/zzz/v6/App/App/WelcomeScreenViewController.xib
/* com.apple.ibtool.errors */
/Users/jried31/Downloads/zzz/v6/App/App/WelcomeScreenViewController.xib: error: The operation couldn’t be completed. (com.apple.InterfaceBuilder error 2001.)
In my case, a merge conflict caused the files to fail to compile, so I just had to open them up in a text editor and resolve the merge.
All the other solution did not work for me. I did not have a merge issue as I got the issue no matter which branch I was using.
In the end I redownloaded Xcode (7.3.1) and now it is working again.
Solved my own problem:
More Clarification of the issue was that all of the XIB's and Storyboard files would not compile, resulting in the 2001 error.
SOLUTION:
The problem was because the Simulator was based on iOS 9.1 and the build target for both the Podfile and iOS project was 9.0...That inconsistency caused issues. I resolved it by the following:
Product -> Clean
Product -> (hold down option) Clean build folders
Delete Derived Data (~/Library/Developer/Xcode/DerivedData)
Download the 9.0 simulator (if you choose to keep the project at 9.0 settings) resulting in two simulator builds (9.1 and 9.0)
Restart XCODE
--- Just make sure that all of your settings reflect the desired OS version you'd like to go with.

Error when building the project in Xcode

I get following error while building the project.
Clening also didn't help. No idea what went wrong all of a sudden
CompileAssetCatalog /Users/Mayu/Library/Developer/Xcode/DerivedData/Pizza_to_Go-dohdzfdfbyycqrhirbysuinqfuzf/Build/Products/Debug-iphonesimulator/Pizza\ to\ Go.app Pizza\ to\ Go/Images.xcassets Pizza\ to\ Go/Images.xcassets
cd "/Users/Mayu/Documents/development/git/pizzatogo/iPhoneApp/Pizza to Go"
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/actool --output-format human-readable-text --notices --warnings --export-dependency-info /Users/Mayu/Library/Developer/Xcode/DerivedData/Pizza_to_Go-dohdzfdfbyycqrhirbysuinqfuzf/Build/Intermediates/Pizza\ to\ Go.build/Debug-iphonesimulator/Pizza\ to\ Go.build/assetcatalog_dependencies.txt --output-partial-info-plist /Users/Mayu/Library/Developer/Xcode/DerivedData/Pizza_to_Go-dohdzfdfbyycqrhirbysuinqfuzf/Build/Intermediates/Pizza\ to\ Go.build/Debug-iphonesimulator/Pizza\ to\ Go.build/assetcatalog_generated_info.plist --app-icon AppIcon --launch-image LaunchImage --platform iphonesimulator --minimum-deployment-target 7.0 --target-device iphone --compress-pngs --compile /Users/Mayu/Library/Developer/Xcode/DerivedData/Pizza_to_Go-dohdzfdfbyycqrhirbysuinqfuzf/Build/Products/Debug-iphonesimulator/Pizza\ to\ Go.app /Users/Mayu/Documents/development/git/pizzatogo/iPhoneApp/Pizza\ to\ Go/Pizza\ to\ Go/Images.xcassets /Users/Mayu/Documents/development/git/pizzatogo/iPhoneApp/Pizza\ to\ Go/Pizza\ to\ Go/Images.xcassets
/* com.apple.actool.errors */
: error: There are multiple app icon set instances named "AppIcon".
: error: There are multiple launch image set instances named "LaunchImage".
/* com.apple.actool.compilation-results */
/Users/Mayu/Library/Developer/Xcode/DerivedData/Pizza_to_Go-dohdzfdfbyycqrhirbysuinqfuzf/Build/Products/Debug-iphonesimulator/Pizza to Go.app/Assets.car
/Users/Mayu/Library/Developer/Xcode/DerivedData/Pizza_to_Go-dohdzfdfbyycqrhirbysuinqfuzf/Build/Intermediates/Pizza to Go.build/Debug-iphonesimulator/Pizza to Go.build/assetcatalog_generated_info.plist
As this error says you have duplicated images AppIcon and LaunchImage. To sort it just make copy of it and remove it from your project (have a look in Images.xcassets and remove it as well). After that import it again to Images.xcassets.
For me, the problem was that I had my assets folder with multiple targets with while extensions already had those target assigned. Fix was to make sure each asset folder was only assigned to its specific target, or delete folders that are not needed.
Error: multiple instances of AppIcon (when working with Storyboard).
This solution worked for me:
Look in the Storyboard window's Navigation panel for a duplicate listing of Images.xcassets. If there, highlight it and press delete key. When asked, select “remove reference” - not send to trash (which might delete the actual Images.xcassets folder). Apparently this duplicate listing in the project can occur if an attempt is aborted to import something into Images.xcassetes.

Xcode 5 storyboard compile failure

I'm running Xcode 5 and building for iOS 7. When I try to build this project for archiving I get this error. I get it on my local machine and on my jenkins build server. I have gone through the storyboard and I am not finding any reason for this error. It builds just fine on simulator and device. I am not even sure what runtime.nib is though addEditHCPViewController.nib is reference to one of the View Controllers inside of the storyboard. Any ideas?
CompileStoryboard myApp/Profiles.storyboard
cd "/builds/Company/workspace/myApp"
setenv IBSC_MINIMUM_COMPATIBILITY_VERSION 6.1
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
setenv XCODE_DEVELOPER_USR_PATH /Applications/Xcode.app/Contents/Developer/usr/bin/..
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors --warnings --notices --minimum-deployment-target 6.1 --output-format human-readable-text --compile /builds/Company/workspace/myApp/build/Distribution-iphoneos/myApp.app/Profiles.storyboardc /builds/Company/workspace/myApp/myApp/Profiles.storyboard
/* com.apple.ibtool.document.warnings */
/builds/Company/workspace/myApp/myApp/Profiles.storyboard:jlW-RT-oUY: warning: 2 views are vertically ambiguous.
/builds/Company/workspace/myApp/myApp/Profiles.storyboard:1Qm-h4-IZr: warning: Position is ambiguous for "Picker".
/builds/Company/workspace/myApp/myApp/Profiles.storyboard:d8p-iA-2QW: warning: Frame for "Button" will be different at run time.
/* com.apple.ibtool.errors */
/builds/Company/workspace/myApp/myApp/Profiles.storyboard: error: Compilation failed. Unable to write to path: /builds/Company/workspace/myApp/build/Distribution-iphoneos/myApp.app/Profiles.storyboardc
Underlying Errors:
Description: The file “runtime.nib” doesn’t exist.
Failure Reason: The file doesn’t exist.
Underlying Errors:
Description: The operation couldn’t be completed. No such file or directory
Failure Reason: No such file or directory
Description: “Profiles.storyboardc” couldn’t be removed.
Failure Reason: The file doesn’t exist.
Underlying Errors:
Description: The operation couldn’t be completed. No such file or directory
Failure Reason: No such file or directory
CompileStoryboard myApp/Profiles.storyboard
cd "/builds/Company/workspace/myApp"
setenv IBSC_MINIMUM_COMPATIBILITY_VERSION 6.1
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
setenv XCODE_DEVELOPER_USR_PATH /Applications/Xcode.app/Contents/Developer/usr/bin/..
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors --warnings --notices --minimum-deployment-target 6.1 --output-format human-readable-text --compile /builds/Company/workspace/myApp/build/Distribution-iphoneos/myApp.app/Profiles.storyboardc /builds/Company/workspace/myApp/myApp/Profiles.storyboard
/* com.apple.ibtool.document.warnings */
/builds/Company/workspace/myApp/myApp/Profiles.storyboard:d8p-iA-2QW: warning: Frame for "Button" will be different at run time.
/builds/Company/workspace/myApp/myApp/Profiles.storyboard:jlW-RT-oUY: warning: 2 views are vertically ambiguous.
/builds/Company/workspace/myApp/myApp/Profiles.storyboard:1Qm-h4-IZr: warning: Position is ambiguous for "Picker".
/* com.apple.ibtool.errors */
/builds/Company/workspace/myApp/myApp/Profiles.storyboard: error: Compilation failed. Unable to write to path: /builds/Company/workspace/myApp/build/Distribution-iphoneos/myApp.app/Profiles.storyboardc
Underlying Errors:
Description: The file “addEditHCPViewController.nib” doesn’t exist.
Failure Reason: The file doesn’t exist.
Underlying Errors:
Description: The operation couldn’t be completed. No such file or directory
Failure Reason: No such file or directory
I found the answer to this. During a merge in git, the project file had not been merged properly and Profiles.storyboard was being included as a resource twice. When it tried to compile the same resource the second time, it would fail.
I just Cleaned the project, then built it again, afterwards the error disappeared.
Just feel I should add that I had this problem for a while and had no clue how to solve it.
Turns out one of my Storyboard IDs had a slash in (/) which was causing the error. Removing this slash resolved the error!
Hope this helps some people!
Removing "/" in the storyboard Id is fixed my problem.
#imran-ahmed solved the problem. I worked on this problem for a couple hours and finally found the comment about the '/' in a StoryBoard ID. A year later and the '/' in the StoryBoard ID still kills Xcode compile. That was my problem and simply deleting the '/' solved the problem.
I faced a similar issue, in my case I had not checked the Target Membership option. Make sure it is checked otherwise Xcode won't be able to find it.

Can't link MacOS frameworks with CMake

I'm trying to build a subproject with cmake (it's not an xcode project or even an app for iphone, the result is cross-platform console executable, which #includes some inherited from C++ abstract classes, written in objective-c++)
I'm using this guide to link mac os frameworks: http://www.vtk.org/Wiki/CMake:HowToUseExistingOSXFrameworks
and this macro:
macro(ADD_FRAMEWORK fwname appname)
find_library(FRAMEWORK_${fwname}
NAMES ${fwname}
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
NO_DEFAULT_PATH)
if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
MESSAGE(ERROR ": Framework ${fwname} not found")
else()
TARGET_LINK_LIBRARIES(${appname} ${FRAMEWORK_${fwname}})
MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
endif()
endmacro(ADD_FRAMEWORK)
This is the important part in CMakeLists.txt
project(myprojectname)
........
add_executable(mytarget src/mytarget.cpp)
add_framework(CoreMedia mytarget)
add_framework(CoreVideo mytarget)
add_framework(AVFoundation mytarget)
add_framework(Foundation mytarget)
........
And that's what i have when trying to build:
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CoreMedia.framework". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CoreVideo.framework". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/AVFoundation.framework". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "mytarget" requests linking to directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/Foundation.framework". Targets may link only to libraries. CMake is dropping the item.
It actually finds all these frameworks, but can't link, which produces a lot of linker errors. I'm pretty sure that that's the reason because i made a testproj using XCode and it has the same errors till i linked all the needed frameworks.
When i just use
FIND_LIBRARY(COREMEDIA_LIB CoreMedia)
...
then COREMEDIA_LIB is set to NOTFOUND - what's going on? :/
I googled a lot but nothing :( Feeling pretty much lost there.
Got the thing: you have to link NOT the frameworkname.framework folder in the TARGET_LINK_LIBRARIES, but the fwname.framework/fwname file! Now it works that way.
The changed macro is this:
macro(ADD_FRAMEWORK fwname appname)
find_library(FRAMEWORK_${fwname}
NAMES ${fwname}
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
NO_DEFAULT_PATH)
if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
MESSAGE(ERROR ": Framework ${fwname} not found")
else()
TARGET_LINK_LIBRARIES(${appname} "${FRAMEWORK_${fwname}}/${fwname}")
MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
endif()
endmacro(ADD_FRAMEWORK)
Hope it will be useful for someone...

How to generate the xcode project of static libs for IOS using Cmake?

I'm trying generate the Xcode project of ASSIMP using Cmake. I know there is already one in it's workspace folder. And I just trying to generate myself. I tried to write the cmakelist.txt:
cmake_minimum_required(VERSION 2.8)
project(assimp)
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
set(CMAKE_OSX_SYSROOT iphoneos5.1)
set(CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
add_subdirectory(assimp)
then i ran this command:
#!/bin/bash
cd "$(dirname "$0")"/assimp
if [ ! -d xcode ]
then
mkdir xcode
fi
cd xcode
cmake -G Xcode ../.. -DINSTALL_LIBS=ON -DCMAKE_INSTALL_PREFIX=../.. -DBUILD_SHARED_LIBS=OFF -DBUILD_ASSIMP_TOOLS:BOOL=OFF -DENABLE_BOOST_WORKAROUND=ON
# Device or simulator
xcodebuild -target install -configuration Release
it generates the Xcode project but in products is libassimp.dylib and got the "target specifies product type 'com.apple.product-type.library.dynamic', but there's no such product type for the 'iphoneos' platform" error.
How to change the 'com.apple.product-type.library.dynamic' to static? I had set -DBUILD_SHARED_LIBS=OFF but it didn't work.
I searched the web and can't find what is causing the problem.
Thank you very much for any help!
in cmakelist.txt at /code/ directory there is a line: ADD_LIBRARY( assimp SHARED just change the SHARED to STATIC
the cmakelist i'm using:
cmake_minimum_required(VERSION 2.8.6)
project(assimp)
# Set the Base SDK (only change the SDKVER value, if for instance, you are building for iOS 5.0):
set(SDKVER "5.1")
set(DEVROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer")
set(SDKROOT "${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk")
if(EXISTS ${SDKROOT})
set(CMAKE_OSX_SYSROOT "${SDKROOT}")
else()
message("Warning, iOS Base SDK path not found: " ${SDKROOT})
endif()
# Will resolve to "Standard (armv6 armv7)" on Xcode 4.0.2 and to "Standard (armv7)" on Xcode 4.2:
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)")
# seamless toggle between device and simulator
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(assimp)

Resources