我正在使用OpenCV和Dlib的项目,我希望该项目是跨平台和自包含的。所以我可以只将项目Dir复制到另一个平台,并通过ruing cmake获得exe。
DIR:
project/
opencv-3.2.0
|
dlib-19.2
|
include
|
source
“opencv-3.2.0”和“dlib-19.2”包含从官方网站下载的库的相应源代码。 “include”和“source”分别包含我的.h和.cpp。
这是我迄今为止提出的CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(visionBean)
set (OPENCV_VERSION_DIR_NAME ${PROJECT_SOURCE_DIR}/opencv-3.2.0)
set (DLIB_VERSION_DIR_NAME ${PROJECT_SOURCE_DIR}/dlib-19.2)
#setup opencv
add_subdirectory(${OPENCV_VERSION_DIR_NAME})
include_directories( ${OpenCV_INCLUDE_DIRS} )
#setup dlib
add_subdirectory(${DLIB_VERSION_DIR_NAME})
include_directories( ${DLIB_INCLUDE_DIRS} )
#files for main project
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/source)
file(GLOB ${PROJECT_NAME}_INC "${PROJECT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE ${PROJECT_NAME}_SRC "${PROJECT_SOURCE_DIR}/source/*.cpp")
add_executable(${PROJECT_NAME} source/demo.cpp)
target_link_libraries(${PROJECT_NAME}_LINKER ${OpenCV_LIBS} ${DLIB_LIBS})
如果某人已经这样做了,你能告诉我如何做到这一点或者指出我正确的方向吗?谢谢
修改 我遇到的Fist camke错误是:
CMake错误:CMake无法确定目标的链接器语言:opencv_xxx
答案 0 :(得分:1)
我认为这不会奏效。您正在将一个完整的项目添加为子目录。
opencv本身就是一个CMake项目,因为它的顶级CMakeList.txt有一个project
命令,它不仅仅是一个子目录。
你可以修改opencv CMakeLists.txt,把它变成一个单纯的子目录,但我不建议这样做,只需编写一个脚本(* .sh for linux和* .bat for windows)为每个项目调用cmake