Search code examples
c++openglcmakecpack

Including external libraries in cpack output


Im currently working on a cmake project which is making use of external libraries which are being imported through the find_package function. My question revolves around cpack and how I am supposed to go about adding the found packages into the cpack output. For example if I use this

find_package(OpenGL REQUIRED)

add_executable(Example_App MACOSX_BUNDLE src/main.cpp)

target_include_directories(Example_App SYSTEM PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(Example_App PUBLIC ${OPENGL_LIBRARIES})

install(TARGETS Example_App
    BUNDLE DESTINATION "."
    RUNTIME DESTINATION bin)

If I then run cmake .. followed by make and make package my output from cpack (I can include an example of my cpack code if needed too) would then be. ExampleApp-linux.tar.bz2

- bin
-- Example_App
- Share
-- Resource files

Rather than something like:

- bin
-- Example_App
- Lib
-- OpenGL.a
- Share
-- Resource files

Any help would be much appreciated!


Solution

  • You would have to explicitly add an install rule for the external project libraries.

    For example:

    install(FILES ${OPENGL_LIBRARIES}
      RUNTIME DESTINATION bin COMPONENT RuntimeLibraries
      LIBRARY DESTINATION bin COMPONENT RuntimeLibraries
      ARCHIVE DESTINATION Lib COMPONENT Development
      )
    

    Or you could use a specific library reference like ${OPENGL_gl_LIBRARY} instead of ${OPENGL_LIBRARIES}. See Modules/FindOpenGL.cmake for more details.