Skip to content
Stephen Orso edited this page May 2, 2018 · 8 revisions

WikiCMake Build LogicCMake Scripts

CMakeLists.txt files in the Hyperion source directory and the subdirectories crypto and decNumber.

CMakeLists.txt in the Source Directory

The following is done:

  • Verifies the installed versions of CMake and git.
  • Checks for an in-source build, or an attempt to use a source directory that was contaminated by a previous in-source build. Terminates if either are detected.
  • Sets Position Independent Code for all compiles.
  • Determines the build type, and whether the selected generator is a multi-configuration generator. Multi-configuration generators support multiple build types at configuration time, and a configuration type must be selected when building or running ctest.
  • (Windows only) Determines whether a 32-bit or 64-bit Hercules will be built. If building a 32-bit Hercules on a 64-bit system and using the default installation prefix, append "(x86)" to the installation prefix root.
  • Defines the installation target directories appropriate to the target system. Windows uses a different structure than UNIX-like systems or macOS.
  • Includes CMake functions, both CMake-provided and CMake/Herc00_Includes.cmake, needed for the rest of the configuration.
  • Calls the following sub-scripts to perform each of the steps in the configuration of Hercules. All reside in the CMake subdirectory and have .cmake file extensions.
  • One of the following scripts are run to set option flags for the compiler and linker. Multiple groups of flags are set: one for all compilations, one for Debug compilations, one for Release compilations. Similar groups are used for the linker.
  • Herc31_CoptsAppleGNU - gcc on (very old) macOS systems
  • Herc31_CoptsGNU - gcc or clang on other than macOS
  • Herc31_CoptsMSVC - Microsoft Visual Studio C (MVSC)
  • Herc31_CoptsUnknown - unrecognized compiler (includes for the nonce clang on macOS)
  • Throughout the execution of the above scripts, error messages are accumulated in an associative array. If any errors were detected by this point, the array is dumped to the console and the configuration terminated. Errors detected after this point are considered to be internal to the CMake scripts and result in message( FATAL_ERROR ) termination of configuration.
  • Herc41_ExtPackageBuild is run to create CMake external projects for any external packages that must be built from source at the same time Hercules is compiled. Creation of an external project is the same for any project; Herc02_ExtPackageBuild contains the function that issues the CMake add_externalproject() command.
  • A list of system link libraries required to link Hercules is assembled based on the results from Herc22*.
  • The RPATH value for the build and install trees is set. CMake ignores RPATH for Windows targets, as Windows uses a different method for locating shared libraries and loadable modules.
  • config.h is generated from CMake/config.h.in and the information collected during configuration.
  • commitinfo.h is generated from CMake/commitinfo.h.in by CMake/Herc01_GitVer.cmake. Note: Herc01_GitVer.cmake is re-run to update commitinfo.hevery time Hercules is built to capture changes in the git status.
  • A summary of the configuration options is displayed on the console.
  • Herc60_CreateTargets is run to create all Hercules targets. Mapping of source file names to targets is in Herc61_SlibSources.
  • (Windows only) A command is added to copy external package shared libraries to the build directory. This is done only for those external packages built from source when Hercules is compiled.
  • Finally, the tests subdirectory is copied to the build directory. This eliminates any dependency on the source directory when running tests. (Note: this needs to be updated so that updates to the source tests directory get propagated to the build directory.)

CMakeLists.txt in the decNumber Directory

This straightforward script uses information collected by the main CMakeLists.txt to compile the decNumber shared library. There is no complexity or sophistication to this script.

CMakeLists.txt in the crypto Directory

This straightforward script uses information collected by the main CMakeLists.txt to compile the dyncrypt dynamically loaded module. Because dyncrypt includes config.h, it is sensitive to the external packages used to provide BZip2, PCRE (Windows only), and Zlib. Dependencies are added for any of those three packages that will be built by Hercules so their headers are available when dyncrypt is compiled.


This Wiki Copyright © 2018 by Stephen R. Orso. This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

Clone this wiki locally