将编译的库和包含文件添加到CMake项目中? [英] Adding compiled libraries and include files to a CMake Project?

查看:676
本文介绍了将编译的库和包含文件添加到CMake项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将预构建库包含到cmake项目中的最佳方法是什么?我想将FreeType包含到我正在处理的项目中,文件结构如下所示:



  • 构建
    $ b

    • MacOS


      • 制作/

      • XCode /


    • Windows


      • VisualStudio /



      • 来源


        • libs


          • MacOS


            • libfreetype


          • Windows


            • freetype.dll



        • 包括


          • freetype /(由ftbuild自动包含的各种头文件.h)

          • ftbuild.h(这是我理解的代码中包含的内容。)


          • MyProject
            $ b

            • main.cpp

            • foo.cpp

            • foo.h




库已经编译完成。 MyProject是当前项目的名称。



谢谢!
Mike

解决方案

最近的版本已经有了一个用于查找FreeType的模块。以下是我过去所做的事情:

  INCLUDE(FindFreetype)
IF(NOT FREETYPE_FOUND)
FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype freetype.dll PATHS./libs/MacOS./libs/WindowsDOCFreetype library)
FIND_PATH(FREETYPE_INCLUDE_DIRS ftbuild.h./includesDOC Freetype包含)
ENDIF(NOT FREETYPE_FOUND)
INCLUDE_DIRECTORIES($ {FREETYPE_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(MyProject $ {FREETYPE_LIBRARIES})

您需要将路径更改为相对于您的CMakeLists.txt。



调用FindFreetype模块检入标准系统位置。如果它无法在那里找到该库,那么这将回退到检查与您的CMakeLists.txt脚本相关的目录。如果 仍然失败,您仍然可以通过常用的CMake UI设置或覆盖位置。在任何情况下,它都会尝试添加一些东西到包含和库的链接中。


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

解决方案

Recent versions already have a module for finding FreeType. Here's the kind of thing I've done in the past:

INCLUDE(FindFreetype)
IF(NOT FREETYPE_FOUND)
  FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype freetype.dll PATHS "./libs/MacOS" "./libs/Windows" DOC "Freetype library")
  FIND_PATH(FREETYPE_INCLUDE_DIRS ftbuild.h "./includes" DOC "Freetype includes")
ENDIF(NOT FREETYPE_FOUND)
INCLUDE_DIRECTORIES(${FREETYPE_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(MyProject ${FREETYPE_LIBRARIES})

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.

这篇关于将编译的库和包含文件添加到CMake项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