2

我正在尝试创建一个包含其他第三方项目(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),并且我更喜欢定期更新它们,而不需要修改(我不是足以修改它们的专家)。

有谁知道如何得到这个结果?我应该在我的文件中手动定义所有变量,如“OGRE_FOUND”、“Boost_FOUND”和它们各自的子变量(“OGRE_LIB”、“OGRE_H_PATH”等),masterProject/CMakeLists.txt还是有一种“更智能”或“更清洁”的方法来做到这一点? 无论如何,必须以某种方式定义这些变量,因为项目需要它们......

目前,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 和相关变量。我的项目的同上...

提前感谢您的回答,干杯

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

4

1 回答 1

2

在主项目中自己设置查找脚本的变量是一种有效的方法。从某种意义上说,您依赖各个项目而不更改其查找脚本,这有点脆弱,但除此之外这似乎很好。

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.

于 2014-01-17T09:54:15.263 回答