Need help trying to make Cmake find third party libraries

戏子无情 提交于 2019-11-30 17:59:53
André

In the case of ZLib, a FindZLIB.cmake is provided with CMake and you can "simply" put a find_package call in your cmakelists. If necessary you can make some modifications to findzlib.cmake to suit your needs. E.g. adding ZLIB_DIR as an additional hint when searching for the library. This ZLIB_DIR can then be set by the user.

Assuming your library/executable is called YourProject, you can use it as follows.

find_package( ZLIB REQUIRED )
if ( ZLIB_FOUND )
    include_directories( ${ZLIB_INCLUDE_DIRS} )
    target_link_libraries( YourProject ${ZLIB_LIBRARIES} )
endif( ZLIB_FOUND )

You should use the same approach for TagLib, but instead should write your own FindTagLib.cmake (or search for a good one).

The important part here is that you give the user the option to set a TagLib_DIR variable, which you use to search for TagLib and that you use FindPackageHandleStandardArgs to report success or failure.

Not sure about interactive prompt, but you always can use environment variables or following:

cmake -D<VAR_NAME>:STRING=<path to custom zlib> .

to provide cmake with custom zlib or taglib location.

Don't forget to update FindZLIB.cmake to handle this variables in FIND_PATH and FIND_LIBRARY

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!