Add a library to CMake macOS bundle - c++

How can I add a libary to a macos bundle, such that it ends up in the bundle as well? The library in question is part of the project, which has two targets: a library and a
bootstrapper executable. If I make the boostrapper executable a Macos Bundle the app bundle is built and works fine but however the library is not put into the bundle. How can I achieve this? It is a rather general question but you can see the current state here.

Related

Can't add dynamic frameworks to Command Line Tool

Goals
I added Command Line Tool target to an iOS app and linked with swift frameworks. (tested with Realm and SwiftyJSON)
Expected Results
Build Command Line tool with those libraries.
Actual Results
Xcode output:
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: .../Xcode/DerivedData/.../Build/Products/Debug/RealmSwift.framework/Versions/A/RealmSwift
Reason: Incompatible library version: RealmSwift requires version 1.0.0 or later, but libswiftCore.dylib provides version 0.0.0
Steps to Reproduce
Create empty Swift Command Line Tool and link Realm frameworks
Code Sample
CommandLineTest.zip
Version of Frameworks and Tooling
Realm version: github "realm/realm-cocoa" "master"
SwiftyJSON version: github "acegreen/SwiftyJSON" "swift3"
Xcode version: 8 GM (which is on the App Store)
Dependency manager + version: Carthage 0.18
Command-line tools are best with static archives because everything is distributed as a single binary. Looking at Realm, I don't see that there is a static archive option. They do have an iOS static framework that I got compiling for macOS but that's not quite what you want. You might want to try playing with Realm's source a bit more to see if you can get it to produce a static archive.
In the mean time, as a workaround, you'll need to tell Xcode where to find the dylibs at runtime and also to install them somewhere.
In your Build Settings, go down to "Runpath Search Paths" and add "#rpath".
In Build Phases, under Copy Files, click the + button and add both Realm.framework and RealmSwift.framework from your project.
Because Realm is compiled with an older version of Swift, you also need to specify "Use Legacy Swift Language Version" in Build Settings.
That will get your project building and finding the Realm libraries but now it will fail to find libswiftCore.dylib. That's because normally command-line tools are statically linked with the Swift library but as soon as you add a framework/dylib, the linker no longer includes the static version.
Go back to Build Phases, Copy Files, and add the following:
libswiftObjectiveC.dylib
libswiftIOKit.dylib
libswiftFoundation.dylib
libswiftDispatch.dylib
libswiftDarwin.dylib
libswiftCoreGraphics.dylib
libswiftCore.dylib
You can find them inside your Xcode installation and then ./Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/macosx/
WARNING: Keep in mind that you will need to distribute the frameworks and the dylibs with your command-line tool and they will need to be in the same directory as the tool. You can put them somewhere else on the system by specifying a different runpath but you'll still need them distributed with your tool.
The nice thing about a .app bundle is that it gives you a place to put this stuff and users can just drag-and-drop it to install it. If you could get a static archive version of Realm, you could distribute everything in one binary.

Generate a redistributable project with CMake

