What is the best method to include a prebuilt library to a cmake project? I want to include FreeType into the project I am working on and the file structure is like this:
- Build
- MacOS
- Make/
- XCode/
- Windows
- VisualStudio/
- Source
- libs
- MacOS
- libfreetype
- Windows
- freetype.dll
- includes
- freetype/ (Various header files that are included automatically by ftbuild.h)
- ftbuild.h (this is what is included in code from my understanding.)
- MyProject
- main.cpp
- foo.cpp
- foo.h
The library is already compiled. MyProject is the name of the current project.
Thanks! Mike
Just use target_link_libraries with the full path to the prebuilt lib.
So, something like:
Recent versions already have a module for finding FreeType. Here's the kind of thing I've done in the past:
You'll need to change the paths to be relative to your CMakeLists.txt.
This snippet first invokes the FindFreetype module to check in the standard system locations. If it fails to find the library there, then this falls back to checking directories relative to the your CMakeLists.txt script. If that still fails, you can still set or override the locations via the usual CMake UI. In any event, it tries to add something to the list of includes and libraries to link.