5

我正在尝试使用OpenKinect项目编写一些程序。我想将 OpenKinect 的主分支作为子目录添加到我的项目源中。但是,如果你查看 OpenKinect 自己的 CMake,那里的东西太多了,我不需要所有东西。那里有某些选项,它们被设置为 ON 或 OFF,如下所示:

OPTION(BUILD_AUDIO "Build audio support" OFF)
OPTION(BUILD_REDIST_PACKAGE "Build libfreenect in a legally-redistributable manner (only affects audio)" OFF)
OPTION(BUILD_EXAMPLES "Build example programs" ON)
OPTION(BUILD_FAKENECT "Build fakenect mock library" ON)
OPTION(BUILD_C_SYNC "Build c synchronous library" ON)
OPTION(BUILD_CPP "Build C++ Library (currently header only)" ON)
OPTION(BUILD_CV "Build OpenCV wrapper" ON)
OPTION(BUILD_AS3_SERVER "Build the Actionscript 3 Server Example" OFF)
OPTION(BUILD_PYTHON "Build Python extension" ON)
IF(PROJECT_OS_LINUX)
    OPTION(BUILD_CPACK "Build an RPM or DEB using CPack" ON)
ENDIF(PROJECT_OS_LINUX)

在不对 OpenKinect 文件进行任何重大更改的情况下(以便我可以在git pull需要时随时更改),我如何仅将某些部分(例如C++ wrapperOpenCV bindings)导入到我自己的 CMake 项目中?如果我完全重写 CMake 文件,我想复制某些不依赖于其他目录的目录。我将无法再使用 git,但这将是一个快速修复。但是我遇到了奇怪的错误,比如“stdexcept 没有在这个范围内声明”,这是没有意义的,因为它是一个标准的 gc++ 库。

4

1 回答 1

6

If you simply want to enable/disable some parts of that library, you can simply set the appropriate options before calling ADD_SUBDIRECTORY.

Simply use the same OPTION commands as in the library's CMakeLists.txt but set them ON/OFF as you need. Of course, oyu are free to change/choose the describing string as you like.

Alternatively (and if options have a different value than true/false), you can use the SET(.... CACHE ... )

e.g.

SET(BUILD_CPP TRUE CACHE BOOL "Build C++ Library (currently header only)")

Similar question: Override option in CMake subproject

于 2013-01-14T08:59:14.070 回答