title: CMAKE create OSX bundle for dylib?
body: <p>I need some help from from someone that unlike me actually knows something about CMAKE.</p>
  
  <p>Problem:
  I have this CMAKE project that produces a .so/.dylib/.dll (its a plugin for another application) and so far everything is fine it's  compiling and linking and produces the expected output. It's setup to build as a MODULE like this: </p>
  
  <pre><code>ADD_LIBRARY(${PROJECT_NAME} MODULE ${CORE_SRC} ${CORE_HEADERS})
  </code></pre>
  
  <p>with a healthy bunch of external dependencies and a few compiler/linker settings.</p>
  
  <p>And builds using two custom targets:</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>My problem is that on osx this dylib must be packaged as a osx BUNDLE or it wont load. I could create the bundle directory structure manually but with my not so comprehensive CMAKE knowledge I do believe I should be able to have it generated for me. I did try to follow some examples, but I could only get it to work for executable files.</p>
  
  <p>What I would like is to have my dylib installed into a bundle with its resources inside my out of source directory. On other platforms the resources just go into a folder next to the dylib. And then have the bundle installed, or dll and folder, into whatever destination they are destined for.</p>
  
  <p>So how to bundle a module? Is it even possible or am I wasting my time?</p>