CMake, OpenGL, and GLX on OS X

As you may know, I am staying at Duke this summer for research. My research, which I started last semester and am going to be doing for a while, focuses on scalable algorithms. While that is pretty broad, I am currently working on using the graphics card to speed up processing. Again, here are some technical notes on code.

In doing my work I have come to have to write and run C++ OpenGL code on both OS X and Ubuntu. To make this easier, CMake has been great for both having readable make files and for being able to keep the files consistent across both platforms. Additionally, while GLUT is great for cross-platform OpenGL coding, I needed more control over the environment. Being able to run X11 on OS X has allowed me to test GLX natively without always testing on Linux. However, to get this set up on OS X without XCode can be a little tricky. So, two snippets of CMake files for using OpenGL on OS X and Linux.

If you want to run OpenGL with the standard OS X libraries, CMake generally finds the correct frameworks, but it can’t hurt to specify them more precisely. A basic example of the CMakeLists is shown below:

If, however, you are looking to run your code also on a Linux machine or simply want to use GLX rather than CGL, you will need to have X11 installed (which your OS X installation disk contains) and specifically point CMake at the X11 libraries. The CMake code for this is shown below: