I am trying to create a CMAKE project that includes other third party projects (OGRE3D, CEGUI, etc) and my specific project (or projects). More specifically, I have a directory tree like this:
+ myMasterProject
-----+ OGRE3D_DEPENDENCIES
-----+ OGRE3D_CORE
-----+ CEGUI
-----+ myProject
If I build the libraries manually one by one in the right order everything works fine (even myProject). Every project has its own CMakeLists.txt file, and they almost all use the find_package
function. For example, CEGUI needs to find OGRE for the OGRE renderer and returns an error if does not find it with find_package(OGRE REQUIRED)
. myProject
needs both OGRE and CEGUI.
An important detail is that I would not modify the CMakeLists.txt
files of the subprojects, as I import them as sub-projects using mercurial or svn (depends on their respective CVS), and I prefer to update them regularly, without modifications (I'm not expert enough to modify them).
Does anyone have an idea on how to get to this result? shall I define all the variables like "OGRE_FOUND", "Boost_FOUND", and their respective sub-variables ("OGRE_LIB", "OGRE_H_PATH" etc) manually in my masterProject/CMakeLists.txt
file or is there a "smarter" or "cleaner" way to do it? In any case, these variables have to be defined somehow, because they are needed by the projects...
For the moment, myMasterProject/CMakeLists.txt
contains only:
project(myMasterProject)
add_subdirectory("OGRE3D_DEPENDENCIES")
add_subdirectory("OGRE3D_CORE")
add_subdirectory("CEGUI")
add_subdirectory("myProject")
Here is the CMAKE output that I get:
-- Configuring OGRE 1.8.2
-- Detected g++ 4.6.1
-- Enabling GCC visibility flags
-- Search path: /home/me/myMasterProject/build/OGRE3D_CORE/Dependencies;/home/me/myMasterProject/sources/OGRE3D_CORE/Dependencies;/home/me/myMasterProject/build/OGRE3D_CORE/../Dependencies;/home/me/myMasterProject/sources/OGRE3D_CORE/../Dependencies
-- Looking for ZLIB...
-- Found ZLIB: optimized;zlib;debug;zlib
-- Looking for ZZip...
-- Found ZZip: optimized;zziplib;debug;zziplib
-- Looking for FreeImage...
-- checking for module 'freeimage'
-- package 'freeimage' not found
-- Found FreeImage: optimized;FreeImage;debug;FreeImage
-- Looking for FREETYPE...
-- CMAKE_PREFIX_PATH: /home/me/myMasterProject/build/OGRE3D_CORE/Dependencies;/home/me/myMasterProject/sources/OGRE3D_CORE/Dependencies;/home/me/myMasterProject/build/OGRE3D_CORE/../Dependencies;/home/me/myMasterProject/sources/OGRE3D_CORE/../Dependencies;/usr/local;/usr/lib/x86_64-linux-gnu
-- CMAKE_PREFIX_PATH: /home/me/myMasterProject/build/OGRE3D_CORE/Dependencies;/home/me/myMasterProject/sources/OGRE3D_CORE/Dependencies;/home/me/myMasterProject/build/OGRE3D_CORE/../Dependencies;/home/me/myMasterProject/sources/OGRE3D_CORE/../Dependencies;/usr/local;/usr/lib/x86_64-linux-gnu
-- Found FREETYPE: optimized;freetype;debug;freetype
-- Looking for Cg...
-- checking for module 'Cg'
-- package 'Cg' not found
-- Found Cg: optimized;/usr/lib/libCg.so;debug;/usr/lib/libCg.so
-- Looking for POCO...
-- checking for module 'POCO'
-- package 'POCO' not found
-- Could not locate POCO
-- Looking for TBB...
-- Could not locate TBB
-- Looking for GLSL_Optimizer...
-- checking for module 'GLSL_Optimizer'
-- package 'GLSL_Optimizer' not found
-- Could not locate GLSL_Optimizer
-- Looking for HLSL2GLSL...
-- checking for module 'HLSL2GLSL'
-- package 'HLSL2GLSL' not found
-- Could not locate HLSL2GLSL
-- Looking for OIS...
-- Found OIS: optimized;OIS;debug;OIS
-- Looking for Softimage...
-- Could not locate Softimage
-- Looking for CppUnit...
-- Found CppUnit: optimized;/usr/lib/libcppunit.so;debug;/usr/lib/libcppunit.so
--
-----------------------------------------------------------------------------
-- The following external packages were located on your system.
-- This installation will have the extra features provided by these packages.
+ zlib
+ zziplib
+ freeimage
+ freetype
+ X11
+ Xt
+ Xaw
+ OpenGL
+ OpenGL ES 2.x
+ cg
+ boost
+ boost-thread
+ boost-date_time
+ OIS
+ Doxygen
+ CppUnit
-----------------------------------------------------------------------------
-- The following OPTIONAL packages could NOT be located on your system.
-- Consider installing them to enable more features from this software.
+ OpenGL ES 1.x: Support for the OpenGL ES 1.x render system (DEPRECATED) <http://www.khronos.org/opengles/>
+ POCO: POCO framework <http://pocoproject.org/>
+ tbb: Threading Building Blocks <http://www.threadingbuildingblocks.org/>
+ GLSL Optimizer: GLSL Optimizer <http://github.com/aras-p/glsl-optimizer/>
+ HLSL2GLSL: HLSL2GLSL <http://hlsl2glslfork.googlecode.com/>
+ Softimage: Softimage SDK needed for building XSIExporter <FALSE>
-----------------------------------------------------------------------------
--
----------------------------------------------------------------------------
FEATURE SUMMARY
----------------------------------------------------------------------------
Building components:
+ Paging
+ Property
+ Terrain
+ RTShader System
+ RTShader System Core Shaders
+ RTShader System Extensions Shaders
Building plugins:
+ BSP scene manager
+ Cg program manager
+ Octree scene manager
+ Portal connected zone scene manager
+ Particle FX
Building rendersystems:
+ OpenGL
Building executables:
+ Samples
+ Tools
Building core features:
+ DDS image codec
+ FreeImage codec
+ ZIP archives
Build type: dynamic
Threading support: background (boost)
Use double precision: disabled
Allocator type: nedmalloc (pooling)
STL containers use allocator: enabled
Strings use allocator: disabled
Memory tracker (debug): disabled
Memory tracker (release): disabled
Use new script compilers: enabled
Use Boost: enabled
----------------------------------------------------------------------------
OGRE_LIB = OGRE_LIB-NOTFOUND
OGRE_H_PATH = OGRE_H_PATH-NOTFOUND
OGRE_H_BUILD_SETTINGS_PATH = OGRE_H_BUILD_SETTINGS_PATH-NOTFOUND
CMAKE_MODULE_PATH = /home/me/myMasterProject/sources/CEGUI/cmake
-- Could NOT find PCRE (missing: PCRE_LIB PCRE_H_PATH)
-- Could NOT find MINIZIP (missing: MINIZIP_LIB MINIZIP_H_PATH)
-- Could NOT find GLFW (missing: GLFW_LIB GLFW_H_PATH)
-- Could NOT find DIRECTXSDK (missing: DIRECTXSDK_LIB_PATH DIRECTXSDK_H_PATH DIRECTXSDK_MAX_D3D)
-- Could NOT find D3DX11EFFECTS (missing: D3DX11EFFECTS_LIB D3DX11EFFECTS_H_PATH)
-- Could NOT find IRRLICHT (missing: IRRLICHT_LIB IRRLICHT_H_PATH)
-- Could NOT find OGRE (missing: OGRE_LIB OGRE_H_PATH OGRE_H_BUILD_SETTINGS_PATH)
-- Could NOT find DIRECTFB (missing: DIRECTFB_LIB DIRECTFB_H_PATH)
-- Could NOT find OPENGLES (missing: OPENGLES_LIB OPENGLES_H_PATH)
-- Could NOT find XERCESC (missing: XERCESC_LIB XERCESC_H_PATH)
-- Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
-- Could NOT find TINYXML (missing: TINYXML_LIB TINYXML_H_PATH)
-- Could NOT find RAPIDXML (missing: RAPIDXML_H_PATH)
-- Could NOT find IL (missing: IL_LIB IL_H_PATH)
-- Could NOT find ILU (missing: ILU_LIB)
-- Could NOT find SILLY (missing: SILLY_LIB SILLY_H_PATH)
-- Could NOT find CORONA (missing: CORONA_LIB CORONA_H_PATH)
-- Could NOT find PVRTOOLS (missing: PVRTOOLS_LIB PVRTOOLS_H_PATH)
-- Could NOT find LUA51 (missing: LUA_LIB LUA_H_PATH)
-- Could NOT find TOLUAPP (missing: TOLUAPP_LIB TOLUAPP_H_PATH)
-- Could NOT find Boost
CMake Error at /usr/share/cmake-2.8/Modules/CPack.cmake:338 (message):
CPack package description file:
"/home/me/myMasterProject/sources/doc/README" could not be
found.
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/CPack.cmake:342 (cpack_check_file_exists)
CEGUI/CMakeLists.txt:574 (include)
CMake Error at /usr/share/cmake-2.8/Modules/CPack.cmake:338 (message):
CPack license resource file:
"/home/me/myMasterProject/sources/doc/COPYING" could not be
found.
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/CPack.cmake:343 (cpack_check_file_exists)
CEGUI/CMakeLists.txt:574 (include)
CMAKE_MODULE_PATH =/home/me/myMasterProject/sources/myProject/cmake
CEGUI LIBRARY:
CEGUI OGRE LIBRARY:
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 2.8)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
As you can notice, when building OGRE everything seems to work well, but after, when CEGUI is building it does not recognize OGRE and related variables. Idem for myProject...
Thanks in advance for your answers, Cheers
DISCLAIMER: I am almost a newbie with CMAKE... Moreover, I know that similar questions have been already posted here, but I didn't find an answer that works...
Setting the variables for the find script yourself in the master project is a valid approach. It is a bit fragile in the sense that you rely on the respective projects not changing their find scripts, but otherwise this seems perfectly fine.
An alternative could be using CMake's ExternalProject functionality. With this approach, instead of building all dependencies from your master project, they get built during CMake configure time. The advantage here is that dependencies are built as if you would build them directly from the command line, so the effects described in your question are avoided. It also does not depend on any of the dependency's build system internals.