iOS CMake install(targets ...) function uses wrong folders - ios

When using the iOS.cmake toolchain (located here https://code.google.com/p/ios-cmake/) my build folders are changed from Debug and Release to Debug-iphoneos and Release-iphoneos.
This isn't an issue except when I try running the code below:
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin COMPONENT development
ARCHIVE DESTINATION lib COMPONENT development
LIBRARY DESTINATION ${MYPROJECT_LIB_SUBDIR} COMPONENT development NAMELINK_SKIP)
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin COMPONENT runtime
ARCHIVE DESTINATION lib COMPONENT source
LIBRARY DESTINATION ${MYPROJECT_LIB_SUBDIR} COMPONENT source NAMELINK_SKIP)
This code gives me the following errors:
-- Install configuration: "Release"
-- Install component: "development"
CMake Error at cmake_install.cmake:54 (FILE):
file INSTALL cannot find
"/Users/username/Documents/Projects/MyFramework/src/ios-build/MyProject/Release/libMyProject.a".
-- Install configuration: "Debug"
-- Install component: "development"
CMake Error at cmake_install.cmake:48 (FILE):
file INSTALL cannot find
"/Users/username/Documents/Projects/MyFramework/src/ios-build/MyProject/Debug/libMyProjectd.a".
For some reason the install(targets ...) function is looking for folders named Debug and Release instead of Debug-iphoneos and Release-iphoneos.
So I either need to make sure that install(targets ...) is looking in the correct folders for the archive or I need to prevent iOS.cmake from renaming the Debug and Release folders. Can anyone suggest anything for this?
Edit
Looks like this is an issue with CMake as identified here: http://public.kitware.com/Bug/view.php?id=9117
I tried updating to the latest version of CMake to see if this had been fixed and I'm still getting the same error. I see a patch attached to the bug report but I'm not sure how to apply it or what I can do to fix this issue.

Found a more specific report of this issue here: http://public.kitware.com/Bug/view.php?id=12506
There are a couple of workarounds on that site. However I used the code snippet below instead to create the Release and Debug folders in the same directory without appending the EFFECTIVE_PLATFORM_NAME to them.
if(${IOS})
set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
endif(${IOS})

Related

Trying to install program, but can't find LTDL_LIBRARY on Mac

I'm trying to install a program on Mac terminal, but I've been stuck on this step: "cmake -DCMAKE_BUILD_TYPE=Release .. && make"
This is the error I initially got:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GMP_LIBRARY
linked by target "ipknot" in directory /Users/samuellee/Downloads/ipknot-master
LTDL_LIBRARY
linked by target "ipknot" in directory /Users/samuellee/Downloads/ipknot-master
MPFR_LIBRARY
linked by target "ipknot" in directory /Users/samuellee/Downloads/ipknot-master
CMake Warning at CMakeLists.txt:77 (target_link_libraries):
Target "ipknot" requests linking to directory "/usr/local/lib". Targets
may link only to libraries. CMake is dropping the item.
CMake Warning at CMakeLists.txt:77 (target_link_libraries):
Target "ipknot" requests linking to directory
"/Library/gurobi1001/macos_universal01/macos_universal2/lib". Targets may link only to
libraries. CMake is dropping the item.
CMake Warning at CMakeLists.txt:77 (target_link_libraries):
Target "ipknot" requests linking to directory
"/Library/gurobi1001/macos_universal2/lib". Targets may link only to
libraries. CMake is dropping the item.
I found GMP_LIBRARY and MPFR_LIBRARY but I can't find LTDL_LIBRARY anywhere on my laptop nor on the internet. Any help?
P.S. I tried finding it in /usr but nothing came up. I also tried installing libtool (even though my friend said that it should already be installed by default). Nothing came up.

Using ZMQ on iOS

