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供给的功用十分强壮,有的功用还会长途拉取代码,这个时分往往会由于国内网速的原因导致终端构建装备。不过,供给这种功用的模块往往对错有必要的构建选项,能够找一找将其取消掉,在从头进行构建。
总归,多看看的构建装备的输出信息和选项,游刃有余,有了经历今后就能又快又好地构建依靠库了。