CMAKE creates OSX package for dylib?

I need help from someone who, unlike me, really knows something about CMAKE.

Problem: I have this CMAKE project that creates .so / .dylib / .dll (its a plugin for another application) and so far everything compiles and links fine and produces the expected output. It will tune in to create as MODULE:

ADD_LIBRARY(${PROJECT_NAME} MODULE ${CORE_SRC} ${CORE_HEADERS})

      

with healthy linking of external dependencies and a few compiler / linker tweaks.

And builds using two custom targets:

ADD_CUSTOM_TARGET(debug
        COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
        COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
        COMMENT "Switch CMAKE_BUILD_TYPE to Debug")

ADD_CUSTOM_TARGET(release
        COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
        COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
        COMMENT "Switch CMAKE_BUILD_TYPE to Release")

      

My problem is that in osx this dylib must be packaged as osx BUNDLE or it won't load. I could create the package directory structure manually, but with my less extensive knowledge of CMAKE, I believe I should be able to generate this for me. I tried to follow some examples, but I could make it work with executables only.

I would like my dylib to be installed complete with its resources inside my source directory. On other platforms, the resources just come in a folder next to dylib. Then install the package, or dll and folder, to whatever destination it is for.

So how do you link a module? Is this possible or am I wasting my time?

+3


source to share


1 answer


all of this is quite possible with cmake; I remember that it was difficult for me to find all this.

I have a fairly complex project that does this with dylib, a framework, and a series of plugins (which also have .so

s values ). Here is one of the CMakeLists.txt files that covers most of what you need (around line 38).

If you want cmake to build the box for you, you need to pass MACOSX_BUNDLE

( ADD_EXECUTABLE

) when adding the executable . Note that this is for the application itself, not for dylib.

If you can create a dylib as a framework (property FRAMEWORK

), cmake should automatically place it in the package framework directory when you add it. dito for plugins if you build them using the property BUNDLE

.



you can also manually assign to the property MACOSX_PACKAGE_LOCATION

whatever you like

I believe you might have to do something like this SET(CMAKE_INSTALL_RPATH @loader_path/../Frameworks)

for the purpose.

Let me know if you have any questions and I will update my answer.

+2


source







All Articles