I am trying to build an iOS app that is exposed to a fairly extensive Rust project, but I am having issues with one of the dependencies in the project. The Rust project has a ZMQ dependency, and while I am able to build the project on my Mac, when I try to incorporate the Rust project I get the following error:
error: failed to run custom build command for `zmq-sys v0.8.3`
Caused by:
process didn't exit successfully: `/Users/lisa/company/project/project_detail/target/debug/build/zmq-sys-16dfc88dff84d855/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=LIBZMQ_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-apple-ios
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_apple_ios
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-ios
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_ios
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-ios
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_ios
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'Unable to locate libzmq:
pkg-config has not been configured to support cross-compilation.
Install a sysroot for the target platform and configure it via
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
cross-compiling wrapper for pkg-config and set it via
PKG_CONFIG environment variable.', /Users/lisa/.cargo/registry/src/github.com-1ecc6299db9ec823/zmq-sys-0.8.3/build.rs:31:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
I am trying to build the appropriate library for the iOS and iOS simulator architectures without relying on pkg-config, but if someone can provide useful instructions for configuring pkg-config for cross-compilation, I am not opposed to it, I just don't know how and can't find any up to date resources.
I have cloned the libzmq project from this github: https://github.com/zeromq/libzmq.git, then navigate into libzmq.
Inside libzmq, I run ./autogen.sh followed by ./configure --prefix [directory location] --target "aarch64-apple-ios", then make and make install.
The above procedure without the --target flag is how I got the project to compile on my Mac in the first place, and with the target flag in place make and make install both complete successfully, but when I try to build the project using PROJECT_DIR="${PWD}/ProjectName" ./ProjectName/build-rust.sh,
I get the previously posted error.
I am following the Swift-Bridge Book (https://chinedufn.github.io/swift-bridge/building/xcode-and-cargo/index.html) to try to load the Rust libraries into Xcode.
One thing to note: In the libzmq git hub, there is a folder called builds/ios/ and inside this folder is what looks to be a build file for all of the iOS archs, but I haven't been able to get the repo to build with that file. I think figuring out how to use the build_ios.sh build file as opposed to the standard build.sh provided might be the answer, but I've tried dropping build_ios.sh where build.sh is, and ./autogen.sh doesn't work, because it complains that it can't find configure.ac, even though this file does exist.

How build clang-tools? "make clang-tools" does nothing

I succesfully checked-out llvm (v12) project and built llvm+clang invoking:
cmake -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
make check-all
After this operation empty clang-tools directory appeared. After calling make clang it remains empty. When I call make clang-tools it does nothing - there is a target with this name because there is no error info about missing target but the command doesn't do nor print anything. On the other hand, when I try make clang-tools-extra it complains that there is no such project despite the fact that I configured it with cmake. So I'm also unable to build clang-tools-extra.
What am I doing wrong?
update:
There is no CMakeFiles directory in llvm/clang/tools which is - I think - unexpected.
Find the list of targets in the output of ninja help or make help or xcodebuild -list or any other generator.
A project's external name can very well be different from the internal target name.
If you want to build everything, just set the install prefix:
cmake -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm -DCMAKE_INSTALL_PREFIX=../my_install
and run make install
It will do the right thing.

CMake: How can I copy a directory into the ios application bundle

I have an ios project that builds with CMake 3.1.1, but I am stuck on the last problem - getting CMake to copy the asset directory into the right location for the app.
I have this, which works when running the app in the simulator. However, it does not work, and in fact causes a build failure when archiving because the destination directory it constructs does not exist.
get_target_property(APPLICATION_BIN ${APPLICATION_NAME} LOCATION)
get_dotapp_dir(${APPLICATION_BIN} APPLICATION_APP_LOCATION)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND cp -r "${CMAKE_SOURCE_DIR}/assets" "${APPLICATION_APP_LOCATION}")
The directory I am copying has many subdirectories and I need them all preserved. Essentially I want to accomplish with cmake the same thing that happens when I drag the "assets" folder into the ios project underneath "Resources".
Use ${CMAKE_COMMAND} -E copy_directory instead of calling cp.
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP} DEPENDS "${PROJECT_SOURCE_DIR}/assets" COMMAND -E copy_directory ${PROJECT_SOURCE_DIR}/assets ${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP})
add_custom_target(${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP} DEPENDS
My solution to this is similar to this answer. The goal of my project was to get googletests running on a cross-platform library, in which I had to wrap googletests into an XCTest Bundle. The build tool we are converting to is CMake for obvious reasons.
I ended up doing this as a pre-build step:
add_custom_command(TARGET ExampleTestTarget PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/resources $<TARGET_FILE_DIR:ExampleTestTarget>
)
Essentially, at prebuild, CMake will copy everything in the resources folder into the root of the target's bundle. For some reason (probably a CMake thing), XCode picked these resource files up with no issue, so I didn't have to set the files to be RESOURCE files explicitly.
If you're using MacOS Bundles/Packages/etc., you'll have to copy-paste these files into $<TARGET_FILE_DIR:ExampleTestTarget>/Resources instead since this is the default resource location for MacOS xcodeproj's generated by CMake. (There are so many loopholes to get XCTests working in CMake that I advise everyone doing cross-platform gtests to create an executable instead for MacOS so you won't get into any trouble like this anyway).
Note, you won't see the files in XCode unless you add the files in target_sources(), but who cares... it works anyway! Who develops C++ exclusively in iOS? ....

