Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include existing CMake git repo as submodule in my own CMake project?

I am trying to write some program using the OpenKinect project. I want to add the OpenKinect's master branch as a subdirectory to my project's source. But, if you look into the OpenKinect's own CMake, there is too much stuff there, and I do not need everything. There are certain options there, which are being set to ON or OFF, like this:

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)

Without making any major changes to the OpenKinect files (so that I can git pull any time I need to), how do I import only some parts (e.g., the C++ wrapper and the OpenCV bindings) to my own CMake project? I thought of copying certain directories, which are not dependent on the other directories, if I completely re-write the CMake files. I would not be able to use the git any more, but it would be a quick fix. But I am getting strange errors that way, such as "stdexcept was not not declared in this scope", which makes no sense, because it is a standard gc++ library.

like image 311
Subhamoy S. Avatar asked Jan 13 '13 21:01

Subhamoy S.


1 Answers

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

like image 59
Johannes S. Avatar answered Oct 17 '22 09:10

Johannes S.