当<package>作为同一主项目的“add_subdirectory”包含时,如何避免CMAKE错误“无法找到<package>”</package> </package>

时间:2014-01-15 15:25:18

标签: cmake ogre3d subproject cegui

我正在尝试创建一个包含其他第三方项目(OGRE3D,CEGUI等)和我的特定项目(或项目)的CMAKE项目。更具体地说,我有一个像这样的目录树:

+ myMasterProject
-----+ OGRE3D_DEPENDENCIES
-----+ OGRE3D_CORE
-----+ CEGUI
-----+ myProject

如果我按正确的顺序逐个手动构建库,一切正常(甚至是myProject)。每个项目都有自己的CMakeLists.txt文件,它们几乎都使用find_package函数。例如,CEGUI需要为OGRE渲染器找到OGRE,如果找不到find_package(OGRE REQUIRED),则返回错误。 myProject需要OGRE和CEGUI。

一个重要的细节是,我修改子项目的CMakeLists.txt文件,因为我使用mercurial或svn将它们作为子项目导入(取决于它们各自的CVS),而且我更喜欢定期更新它们而不做任何修改(我不够专家来修改它们)。

有没有人知道如何获得这个结果?我应该在我的masterProject/CMakeLists.txt文件中手动定义所有变量,如“OGRE_FOUND”,“Boost_FOUND”及其各自的子变量(“OGRE_LIB”,“OGRE_H_PATH”等)或在那里这是一种“更聪明”或“更清洁”的方式吗?无论如何,必须以某种方式定义这些变量,因为项目需要它们......

目前,myMasterProject/CMakeLists.txt仅包含:

project(myMasterProject)
add_subdirectory("OGRE3D_DEPENDENCIES")
add_subdirectory("OGRE3D_CORE")
add_subdirectory("CEGUI")
add_subdirectory("myProject")

这是我得到的CMAKE输出:

-- 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!

正如您所注意到的,在构建OGRE时,一切似乎都运行良好,但在CEGUI构建之后,它无法识别OGRE和相关变量。同意myProject ...

提前感谢您的回答, 干杯

免责声明:我几乎是CMAKE的新手...而且,我知道类似的问题已经发布在这里,但我找不到有效的答案......

1 个答案:

答案 0 :(得分:2)

在主项目中自己设置查找脚本的变量是一种有效的方法。它在某种意义上有点脆弱,你依赖于不改变其查找脚本的相应项目,但除此之外,这似乎完全正常。

替代方案可能是使用CMake的ExternalProject功能。使用这种方法,不是从主项目构建所有依赖项,而是在CMake配置时间内构建它们。这里的优点是构建依赖项就好像您可以直接从命令行构建它们一样,因此可以避免问题中描述的效果。它也不依赖于依赖的任何构建系统内部。