This repository contains a collection of CMake files that are useful for building SaC-based projects, such as modules and SaC programs.
A typical initial stage of making use of these CMake files is to add the repository as a git submodule, this way you can maintain a specific version of the files in your SaC project.
To make it as easy as possible to use SAC within a CMake-based project,
we provide a package which searches for the SAC compiler and other tools
and sets certain needed variables for building. Additionally, we provide
the UseSAC module which provides some conveniences functions for building
SAC programs and modules.
To make use of this, you can use the following example CMakeLists.txt file
as a base to start with:
CMAKE_MINIMUM_REQUIRED (VERSION 3.19)
# Project language can be anything really, we use C here as an example
PROJECT (<project-name> C)
# we need to append this repo to CMake module path
LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-common")
# Now we can "find" sac2c and other tools; this provides paths to
# the compiler with some variables set which might be needed to
# compile some SAC code, e.g. provides the ${SAC_COMPILER} variable
# for sac2c, and ${SAC_C_COMPILER} for saccc.
FIND_PACKAGE (SAC REQUIRED)
# Functions provided here make it easy to compile SAC programs
# and modules!
INCLUDE ("${CMAKE_SOURCE_DIR}/cmake-common/UseSAC.cmake")
# When building modules, it is advisable to correct create a sac2crc
# file so that the SAC compiler can find the modules
INCLUDE ("${CMAKE_SOURCE_DIR}/cmake-common/misc-macros.cmake")
CREATE_SAC2CRC_TARGET ("<project-name>" "${CMAKE_BINARY_DIR}/lib" "${CMAKE_BINARY_DIR}/lib" "")
# Other CMake stuff...
# Now we can call function to build SAC program
ADD_SAC_EXECUTABLE (proga proga.sac)Briefly, from UseSAC you can use the following functions:
-
ADD_SAC_EXECUTABLE (name source [TARGET seq] [CSOURCE c-file;...] [EXCLUDE_FROM_ALL])Causes the SAC sources (together with any C-sources) to be compiled into a program calledname. -
ADD_SAC_LIBRARY (name source [TARGET seq] [CSOURCE c-file;...] [EXCLUDE_FROM_ALL])Causes a SAC module to be built from filesource
As with the CMake ADD_EXECUTABLE and ADD_LIBRARY, you can create cross dependencies
using ADD_DEPENDENCIES.
For further details, read the documentation in UseSAC.cmake and FindSAC.cmake.
These files provide macros and functions which can be directly called within your SaC project. A description of the features provided by each file is given below:
-
check-sac2c.cmakechecks whether we have an operational sac2c compiler. TheSAC2C_EXECvariable overrides search forsac2con the PATH. This produces theSAC2C_VERSIONvariable. -
sac2c-variables.cmakedefines a number of useful sac2c variables that are mainly coming from parsing sac2crc for a given TARGET. Also it performs some sanity checks like: chosen target is set in sac2crc, sac2c executable is set, etc. Feature flag support is also checked here using theCHECK_SAC2C_SUPPORT_FLAGmacro frommisc-macros.cmake, as this is used locally theCMAKE_COMMON_DIRvariable is configurable to set the path to themisc-macros.cmakefile from the root of the project directory, this defaults to the pathcmake-common. -
generate-version-vars.cmakedefined a function where generates the MAJOR, MINOR, and PATCH numbers using thegit-describetool. -
resolve-sac2c-dependencies.cmakedefines a function that for a given file runssac2c -M, checks whether external dependencies to the Tree and Mod shared libraries can be found; and generates a list of local dependencies that can be used while defining a custom target in CMake. -
generate-sac2c-dependency-targets.cmakeprovides a very similar function as is inresolve-sac2c-dependencies.cmake, with the main distinction being that instead of outputting module library file paths, it returns target names. -
generate-sac2crc-file.cmakeis a script which is used to generate a sac2crc file for a package, calledsac2crc.package.<package>. It places it into the user's home directory under.sac2crcdirectory. It is intended that the script is used as a target within the package build. -
check-sac2c-feature-support.cmakecontains a collection of macros/functions which check for supported features insac2c. The results are intended to be exposed via the generatedconfig.hfile, but may also affect whether or not certain build options can be used. -
build-sac2c-module.cmakeprovides macros to create targets to build SaC modules (with dependency resolution provided byresolve-sac2c-dependencies.cmake) -
build-sac2c-progam.cmakeprovides macros to create targets to build SaC programs (with dependency resolution provided byresolve-sac2c-dependencies.cmake) -
sac2c-prog-with-versions.cmakeprovides macros to create targets to build SaC programs that make use of an external version config. Precise details of what this is is explained within the cmake file. -
misc-macros.cmakecontains a miscellaneous collection of functions and macros. Further details on what these functions do is given as comments within.
To add this repository as a submodule, do the following in your SaC project repository:
$ git submodule add https://github.com/SacBase/cmake-common.git
$ git submodule update --initIf you later wish to pull a more recent version the cmake-common repo, you can do the
following:
$ git submodule update --recursive --remoteTo use the functions and macros, you need to INCLUDE these into your CMake project.
See LICENSE.txt for details.