Very well explained [here](https://stackoverflow.com/questions/17511496/how-to-create-a-shared-library-with-cmake).