I'm looking for generating a redistributable project for Windows and Linux using CMake as project configuration system and gcc-4.8 / VS2012, plus extra thirdparty libraries like Qt5. How can i create a package with all the needed dependencies and make the project running on other machines, without installing on those machines the required packages (i.e. Qt5 setup)?
EDIT
Googling heavily i've found Qt5 requires some files and i've found this discussion
Application deployed with QT5 libraries does not start on Windows 7
which explains the required Qt5 dependencies.
Normally, I would use install to list the desired files and CPack for packaging them. That is, suppose I'd like to create a package consisting of the following components:
my_nifty_library.dll
my_nifty_executable.exe
QtCore.dll
QtGUI.dll
(Disclaimer: I'm not Qt expert so the last two files might not exist at all, but you get the idea.)
Given that both my_nifty_library and my_nifty_executable are part of your project, you have control over them, so simply do the following:
install(TARGETS my_nifty_library my_nifty_executable
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
Now, since Qt won't be built as part of your project, I suggest you use the ExternalProject module.
Now, you can use CPack and create, say, a NSIS installer or a tar.gz out of the installed files.

Using Ogre library locally for a project

what I would like to do is to have an application (I am currently working off the sample framework app) and include any ogre library files with it, as opposed to have it installed for the whole system. This way I can easily port the application onto other computers once built.
I am on Mac OS 10.9. I built Ogre by first running the CMake app to configure the Xcode project, then opening the created Xcode project and building the Install and SampleBrowser congifurations. A directory sdk/lib was created in the Ogre directory. This contains directories debug, OGRE and pkgconfig. The OGRE directory has all the samples .dylib files. What I do not see is the main ogre library file.
The contents of the file lib/pkgconfig/Ogre.pc suggest that there should be a library file called OgreMain in the lib directory:
Libs: -L${libdir} -lOgreMain -lpthread
As far as I understand it, I need this library file to be a part of my project. I could then link the sdk/include for all the Ogre's header files. I am confused about how to make this work. Could anyone please help?
Sounds like this is Ogre 1.8. In that case the libraries and frameworks need to be installed in your application bundle. Inside MyApp.app/Contents you will need folders named Components, Plugins and Frameworks. Ogre.framework goes in frameworks, component dylibs go into Components, plugin dylibs go in Plugins.
I actually found a great tutorial that worked straight away for me here: http://will.thimbleby.net/ogre3d-tutorial/
This is for Ogre 1.8, the only difference when using Ogre1.9 is that you don't use RenderSystem_GL.dylib but RenderSystem_GL.framework (found at the same place as Ogre.framework) and you deal with it in the same manner in terms of your project setup as with Ogre.framework.

How do I compile libnoise on Mac OS X Mountain Lio

I am new to the Mac OS X environment when it comes to compiling linux based libraries. Whenever I used a library i just downloaded the .framework file, added it to my /Library/Frameworks and included it in my XCODE project, and all was fine.
Now I am stuck with libnoise. I want to use it on my project and I have no idea how to generate the .framework file/directory.
Can you help me please?
If you have libnoise, most likely it contains some sort of a Makefile or a configure script.
By running the
./configure
make all
you will get the library file (libnoise.a) for your platform, the OSX10.8.
Framework is essentially a folder with specific layout and a .plist file. To generate such a folder automatically, you may create an expty Xcode project of the type Framework and add the libnoise.a you've just created as a linker's input.
There is a detailed instruction on how to create the Framework from static libraries (.a files): http://www.blackdogfoundry.com/blog/creating-a-library-to-be-shared-between-ios-and-mac-os-x/
You might be missing the header files in you framework, but then can be also added to the Xcode project from libnoise sources.
This SO answer may be of use also: Difference between framework and static library in xcode4, and how to call them
Apple's documentation is also good: https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
I'm not entirely sure if this is what was meant by "with a different fork and cmake"
but I got libnoise to run in my mac using this git repo.
https://github.com/qknight/libnoise

Windows package-manager for C++ libraries

I've been working on various open-source projects, which involve the following C++ libraries (& others):
MuPDF
Boost
FreeType
GTKmm
hummus PDF libraries
LibTiff
LibXML2
Wt xpdf
xpdf
Poppler
ZLib
It often takes a long time to configure these libraries, when setting them up on a clean machine. Is there a way to automate the grabbing of all dependencies on a windows machine?
The closest I've found is CMake, which checks to make sure you have the dependencies installed/extracted before generating your project files. But I haven't found anything for Windows which can parse the list of dependencies and then download+install the required versions.
Please recommend a package manager for Windows with up-to-date C++ libraries.
Vcpkg, a Microsoft open source project, helps you get C and C++ libraries on Windows.
Take a look at the Hunter package manager when you already use CMake to setup your project. It automatically downloads and builds your dependencies whith only a few lines of extra cmake code. Hunter is based on cmake export and import targets.
For example if you want to use the GoogleTest library in your cmake based project you would add the following lines to your root CMakeLists.txt
# file root CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
# To get hunter you need to download and include a single cmake file
# see documentation for correct name
include("../gate.cmake")
project(download-gtest)
# set the location of all your hunter-packages
set( HUNTER_ROOT_DIR C:/CppLibraries/HunterLibraries )
# This call automaticall downloads and compiles gtest the first time
# cmake is executed. The library is then cached in the HUNTER_ROOT_DIR
hunter_add_package(GTest)
# Now the GTest library can be found and linked to by your own project
find_package(GTest CONFIG REQUIRED)
add_executable(foo foo.cpp)
target_link_libraries(foo GTest::main)
Not all the libraries you list are available as "hunter-packages" but the project is open source so you can create hunter-packages for your dependencies and commit them to the project. Here is a list of libraries that are already available as hunter packages.
This will not solve all your problems out of the box because you have to create hunter-packages for your dependencies. But the existing framework already does a lot of the work and it is better to use that instead of having a half-assed selfmade solution.
Biicode is a new dependency manager for C++. It also has a few libraries that you listed. Biicode automatically scans your source files for dependencies, downloads and builds them. See here for a very cool example that includes Freeglut.
What I've found:
Closest thing to what I'm looking for:
NuGET
Unfortunately it doesn't have any of the libraries I require in its repository.
So I ended getting most of the libraries from the KDE4windows project and custom building the rest.
Npackd is a package manager for Windows. There is a default repository for C++ libraries and also a third party repository for Visual Studio 2010 64 bit libraries. Boost and zlib are already in the default repository. If you decide to use Npackd, you could file an issue if you need other libraries.
Windows does not have a package manager. Go to the libraries' website and download the Windows builds if they provide any.
There are some alternatives, but not without drawbacks:
Cygwin: provides a nice package manager, but all binaries are built for Cygwin, which means they run slower than their native equivalent, any apps using them will link to the Cygwin DLL, and you're stuck with that license. Also the use of the native Win32 API is sometimes troublesome due to incompatibility with the POSIX emulation offered. Only for GCC.
MinGW-get: is a package manager for the MinGW.org compiler. These are native Win32 binaries, but only for use with MinGW's GCC.
There is no package manager or slightly equivalent thing for anything Visual Studio or MinGW-w64 related.
There is no package management on Windows. On Windows developers typically use full-blown everything-and-the-kitchen-sink development environments and produce monolithic applications themselves, shipped with all dependencies.