我试图将这个C++ https://github.com/sikang/DecompUtil包包含到我的项目中,但我不确定如何在我的CMakelists.txt中实现它。我不断地遇到这个错误:
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "FindDecompUtil.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"DecompUtil", but CMake did not find one.
Could not find a package configuration file provided by "DecompUtil" with
any of the following names:
DecompUtilConfig.cmake
decomputil-config.cmake
Add the installation prefix of "DecompUtil" to CMAKE_PREFIX_PATH or set
"DecompUtil_DIR" to a directory containing one of the above files. If
"DecompUtil" provides a separate development package or SDK, be sure it has
been installed.
复制问题的步骤:
git clone https://github.com/sikang/DecompUtil
到项目目录cd DecompUtil
mkdir build && cd build && cmake .. && make
构建包(成功)cd project_root
mkdir build && cd build
cmake ..
(错误在此)
这里是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(test)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/DecompUtil)
add_subdirectory(DecompUtil)
find_package(DecompUtil REQUIRED)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
${DECOMP_UTIL_INCLUDE_DIRS})
add_executable(test src/test.cpp)
target_link_libraries(test DecompUtil)
install(TARGETS
test
DESTINATION lib/${PROJECT_NAME})
我的项目结构是这样的
内部test.cpp
#include <iostream>
#include <decomp_geometry/polyhedron.h>
int main(){
Polyhedron<3> poly3DViz;
std::cout << "Hello world" << std::endl;
}
1条答案
按热度按时间hec6srdp1#
错误消息非常清楚:
decomp_utilConfig.cmake位于该repo的根。
例如.(因为您将DecompUtil/目录放在项目的root / source目录下)
或
decomp_utilConfig.cmake没有定义一个名为
DecompUtil
的目标,并且您已经使用DECOMP_UTIL_INCLUDE_DIRS
添加了include目录,所以我很确定您的target_link_libraries(test DecompUtil)
是错误的,应该被删除。此外,几乎没有理由将
add_subdirectory
和find_package
混合用于一个东西。您的add_subdirectory(DecompUtil)
应该被删除。