当前位置:首页 > 其他 > 正文内容

CMake构建学习笔记8-OpenSceneGraph库的构建

邻居的猫1个月前 (12-09)其他672

1. 概论

在接连构建了zlib、libpng、libjpeg、libtiff、giflib以及freetype这几个库之后,接下来咱们就要来一个大的,构建OpenSceneGraph这样大型库。OpenSceneGraph(简称 OSG)是一个高性能、跨渠道的三维图形使用程序结构,广泛使用于科学可视化、模仿仿真、游戏开发等范畴。理论上来说,上述几个库不是OSG的有必要依靠库,可是将它们作为依靠库构建,OSG的功用就更完好。

2. 构建进程

构建OSG库的要害指令如下所示:

# 装备CMake      
cmake .. -G "$Generator" -A x64 `
    -DCMAKE_BUILD_TYPE=RelWithDebInfo `
    -DCMAKE_PREFIX_PATH="$InstallDir" `
    -DCMAKE_INSTALL_PREFIX="$InstallDir" `
    -DGIFLIB_LIBRARY="$InstallDir/lib/giflib.lib" `
    -DBUILD_OSG_APPLICATIONS=ON `
    -DBUILD_OSG_EXAMPLES=OFF `
    -DBUILD_OSG_DEPRECATED_SERIALIZERS=OFF `
    -DCMAKE_RELWITHDEBINFO_POSTFIX=""

# 构建阶段,指定构建类型
cmake --build . --config RelWithDebInfo -- /m:8

# 装置阶段,指定构建类型和装置方针
cmake --build . --config RelWithDebInfo --target install

再次着重一遍,假如要优先找到提早编译好的依靠库,就需求设置CMAKE_PREFIX_PATH变量。咱们把一切的库都装置到同一个目录中并设置成CMAKE_PREFIX_PATH变量,这样在构建新的依靠库的时分,CMake就能精确查找到相关的依靠库。不过,也会呈现少量查找不到的状况,这儿的GIFLIB就没有查找到,因而咱们手动设置GIFLIB_LIBRARY。

其他的几个OSG供给的自定义构建选项中:

  1. BUILD_OSG_APPLICATIONS表明是否构建根据OSG的可执行程序,例如osgviewer、osgconv等。这样的使用东西仍是十分有用的,引荐仍是进行构建。
  2. BUILD_OSG_EXAMPLES表明是否构建示例程序,像这样的构建选项,为了加速构建速度一般不必进行构建。
  3. BUILD_OSG_DEPRECATED_SERIALIZERS看到这个DEPRECATED字眼就不必参加进行构建了,横竖也对错有必要项。
  4. CMAKE_RELWITHDEBINFO_POSTFIX表明是否给RelWithDebInfo方法编译的成果添加后缀,默许会添加后缀“rd”,这儿将其设置为空。

3. 经历总结

构建像OSG这样的大型程序库,最好多看看CMake装备完成后的输出信息,例如这儿的输出信息如下所示:

CMake Deprecation Warning at CMakeLists.txt:16 (CMAKE_MINIMUM_REQUIRED):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22631.
-- Could NOT find EGL (missing: EGL_LIBRARY EGL_INCLUDE_DIR) 
-- Checking windows version...
-- 64 bit architecture detected
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR) 
-- Could NOT find LibXml2 (missing: LIBXML2_INCLUDE_DIR) 
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (GTA).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindGTA.cmake:11 (INCLUDE)
  CMakeLists.txt:751 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (GTA).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindGTA.cmake:15 (INCLUDE)
  CMakeLists.txt:751 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Checking for module 'gta'
