Define Xcode copy files build phase in CMake - cmake

My iOS project uses third-party dynamic library that needs to be code-signed and bundled into the application. In Xcode, this can be easily achieved by adding new Copy files build phases. The Xcode project is generated with CMake, however I can't find a way to define this copy files build phase. MACOSX_PACKAGE_LOCATION makes the library treated as bundle resource and doesn't do code signing.
There is surprisingly very little information on the topic on the web, so does anybody know if it is possible to define Copy files build phases in CMake? Or, alternatively, is there another way to code sign and bundle third-party dynamic library using CMake?

Related

Ksp multiplatform redeclaration of files

I am implementing ksp processor in kotlin multiplatform targeting iOS and android applications, following documentation I'm defining multiple configuration names for KSP ie:
add("kspIosArm64", project(":test-processor"))
add("kspIosX64", project(":test-processor"))
However running those gives me file redeclaration error. Indeed files are created in separate locations:
build/generated/ksp/iosArm64/ and build/generated/ksp/iosX64/ but packages are the same.
And Im quite lost how to solve this issue, is there any way of getting this generated folder path for each generated file so that package can be modified?
I will try to partially answer your questions right now, not to make you stack and focus on making the project able to run. I assume that you are using XCode to run the project for iOS. The problem here is that (as you mentioned) all of those source sets are being generated with the same package name which is more a KSP issue (I think) that we have to wait for to be solved.
What you can do for now to run and test the project is:
Make sure to clean your build with ./gradlew clean before running the project (especially between Android and iOS runs)
I think clean can be added as a "step" before KMM framework task:
XCode Project file -> Build Phases -> Generate KMM framework -> add clean before running gradle task responsible for building framework (This can will make build time longer)
./gradlew :yourSharedModule:clean :yourSharedModuleName:embedAndSignAppleFrameworkForXcode
Selected only one architecture to be build when running the project
XCode Project -> Build Settings -> Architectures -> Build Active Architecture Only -> Yes
This solutions makes only one architecture to be build and run (it is probably a simulator in your case), issue here is you may have some problems with other architectures and will not be able to spot them easily on daily development.
Create some kind of env or a build config value to distinguish which ksp dependency to add (based on it's value) so not all of processors are added when running the project
XCode Project -> Build Phases -> Generate KMM framework -> pass it as gradle param -Parchitecture=someArchitecture
Or maybe it is even possible to do it within the build.gradle.kts file
Manually comment out some of ksp dependencies (iOS ones) so the only one against which you are building is left (remember to sync project and clean it)
I personally would try to implement the third solution, I do not know whether it is easy, but it seems to be the best one, other solutions should also work, but please consider them as a dirty walk-around.
I can provide more info or some kind of POC for that later, just let me know in the comments or somewhere else whether it is needed.

Are cmake scripts generally written by hand?

I need to create a cmake project which should be able to be built on linux and windows. So I looked into cmake Tutorials and all of them told me to setup the build process by hand. Bit looking at other projects made with cmake, the scripts seam like they were created by a computer (no formatting no comments). So I was wondering if there was a more automated aproach or tool that can be used for cmake files. Or are most cmake scripts really written by hand?
Yes, CMakeLists.txt are generally written by hand. Generated are SomeProjectConfig.cmake modules, which contain exported targets and information how the project was built. These modules are used by find_package command when you want to use SomeProject from your own project.

Using KDevelop during development of a shared library

I'm trying to use KDevelop as an IDE for development of a C++ shared library. An earlier posts here indicate that I need to edit a CMake makefile for doing that. This is quite painful and very time consuming as it means converting our custom gmake-oriented build system into something of CMake.
Is there any other way for doing that?
KDevelop doesn't force you to use a specific buildsystem like many other IDEs do. CMake is just the default as it's very well integrated and many if not all KDE projects use cmake.
You can use a different build system by choosing "Custom Buildsystem" or "Custom Makefile Project Manager".
Custom Makefile Project Manager simply calls "make" - your current build system should work this that.

pjsip using cmake

Has someone compiled pjsip using cmake?
The project does not have a way of using CMake to build the library itself (yet). But you can link to pjproject libs from your CMake project.
Here's a snippet from one of mine that uses pjproject as a dependency:
find_package(PKGCONFIG REQUIRED)
pkg_check_modules(PJSIP libpjproject>=1.14 REQUIRED)
include_directories(${PJSIP_INCLUDE_DIRS})
...
target_link_libraries(your_target ${PJSIP_LIBRARIES})
This requires pkg-config as well, and that pjproject.pc should be in it's default search path, or in directory in $PKG_CONFIG_PATH.
This should work on Linux and OS X.
I just made cmake-based compilation of PJSIP v2.3.
I use this compilation only on Windows platform for now, not tested on linux.
On Linux I recommend use PKG_CONFIG tool to discover PJSIP for your app.
Having peeked at their repository, the project is auto-tools/configure based. You would need to port the build system yourself. Depending on complexity, it is not that hard to accomplish. I have converted many projects to cmake. Maybe the pjsip comunity would welcome an upgrade to their build system, as I see they support multiple platforms like iphone, and windows through visual studio.
If you are using Clion IDE then it can automatically generate cmake file for pjproject. Just import it and it will open a wizard. You’ll need to specify the location of the sources, then select project files and include directories. Clion has the ability to make the cmake file from existing projects. for more help please see this link Clion Documentation

Setting up Xcode for developing Plug-ins

I've never worked in XCode before but I am designing a plugin (objective-c) for an open source radiology program called OsiriX. I can get the thing to compile and I can even get the plugin to run in OsiriX. But, I'm not sure how to run/debug it from XCode. Run/Debug is grayed out on my xcode. Is it because there's no main program?
(1) "Clean all" your projects so that there isn't detritus left around when you do this.
(2) Set Xcode to use a common build products directory (I stick mine in /tmp/ so that it periodically gets nuked). The preference is under the "Building" section.
(3) Re-build OsiriX (so that it'll be built in the shared location).
(4) Make sure the active configuration in your plug-in project has the exact same name as the configuration in OsiriX that you built in (3). (It should probably be "Debug" or "Release", depending on which you build). The configurations can be edited in the build settings editor.
(5) Build your plug-in.
(6) Add a custom executable to your plug-in project and set the path to OsiriX (Project -> New Custom Executable...).
You should now be able to build-and-run or build-and-debug your project. It will launch OsiriX from the build products directory. You might also want to set OsiriX to look for bundles in your build products directory, if it doesn't already. Or you could create a symbolic link from one of OsiriX's plug-in directories to the bundle in your build products directory.
cd /path/to/OsiriX's/bundle/directory
ln -s /path/to/build/products/YourPlugin.bundle
This is a very standard way of ocnfiguring Xcode for development of plug-ins. For example, preference pane developers will set up a custom executable for SystemPreferences.app (even in /Applications -- there is no need to point to a "debug" build of the application).
In order to debug your plugin, you have to be running Osirix in Xcode as well. Download the Osirix source code from Github and compile and run it. You'll have to add the plugin to its plugin list and then when you run in Xcode your NSLog statements from the plugin source will print out in the Xcode console screen for the main Osirix program. I believe breakpoints work as well.
My experience with Xcode is also somewhat limited, but I've found that using the latest version (6.1.1) I can debug my plugin simply by attaching to a running OsiriX process via the Debug -> Attach Process menu. This does not require you to build OsiriX from source - I'm currently using the standard (non-MD) version as downloaded from their website.
Note that you still need to restart OsiriX to pick up any changes to your plugin.