Jon R
Jon R

Reputation: 13

Building a MacOS executable for distribution using cmake including OpenCV

I have a cmakelists.txt file that compiles my MacOS application using OpenCV, C++, OpenGL, based on information I found on SO. When I try copying the folder of the executable to another Mac, I get an error due to missing OpenCV libs, expected in a different folder from my executable.

Is there a change I can make to the file so that it will include the OpenCV compiled code in the executable, or its folder for distribution? For what it's worth I am using CMake because I could not figure out a simpler way to get it to build.

cmake_minimum_required( VERSION 3.1 )
project( go)
set (CMAKE_CXX_STANDARD 11)
find_package( OpenCV REQUIRED )
find_library( COCOA_FW Cocoa )
find_library( OPENGL_FW OpenGL )
find_library( IOKIT_FW IOKit )
add_executable( go main.cpp gl_utils.cpp user_interface.cpp geometry_2d.cpp)
target_include_directories( go PRIVATE ${CMAKE_SOURCE_DIR}/include )
target_link_libraries( go ${OpenCV_LIBS} ${COCOA_FW} ${OPENGL_FW} ${IOKIT_FW} ${CMAKE_SOURCE_DIR}/common/libGLEW.a ${CMAKE_SOURCE_DIR}/common/libglfw3.a)

Upvotes: 1

Views: 851

Answers (1)

Vi1i
Vi1i

Reputation: 130

On another question related: Static OpenCV compile

set(OpenCV_STATIC ON)
find_package(OpenCV REQUIRED)

Now for the find_library( OPENGL_FW OpenGL ), you will need to be more explicit:

# This could change based on the OpenGL library you have installed.
find_library( OPENGL_FW libGL.a )

Upvotes: 2

Related Questions