xcodebuild failure clang:error no such file or directory:

Having a problem when building with xcodebuild. My project/app builds fine with the Xcode - gui. It simply isn't finding/building the libcryptopp library which is part of the build process.
The error is:
clang: error: no such file or directory: '/Users/builder/repo/ioskpay/xcode-cryptopp/cryptopp/build/Release-iphoneos/libcryptopp.a'
This particular file should be derived from another project inside the main app - xcodebuild simply isn't correctly pointing at the right file folder which should be:
~/Library/Developer/Xcode/DerivedData
Any ideas?
To fix this, go to your project settings, go to Targets and select your main project target. Then go to Build phases. Under Target dependencies add the static library project.
This way, when you compile the main project, the static library subproject gets compiled before the main project and your static library will be available.
I had the same problem, but for a resource file .m
I opened target -> build phases -> Compile sources
and I found the file the compiler was tell it can't find duplicated: one with strange icon and the other with a normal icon. I simply removed the one with strange icon and it worked. ( I added the file multiple times and I had a merge conflict before that which made something wrong in the project file)
For your case I think you need to remove the lib from target dependencies list and add it again. This may work for you.
In Xcode Version 9.2 (9C40b) this happened when I drug a bunch of files into the project, some of which were duplicate. Rather than simply not adding the duplicates, it added them again and only the name, not the path.
In Target > Build Phases > Compile Sources each of the duplicates showed with no "...in" after them. Each one caused the clang error.
After removing all of the duplicates that Xcode collected, the project compiled and ran.
It makes you use the Project Navigator instead of managing your source files in the Finder. Then the Project Navigator can't replace duplicates like any decent file management system (ahem Finder). 🤨
My xCode info is:
I faced similar errors during xcode building projects (native swift, flutter, react native, native script) in which I got error messages related to clang compilar. Errors like:
clang-4.0: error: no such file or directory: '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxxxxxxx/Index/Data Store'
clang-4.0: error: cannot specify -o when generating multiple output files
others
Despite of errors related with DerivedData for native apps can be fixed by deleting the directory and, eventually, restart xCode and even restart the machine... in this case, you will see that after deleting the directory and start building process again, the error comes back.
Then, is the moment of checking the clang installation by running clang --version. The normal output will be something like:
as you can see the InstalledDir is incorrect for xCode. In my case, some days ago I needed to install Anaconda app (R, Python, etc) and, now, I remember that I had to install some dependencies and one of them was clang and its installation was altered.
To fix this problem (in my case that I will not need anaconda any more): (edited)
1.- Delete anaconda and all its dependencies (I recommend to use App Cleaner).
2.- Re-install xCode
After reinstalling xCode, if you type again clang --version, you'll get this:
More info at: https://github.com/flutter/flutter/issues/32457#issuecomment-496161092
Hopefully, this info helps some else.
Best
Ok so by simply adding the correct -target -configuration and -scheme parameters I got this to run correctly. However due to my running this in Jenkins for autobuild purposes it still doesn't work as I'd like - getting stuck in exactly the same place. It's odd because I have the exact same code being built in another job that isn't having this problem. There is no rhyme or reason for it at this point. I will keep shooting rubber bands at it and update when I have an answer...
Sometimes Xcode performs weird.
You have to find that static library project e.g.. "filename.a" under 'Link Binary With Libraries' in Build Phase and then remove it and add it again.
I had the same problem while I was archiving my target. I removed the library and the build succeeded.
For me it was because I had removed a package or pod. I ran pod install and it fixed it
Look for the missing file in the Xcode project i.e the files may be deleted or miss placed.
add the missing files to the xcode, then everything will work fine.
Run this command :
$ conda deactivate

Resources