问题
I have tried finding this information on the official CMAKE wiki as well as searching SO (currently waiting for boost to download so I can wade through the source looking for how they do it). I was hoping someone here may be able to help with how this is done, or point me in the right direction to the answers!
I have a project that has several components. Right now, the project has subdirectories for libraries, and for applications. I am attempting to refactor the project and have applications in individual repositories and have the libraries exported.
How do other projects make it possible to use the following command (specifically, specifying which components):
FIND_PACKAGE (Boost REQUIRED COMPONENTS system date_time filesystem)
I would like to use the same system for my own project:
FIND_PACKAGE (Project REQUIRED COMPONENTS view gui execution analysis)
Any help you could provide would be greatly appreciated.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/17976594/how-to-export-libraries-with-components-in-cmake