我正在尝试构建一个具有众多依赖项的项目,例如Boost,OpenSSL和C ++ REST SDK。但是,要求源代码包含在项目工作区中,并且库必须由所述源代码构建。
我发现实现这一目标的最持续成功的方法是使用git submodule add <URL>
,add_subdirectory
,target_link_libraries
以及为此目的而构建的一些聪明项目,例如{{3 }}和boost-cmake。
以以下项目结构为例:
prjct
| include/
| libs/
| | boost-cmake/
| | openssl-cmake/
| | cpprestsdk/
| src/
| tests/
| CMakeLists.txt
顶级CMakeLists.txt将包含以下内容:
...
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/boost-cmake)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/openssl-cmake)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/cpprestsdk)
target_link_libraries(${PROJECT_NAME_L}
PUBLIC
Boost::system
Boost::thread
Boost::log
Boost::program_options
Boost::chrono
ssl # OpenSSL::SSL
crypto # OpenSSL::Crypto
cpprestsdk::cpprest
)
...
但是,对于cpprestsdk库,从cmake ..
运行build/
时收到以下错误:
CMake Error at CMakeLists.txt:55 (add_library):
Target "prjct" links to target "cpprestsdk::cpprest" but the target
was not found. Perhaps a find_package() call is missing for and IMPORTED
target, or an ALIAS target is missing?
如何在这些限制范围内链接和使用C ++ REST SDK?