For Macos, I'd like to link to some framework. In windows, I would like to link to some library.
For example, OpenGL Framework, how to express this requirement using cmake?
You could try the following code:
target_link_libraries(<target name>
"-framework AVFoundation"
"-framework CoreGraphics"
"-framework CoreMotion"
"-framework Foundation"
"-framework MediaPlayer"
"-framework OpenGLES"
"-framework QuartzCore"
"-framework UIKit"
)
To tell CMake that you want to link to OpenGL, add the following to your CMakeLists.txt
:
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(<your program name> ${OPENGL_LIBRARIES})
find_package
will look for OpenGL and tell the rest of the script where OpenGL is by setting some OPENGL* variables. include_directories
tells your compiler where to find OpenGL headers. target_link_libraries
instructs CMake to link in OpenGL.
The following code will do different actions based on the operating system:
if(WIN32)
#Windows specific code
elseif(APPLE)
#OSX specific code
endif()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With