Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use cmake on mac

this may seems obvious for someone, but not for me.

How to use cmake on Mac? Let's say I have a project in Xcode and I want that project link with assimp library.

So I download assimp source, generate build with cmake, point Xcode to /include in downloaded source and what then? Where are built libraries? What I only have is Xcode project of that library. Does it generate libraries?

If I use brew to install assimp, I only set this in my Xcode project:

  1. header path is:
    /usr/local/include
  2. library search path is:
    /usr/local/lib
  3. set liner flag to:
    -lassimp

and I'm finished.

What are benefits of cmake for building libraries from source besides that source is "fresh" and I'm unable to do it right?

Could somebody post step-by-step what to do when building things with Cmake, with explanation?

Most importantly where does Cmake put libraries, and how to link with them?

like image 316
martinerk0 Avatar asked Apr 19 '15 08:04

martinerk0


1 Answers

CMake does not build the libraries, it "only" generates platform specific Makefiles (or equivalents). You still need to compile and install the compiled libraries and headers.

For the library you want to build the following steps are necessary (I am doing them on Linux, but this should be applicable to Mac OS X as well).

git clone https://github.com/assimp/assimp.git
cd assimp
mkdir build
cd build
cmake ..

The build folder now contains a Makefile, and when you run make, the library will be compiled.

After this step, the freshly built library is located at build/code/libassimp.so.

You could leave the library as well as the include files there and reference them when compiling/linking your project. Usually, you want to install them, so they are available systemwide and can be found automatically.

This is done using sudo make install.

The library should now be in /usr/local/lib, the include files in /usr/local/include. You can change these locations using CMake.

like image 79
m.s. Avatar answered Sep 29 '22 08:09

m.s.