--   No package 'gta' found
-- Trying to find DCMTK expecting DCMTKConfig.cmake
-- Trying to find DCMTK expecting DCMTKConfig.cmake - failed
-- Trying to find DCMTK relying on FindDCMTK.cmake
-- Please set DCMTK_DIR and re-run configure (missing: DCMTK_config_INCLUDE_DIR DCMTK_dcmdata_INCLUDE_DIR DCMTK_dcmimage_INCLUDE_DIR DCMTK_dcmimgle_INCLUDE_DIR DCMTK_dcmjpeg_INCLUDE_DIR DCMTK_dcmjpls_INCLUDE_DIR DCMTK_dcmnet_INCLUDE_DIR DCMTK_dcmpstat_INCLUDE_DIR DCMTK_dcmqrdb_INCLUDE_DIR DCMTK_dcmsign_INCLUDE_DIR DCMTK_dcmsr_INCLUDE_DIR DCMTK_dcmtls_INCLUDE_DIR DCMTK_ofstd_INCLUDE_DIR DCMTK_oflog_INCLUDE_DIR)
-- Could NOT find GStreamer (missing: GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES GSTREAMER_APP_INCLUDE_DIRS GSTREAMER_APP_LIBRARIES GSTREAMER_PBUTILS_INCLUDE_DIRS GSTREAMER_PBUTILS_LIBRARIES)
-- Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR) 
-- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) 
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (Poppler-glib).  This can
  lead to problems in calling code that expects `find_package` result
  variables (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindPoppler-glib.cmake:2 (INCLUDE)
  CMakeLists.txt:761 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (Poppler-glib).  This can
  lead to problems in calling code that expects `find_package` result
  variables (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindPoppler-glib.cmake:6 (INCLUDE)
  CMakeLists.txt:761 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Checking for module 'cairo'
--   No package 'cairo' found
-- Checking for module 'poppler-glib'
--   No package 'poppler-glib' found
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (RSVG).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindRSVG.cmake:2 (INCLUDE)
  CMakeLists.txt:762 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (RSVG).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindRSVG.cmake:6 (INCLUDE)
  CMakeLists.txt:762 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Checking for module 'librsvg-2.0>=2.35'
--   No package 'librsvg-2.0' found
-- Checking for module 'cairo'
--   No package 'cairo' found
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (GtkGl).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindGtkGl.cmake:2 (INCLUDE)
  CMakeLists.txt:763 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (PkgConfig)
  does not match the name of the calling package (GtkGl).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args)
  CMakeModules/FindGtkGl.cmake:6 (INCLUDE)
  CMakeLists.txt:763 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Checking for module 'gtk+-2.0'
--   No package 'gtk+-2.0' found
-- Checking for module 'gtkglext-win32-1.0'
--   No package 'gtkglext-win32-1.0' found
-- Could NOT find Fontconfig (missing: FONTCONFIG_LIBRARY FONTCONFIG_INCLUDE_DIR) 
-- osgText will not be linked with FontConfig library
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.26/Modules/Documentation.cmake:30 (message):
  Policy CMP0106 is not set: The Documentation module is removed.  Run "cmake
  --help-policy CMP0106" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  Documentation.cmake is VTK-specific code and should not be used in non-VTK
  projects.  This logic in this module is best shipped with the project using
  it rather than with CMake.
Call Stack (most recent call first):
  CMakeLists.txt:1162 (INCLUDE)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The following OPTIONAL packages have been found:

 * OpenGL
 * Freetype
 * FBX
 * GDAL
 * CURL
 * GIFLIB
 * JPEG
 * ZLIB
 * PNG
 * TIFF
 * Threads

-- The following OPTIONAL packages have not been found:

 * EGL
 * ilmbase
 * Inventor
 * Jasper
 * OpenEXR
 * OpenCascade
 * LibXml2
 * COLLADA
 * GTA
 * LibVNCServer
 * DCMTK
 * FFmpeg
 * GStreamer
 * GLIB
 * DirectShow
 * SDL2
 * SDL
 * Poppler-glib
 * RSVG
 * RSVG
 * GtkGl
 * DirectInput
 * GtkGl
 * DirectInput
 * NVTT
 * NVTT
 * ZeroConf
 * LIBLAS
 * ZeroConf
 * LIBLAS
 * QuickTime
 * LIBLAS
 * QuickTime
 * QuickTime
 * Fontconfig

-- Configuring done (3.5s)
-- Generating done (15.6s)
-- Build files have been written to: C:/Github/BuildCppDependency/Windows/OpenSceneGraph-OpenSceneGraph-3.6.5/build

看起来十分的冗杂,可是其实没什么内容,只要是在说有的依靠库找不到,有的依靠库找到了。最终还把找到的依靠库和没找到的依靠库都列出来了。关于这一点,咱们只需求要点关怀咱们需求的依靠库是否辨认成功了即可,认为有的大型库的依靠项十分多,不太可能一次性就把完好的依靠项准备好。

除此之外,还能够看看程序库供给的自定义构建选项,暂时用不到的暂时设为OFF不进行构建了,例如一些测验程序或许事例程序。CMake供给的功用十分强壮,有的功用还会长途拉取代码,这个时分往往会由于国内网速的原因导致终端构建装备。不过,供给这种功用的模块往往对错有必要的构建选项,能够找一找将其取消掉,在从头进行构建。

总归,多看看的构建装备的输出信息和选项,游刃有余,有了经历今后就能又快又好地构建依靠库了。

扫描二维码推送至手机访问。

版权声明:本文由51Blog发布,如需转载请注明出处。

本文链接:https://www.51blog.vip/?id=686

分享给朋友:

“CMake构建学习笔记8-OpenSceneGraph库的构建” 的相关文章

新做了一个MySQL 数据库 DDL 差异比照的网站

新做了一个MySQL 数据库 DDL 差异比照的网站

MySQL 数据库 DDL 差异比照的网站 摘要 新做了个网站,用来比照不同环境下的 DDL 差异,生成改变点和 搬迁 DDL 网站地址:https://ddlcompare.com/ 比照过程中如果有问题,能够经过邮箱联络我 [email protected],下班后我会密布的修一波 b...

快速入眠:怎么取得一夜好眠0简介

快速入眠:怎么取得一夜好眠0简介

0 简介 睡觉是咱们每个人都会做的作业;事实上,咱们一生中大约有三分之一的时刻是在这种古怪的无意识状况中度过的。但是,直到最近,咱们对睡觉的作用、咱们需求多少睡觉以及梦在改进心理健康方面的作用依然知之甚少。 好消息是,在曩昔的 20 年里,咱们对睡觉以及睡觉的重要性的知道发生了革命性的改变。不久前,...

MacOS下用Homebrew装置yt-dlp并装备yt-dlp.conf

MacOS下用Homebrew装置yt-dlp并装备yt-dlp.conf

MacOS下用Homebrew装置yt-dlp视频下载器并装备.conf装备文件 装置yt-dlp brew install yt-dlp 检查是否装置成功 yt-dlp --version 2024.11.18 给yt-dlp增加装备文件 1、翻开访达文件夹,到~根目录下,通常是你的用户名文件...

区块链通俗易懂的解释,什么是区块链?

区块链通俗易懂的解释,什么是区块链?

区块链技术是一种分布式账本技术,它允许多个参与者在一个共享的数据库中记录交易和信息,而不需要一个中心化的权威机构来管理。区块链的特点是去中心化、不可篡改和可追溯性。简单来说,区块链就像一个公开的、不可篡改的账本,上面记录了所有的交易和信息。这些交易和信息被加密并链接在一起,形成一个链状结构,因此称为...

开源爬虫,助力数据获取与处理的利器

开源爬虫,助力数据获取与处理的利器

3. MechanicalSoup 特点:MechanicalSoup 是一个 Python 库,旨在模拟人类在使用浏览器时与网站的交互,基于 Python 的 Requests 和 BeautifulSoup 构建。 优点:适合模拟人类与网站的交互,支持 HTTP 会话和文档导航。...

区块链是什么时候出现的,区块链的起源与发展历程

区块链技术最早出现在2008年,由一位或多位化名为中本聪(Satoshi Nakamoto)的人或团队在发布的比特币白皮书中首次提出。2009年,比特币作为第一个基于区块链技术的应用正式上线运行。区块链是一种分布式数据库技术,它允许数字信息在多个节点之间安全地存储和共享,同时确保数据的一致性和不可篡...