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
cmake is searched first in CMAKE_MODULE_PATH , then in the CMake module directory. There is one exception to this: if the file which calls include() is located itself in the CMake builtin module directory, then first the CMake builtin module directory is searched and CMAKE_MODULE_PATH afterwards.
Just use target_link_libraries with the full path to the prebuilt lib.
So, something like:
# In the file Source/MyProject/CMakeLists.txt
add_executable(my_exe main.cpp foo.cpp foo.h)
if(WIN32)
target_link_libraries(my_exe ${CMAKE_CURRENT_SOURCE_DIR}/../libs/Windows/freetype.lib)
endif()
if(APPLE)
target_link_libraries(my_exe ${CMAKE_CURRENT_SOURCE_DIR}/../libs/MacOS/libfreetype.a)
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