CMake构建学习笔记8-OpenSceneGraph库的构建
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提供的自定义构建选项中:
- BUILD_OSG_APPLICATIONS表示是否构建基于OSG的可执行程序,例如osgviewer、osgconv等。这样的应用工具还是非常实用的,推荐还是进行构建。
- BUILD_OSG_EXAMPLES表示是否构建示例程序,像这样的构建选项,为了加快构建速度一般不用进行构建。
- BUILD_OSG_DEPRECATED_SERIALIZERS看到这个DEPRECATED字眼就不用参与进行构建了,反正也是非必须项。
- 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提供的功能非常强大,有的功能还会远程拉取代码,这个时候往往会因为国内网速的原因导致终端构建配置。不过,提供这种功能的模块往往是非必须的构建选项,可以找一找将其取消掉,在重新进行构建。
总之,多看看的构建配置的输出信息和选项,熟能生巧,有了经验以后就能又快又好地构建依赖库了。
CMake构建学习笔记8-OpenSceneGraph库的构建的更多相关文章
- 【学习笔记】开源库之 - sigslot (在解决浅拷贝问题的基础上增加信号拦截功能)
前言说明 在文中<[学习笔记]开源库之 - sigslot (提供该库存在对象拷贝崩溃问题的解决方案)>已经介绍过 sigslot ,此文主要应用在实际的工作项目中时,发现会有拦截信号的需 ...
- iOS学习笔记16-数据库SQLite
一.数据库 在项目开发中,通常都需要对数据进行离线缓存的处理,如新闻数据的离线缓存等.离线缓存一般都是把数据保存到项目的沙盒中.有以下几种方式: 归档:NSKeyedArchiver 偏好设置:NSU ...
- SpringCloud学习笔记(6):使用Zuul构建服务网关
简介 Zuul是Netflix提供的一个开源的API网关服务器,SpringCloud对Zuul进行了整合和增强.服务网关Zuul聚合了所有微服务接口,并统一对外暴露,外部客户端只需与服务网关交互即可 ...
- Java学习笔记之使用反射+泛型构建通用DAO
PS:最近简单的学了学后台Servlet+JSP.也就只能学到这里了.没那么多精力去学SSH了,毕竟Android还有很多东西都没学完.. 学习内容: 1.如何使用反射+泛型构建通用DAO. 1.使用 ...
- CMake学习笔记五-依赖库添加
# # 项目名称 # SET(WIS_PROJECT_NAME EXAMPLE) # dependencies SET(DEPENDENCIES #依赖第三方库 ) #Qt模块 SET(QT_MODU ...
- 《Spring实战》学习笔记-第五章:构建Spring web应用
之前一直在看<Spring实战>第三版,看到第五章时发现很多东西已经过时被废弃了,于是现在开始读<Spring实战>第四版了,章节安排与之前不同了,里面应用的应该是最新的技术. ...
- [No000094]SVN学习笔记4-版本库概念与部分日常操作
基本概念 版本库 Subversion 使用集中的数据库,它包含了所有的版本控制文件及其完整历史.这个数据库就是版本库.版本库通常位于运行 Subversion 服务器的文件服务器上,向 Subver ...
- 重温JSP学习笔记--JSTL标签库
以前写jsp的时候对jstl标签库是有些抵触的,因为我觉得嵌入java代码的方式几乎无往不利,没有必要使用标签库,不过这次复习还是好好地学习了一下,发现这个还是很有用处的,用得好能省不少事,JSTL是 ...
- OpenGL学习笔记0——安装库
最近需要做一个基于Zigbee室内无线定位的系统,受到TI公司ZigBee Sensor Monitor软件的启发,打算用OpenGL来做一个3D显示空间内物体位置的程序.学习阶段选择VS2010+O ...
- 学习笔记_Java_day13_JSTL标签库(1、2、3、4、5、6、7、8)
1.一种标签语言 day13 l JSTL标签库(重点) l 自定义标签(理解) l MVC设计模式(重点中的重点) l Java三层框架(重点中的重点) JSTL标签库 1 什么是JSTL ...
随机推荐
- 全志T113-i+玄铁HiFi4开发板硬件说明书(2)
前 言 本文档主要介绍开发板硬件接口资源以及设计注意事项等内容,测试板卡为全志T113-i+玄铁HiFi4开发板,由于篇幅问题,本篇文章共分为上下两集,点击账户可查看更多内容详情,开发问题欢迎留言,感 ...
- [golang]在Gin框架中使用JWT鉴权
什么是JWT JWT,全称 JSON Web Token,是一种开放标准(RFC 7519),用于安全地在双方之间传递信息.尤其适用于身份验证和授权场景.JWT 的设计允许信息在各方之间安全地. co ...
- Linux系统用户组管理
用户管理 和Windows一样在Linux中也存在许多用户,可以登陆Linux,和Windows不同的是,在Windows中同一时刻只可以存在一个用户登录系统,而在Linux中是允许多个用户同时登 ...
- P7086 题解
考虑把每个字符串的前 \(k\) 位和后 \(k\) 位看成点,字符串看成边,那么一个字符串前缀后缀至少有一个是相似群体的前缀后缀,看成这条边的两个端点至少有一个被选中. 那么这就变成了一个最小点覆盖 ...
- ubuntu22 装物理机
前言 最近需要使用u盘装一个ubuntu物理机,原本想试试麒麟,但还需要申请.. 自己捣鼓半天,终于把ubuntu系统装上了,现在记录一下过程. 正文 下载镜像文件 从官网下载 ubuntu22 的镜 ...
- Java反射机制原理详解
什么是反射? Java反射机制的核心是在程序运行时动态加载类并获取类的详细信息,从而操作类或对象的属性和方法.本质是JVM得到class对象之后,再通过class对象进行反编译,从而获取对象的各种信息 ...
- API引用在Element UI (Vue 2)和Element Plus (Vue 3)中的不同
API 变动 样式类名变化: 一些组件的样式类名有所变动,可能需要更新你的自定义样式. 事件名和属性名变化: 某些组件的事件名和属性名发生了变化,需要检查 Element Plus 文档 以了解详细信 ...
- yearrecord——一个类似痕迹墙的React数据展示组件
介绍一下自己做的一个类似于力扣个人主页提交记录和GitHub主页贡献记录的React组件. 下图分别是力扣个人主页提交记录和GitHub个人主页的贡献记录,像这样类似痕迹墙的形式可以比较直观且高效得展 ...
- Profinet转Modbus模块减轻通讯编程工作量实现Modbus通讯
巴图自动化PN转Modbus模块(BT-MDPN10)能够实现Profinet协议与Modbus协议之间的转换,使得Profinet协议设备与Modbus协议设备进行连接并能够相互通信. 通过使用巴图 ...
- pytest + allure2.x 踩坑-报告无数据
我按照网上的教程,在用pytest生成完allure可以使用的json数据之后,然后再用allure生成报告,打开,发现我生成的报告中没有数据显示. 1.首先我用pytest生成数据是没有问题的 2. ...