qmake到Cmake的过渡:外部库的语法 [英] qmake to Cmake transition: syntax for external librairies

查看:111
本文介绍了qmake到Cmake的过渡:外部库的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于特定项目,我要退出qmake,现在必须使用cmake.

For a specific project I am moving out of qmake and now have to use cmake.

我的路径如下:来源:〜/Projects/Project

My path are the following: Source : ~/Projects/Project

外部静态库(在这种情况下为OSVR)路径:〜/osvr/lib/,〜/osvr/include/osvr/osvr/include/jsoncpp

External static library (OSVR in this instance) paths : ~/osvr/lib/ , ~/osvr/include/osvr /osvr/include/jsoncpp

使用qmake,该库的链接部分曾经是:

Using qmake, the linking part to that library used to be:

INCLUDEPATH += /usr/include

LIBS += -L$$PWD/../../osvr/lib/ -losvrClientKit -losvrClient -losvrCommon    -losvrUtil -ljsoncpp

INCLUDEPATH += $$PWD/../../osvr/include/
INCLUDEPATH += $$PWD/../../jsoncpp/include/
DEPENDPATH += $$PWD/../../osvr/lib/

现在我需要使用cmake,但是该库未链接到:

Now I need to use cmake, but the library is not linked to:

我的cmake.txt的相关部分:

The relevant part of my cmake.txt:

set(OSVR_DIR /home/pilou/osvr)
set(OSVR_INCLUDE_DIR /home/pilou/osvr/include/osvr/ClientKit)
find_library(OSVR_LIBRARIES ${OSVR_DIR}/lib)

[...]

target_link_libraries(myexec ${QT_LIBRARIES} ${OSVR_LIBRARIES} )
target_include_directories(myexec PUBLIC include ${OSVR_DIR}/include )

哪些不起作用...

因为我不太确定如何做,所以会有一点帮助是很可爱的

A little help would be lovely as I am not too sure about how:

  • 以确保已扫描外部包含文件夹

  • to ensure the external include folder is scanned

链接到我的3个库osvrClientKit osvrClient osvrCommon.

to link to my 3 libraries osvrClientKit osvrClient osvrCommon.

事实上,我也对一个很好的解释感兴趣.预先感谢.

As a matter of fact I am also interested in a good explanation. Thanks in advance.

感谢ComicSansMs的回复,并且后代使用了有效的Cmake语法:

EDIT : Thanks to the reply from ComicSansMs and for the posterity, the working Cmake syntax :

set(OSVR_DIR /home/pilou/osvr)
set(OSVR_INCLUDE_DIR /home/pilou/osvr/include)
find_library(OSVR_CLIENT_KIT_LIBRARY osvrClientKit HINTS ${OSVR_DIR}/lib)
find_library(OSVR_CLIENT_LIBRARY osvrClient HINTS ${OSVR_DIR}/lib)
find_library(OSVR_COMMON_LIBRARY osvrCommon HINTS ${OSVR_DIR}/lib)
find_library(OSVR_UTIL_LIBRARY osvrUtil HINTS ${OSVR_DIR}/lib)
find_library(JSONCPP_LIBRARY jsoncpp HINTS ${OSVR_DIR}/lib/x86_64-linux-gnu)
set(OSVR_LIBRARIES ${OSVR_CLIENT_KIT_LIBRARY} ${OSVR_CLIENT_LIBRARY} ${OSVR_COMMON_LIBRARY} ${OSVR_UTIL_LIBRARY} ${JSONCPP_LIBRARY})

并跟踪:

target_link_libraries(myExec ${QT_LIBRARIES} ${OSVR_LIBRARIES} )
target_include_directories(myExec PUBLIC include ${OSVR_INCLUDE_DIR} )

推荐答案

您对 find_library 的使用看起来是错误的.

Your use of find_library looks wrong.

查看 find_library 的联机帮助页.您必须提供要查找的库的名称作为参数.您可以选择提供其他提示,以找到该库的位置:

Check out the manpage for find_library. You have to give the name of the library you want to find as an argument. You can optionally provide additional hints where to find that library:

find_library(OSVR_COMMON_LIBRARY osvrCommon
             HINTS ${OSVR_DIR}/lib)

请注意,每个库都需要一个单独的 find_library 调用!由于您的库似乎具有相互依赖关系,因此在CMake中对其进行建模的正确方法是还为每个库添加导入的目标,然后对相互依赖关系进行建模正确定位这些目标.

Note that you will need one separate find_library call for each library! Since your libraries seem to have interdependencies, the correct way to model them in CMake is to also add an imported target per library and then model the interdependencies on those targets correctly.

如果您还不满意这样做,还可以按照正确的顺序将所有查找库添加到单个 OSVR_LIBRARIES 变量中,然后依赖于此:

If you don't feel comfortable doing that yet, you can also add all the find libraries to a single OSVR_LIBRARIES variable in the correct order and then depend on that:

find_package(OSVR_COMMON_LIBRARY ...)
find_package(OSVR_CLIENT_LIBRARY ...)
find_package(OSVR_CLIENTKIT_LIBRARY ...)
 ...

set(OSVR_LIBRARIES ${OSVR_CLIENTKIT_LIBRARY} ${OSVR_CLIENT_LIBRARY} ${OSVR_COMMON_LIBRARY} ...)
target_link_libraries(myexec ${QT_LIBRARIES} ${OSVR_LIBRARIES})

请注意,尽管这种方法在将来的更改方面非常脆弱,但通常应避免使用导入的目标.

Note though that this approach is quite fragile with regards to future changes and should in general be avoided in favor of the imported targets.

此外,请确保在您的find调用实际上找不到任何内容的情况下,您确实具有适当的错误处理机制.

Also, be sure that you actually have proper error handling mechanisms in place for the case that your find calls do not actually find anything.

这篇关于qmake到Cmake的过渡:外部库的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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