How to export libraries with components in CMAKE?

≯℡__Kan透↙ 提交于 2019-12-05 10:45:32

a good guide how to write finders you may found in /usr/share/cmake/Modules/readme.txt (or in cmake sources, if your distro do not include that file). particularly it explains how to write a correct module w/ supporting "standard" syntax (REQUIRE, COMPONENTS & etc) using find_package_handle_standard_args

How to find packages, and also how to write your own find modules is described here: http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries

here is a very simple find module of mine. It´s located in the top dir where all my librarys are located, so in this case finding the correct paths is rather trivial.

# AsmjitConfig.cmake
# - Config file for the Asmjit package
# sets:
# Asmjit_FOUND
# Asmjit_INCLUDE_DIR
# Asmjit_LIBRARIES

set(Asmjit_FOUND FALSE)

find_library(Asmjit_LIBRARY NAMES asmjit HINTS ${CMAKE_CURRENT_LIST_DIR}/asmjit)
find_path(Asmjit_INCLUDE_DIR asmjit/asmjit.h HINTS ${CMAKE_CURRENT_LIST_DIR}/asmjit/src)

message(STATUS "${Asmjit_INCLUDE_DIR}")
message(STATUS "${Asmjit_LIBRARY}")

if(NOT Asmjit_LIBRARY OR NOT Asmjit_INCLUDE_DIR)
    set(Asmjit_FOUND FALSE)
else()
    set(Asmjit_FOUND TRUE)
endif()

in your CMakeLists.txt tell cmake where it can find your modules:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "path/to/librarys")

after that find_package should work just fine.

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