Location>code7788 >text

CMake Build Study Notes 8 - Building the OpenSceneGraph Library

Popularity:755 ℃/2024-08-27 19:22:35

1. General remarks

After building zlib, libpng, libjpeg, libtiff, giflib, and freetype libraries, we're going to take the plunge and build OpenSceneGraph, a high-performance, cross-platform, three-dimensional graphic OSG is a high-performance, cross-platform 3D graphics application framework widely used in scientific visualization, simulation, game development and other fields. Theoretically, the above libraries are not mandatory dependencies for OSG, but by building them as dependencies, OSG is more complete.

2. The construction process

The key instructions for building the OSG library are shown below:

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

# Build phase, specify build type
cmake ---build . --config RelWithDebInfo -- /m:8

# Installation phase, specifying the build type and installation target
cmake ---build . --config RelWithDebInfo ---target install

Again, the CMAKE_PREFIX_PATH variable needs to be set if you want to prioritize finding pre-compiled dependency libraries. By installing all the libraries in the same directory and setting the CMAKE_PREFIX_PATH variable, CMake will be able to find the relevant dependencies when building new ones. However, there are a few cases where it doesn't find them, in this case GIFLIB, so we set GIFLIB_LIBRARY manually.

Of the few remaining custom build options OSG offers:

  1. BUILD_OSG_APPLICATIONS indicates whether or not to build OSG-based executable programs, such as osgviewer, osgconv, and so on. Such application tools are still very useful and it is recommended to still build them.
  2. BUILD_OSG_EXAMPLES indicates whether or not to build the sample program. Build options such as these are generally not used to speed up the build.
  3. BUILD_OSG_DEPRECATED_SERIALIZERS Seeing this DEPRECATED word doesn't need to be involved in doing the build, it's a non-required item anyway.
  4. CMAKE_RELWITHDEBINFO_POSTFIX indicates whether or not to add suffix to the result of RelWithDebInfo compilation, the default will add the suffix "rd", here set it to null.

3. Lessons learned

To build large libraries like OSG, it's a good idea to take a closer look at the output of CMake after it's been configured, for example, the output here is shown below:

CMake Deprecation Warning at :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/: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
  (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:11 (INCLUDE)
  :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/: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
  (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:15 (INCLUDE)
  :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 
-- Trying to find DCMTK expecting  - failed
-- Trying to find DCMTK relying on 
-- 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/: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 (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:2 (INCLUDE)
  :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/: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 (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:6 (INCLUDE)
  :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/: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
  (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:2 (INCLUDE)
  :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/: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
  (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:6 (INCLUDE)
  :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/: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
  (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:2 (INCLUDE)
  :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/: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
  (., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/:99 (find_package_handle_standard_args)
  CMakeModules/:6 (INCLUDE)
  :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/: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.

   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):
  :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

It looks like a lot of work, but there's really not much to it, as long as it's saying that some dependencies couldn't be found and some were found. At the end, it also lists the dependencies that were found and the ones that were not found. At this point, we only need to focus on whether the dependencies we need are successfully identified, thinking that some large libraries have so many dependencies that it is unlikely that the complete set of dependencies will be ready at once.

In addition, you can also look at the custom build options provided by the library, temporarily not used temporarily set to OFF do not build, such as some of the test program or case program.CMake provides a very powerful features, some features will also be remotely pulling the code, often because of the domestic network speed causes the terminal to build the configuration. However, the module that provides this feature is often a non-essential build option, you can look for it to cancel it, in the re-construction.

In short, take a look at the output and options of the build configuration, practice makes perfect, and with experience you will be able to build dependencies quickly and well.