首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

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

编程知识
2024年08月27日 18:25

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提供的功能非常强大,有的功能还会远程拉取代码,这个时候往往会因为国内网速的原因导致终端构建配置。不过,提供这种功能的模块往往是非必须的构建选项,可以找一找将其取消掉,在重新进行构建。

总之,多看看的构建配置的输出信息和选项,熟能生巧,有了经验以后就能又快又好地构建依赖库了。

From:https://www.cnblogs.com/charlee44/p/18383356
本文地址: http://www.shuzixingkong.net/article/1496
0评论
提交 加载更多评论
其他文章 Win11如何找回熟悉的开始菜单、任务栏和右键菜单
背景 公司政策满3年可以换新电脑,前段时间申请了下,到手后发现是Win11系统,配置翻倍,欣然接受,把一些常用的软件都安装上,但是,用了一段时间后,发现右键刷新要点击2次,开始菜单找东西也完全靠搜索,任务栏不可定义了,和以前常用的右下角日历小工具不兼容,如果要和这些用惯好多年的操作say goodb
Win11如何找回熟悉的开始菜单、任务栏和右键菜单 Win11如何找回熟悉的开始菜单、任务栏和右键菜单 Win11如何找回熟悉的开始菜单、任务栏和右键菜单
CANopen学习笔记(二)通讯对象PDO和SDO等
通讯对象 PDO 我的观点:一个 CANopen 设备可以拥有最多 512 个 RPDO 和 512 个 TPDO,总共最多 1024 个 PDO。(得到GPT4o的肯定) CiA协议栈观点:一个只有一个逻辑设备的 CANopen 设备最多有 512 个 PDO。 PDO的两种用法: TPDO:生产
CANopen学习笔记(二)通讯对象PDO和SDO等 CANopen学习笔记(二)通讯对象PDO和SDO等 CANopen学习笔记(二)通讯对象PDO和SDO等
Modbus ASCII 获取数据
根据银河高低温试验箱协议读取数据 1.协议内容 8.1:通讯协议介绍 8.1.5 通讯设置 本通讯协议使用异步串行通讯方式,1 个起始位、8 个数据位、2 个停止 位、无奇偶校验数据通讯格式,其中数据位8 位,第1 位为最高位(MSB),第8 位为最低位(LSB)。 8.1.6 数据格式 通讯采用直
Modbus ASCII 获取数据 Modbus ASCII 获取数据
压缩流使用
压缩流 场景:需要将一些数据,以及这些数据关联的附件压缩下载,数据导出为一个Excel,附件导出到一个文件夹中 这里使用easyexcel 导出excel 从华为云 obs 下载附件 并交给浏览器 public void downloadAllEliminate(HttpServletRespons
压缩流使用
扫描线
引入 扫描线一般运用在图形上面,它和它的字面意思十分相似,就是一条线在整个图上扫来扫去,它一般被用来解决图形面积,周长,以及二维数点等问题。 Atlantis 问题 题意 在二维坐标系上,给出多个矩形的左下以及右上坐标,求出所有矩形构成的图形的面积。 解法 根据图片可知总面积可以直接暴力即可求出面积
扫描线
windows权限维持汇总
Windows 权限维持 一、文件层面 1)attrib 使用 Attrib +s +a +h +r 命令 s:设置系统属性(System) a:设置存档属性(Archive) h:设置隐藏属性(Hidden) r:设置只读属性(Read-only) attrib +s +a +h +r c:\te
windows权限维持汇总 windows权限维持汇总 windows权限维持汇总
k8s网络原理之Calico
之前整理总结过有关flannel的相关原理以及详细的传输过程,一直都想总结一篇通俗易懂的有关calico的相关原理和传输过程的,因为平常事情较多,没想到一拖就是这么久,这回借着复习的机会,将calico的原理,传输过程,以及各组件的作用还有两种模式的对比进行了细致的讲解和分析对比,也是对自己之前学习
k8s网络原理之Calico k8s网络原理之Calico k8s网络原理之Calico
生产者消费者模式,以及基于BlockingQueue的快速实现
生产者消费者模式,以及基于BlockingQueue的快速实现什么是生产者消费者模式,简单来说就是有两个角色,一个角色主要负责生产数据,一个角色主要负责消费(使用)数据。那么生产者直接依赖消费者,然后直接调用是否可以?答案是可以的,但是有些场景无法及时解决,典型的就是生产者消费者的速度无法同步,导致
生产者消费者模式,以及基于BlockingQueue的快速实现 生产者消费者模式,以及基于BlockingQueue的快速实现 生产者消费者模式,以及基于BlockingQueue的快速实现