CMake

Piles use CMake as a build system. Several CMake scripts are provided in pile-cmake repository to make the job of the developer as simple as possible. Here is a complete list:

pileCmakeOutputPath

Computes an output path CMake style. A relative path to PROJECT_SOURCE_DIR is computed using pileRelativePath, then it is appended to PROJECT_BINARY_DIR.

Arguments:
output
the name of the output variable;
input
(absolute) input path
Example:
pileCmakeOutputPath (OUTPUT_VAR "${CMAKE_SOURCE_DIR}/a_file.cc")

pileRelativePath

Computes a relative path. Both reference ans input must be either unix like (/usr/bin) or Windows like (C:/Windows). Mixing them is undefined.

  • for input /a/b/c and reference /a/b the result is ..
  • for input /a/b and reference /a/b/c the result is c
  • for input /a/1/2/3 and reference /a/b/c the result is ../../../b/c

If the paths are the same . is returned

Arguments:
output
the name of the output variable;
reference
(absolute) reference path
input
(absolute) input path
Example:
pileRelativePath (OUTPUT_VAR "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/a_file.cc" )

pileUsedBy

Depending on the use style for this pile, may add the library to the target using target_link_libraries or it may create a dependency to the copy headers target.

Arguments:
pile_name
name of the pile
target
name of the target
Example:
pileUsedBy (myLib somePile)
Status:
not fully implemented

pileDebugMessage

Shows a debug message on behalf of the pile. These messages can be enabled or disabled on a per-pile basis using PILE_DEBUG_MSG variable (PILE is the name of the pile upper-cased).

To disable all messages generated by this macro set PILE_SUPPORT_DEBUG to OFF (PILE in this case is the actual word PILE).

The macros in pile-cmake repository use this macro to report debug events.

Arguments:
name
name of the pile
message
the message to show
Example:
pileDebugMessage (SomePile "message from a pile")

pileInclude

Includes a pile .cmake file but does not initialize the pile.

Path can be provided as optional arguments. If path is provided it can be absolute or relative to CMAKE_SOURCE_DIR. If path is not provided then ${CMAKE_SOURCE_DIR}/name and ${CMAKE_SOURCE_DIR}/name-src are tried.

Defines following variables:

PILE_NAME
the name with all-lower-case letters
PILE_NAME_U
the name with all-UPPER-case letters
PILE_NAME_C
the name as provided (should be CamelCase)
PILE_SOURCE_DIR
the path where this pile is stored (not including /cmake)
PILE_BINARY_DIR
the path where this pile generates output

By using this function the top level CMake file does not have to alter CMAKE_MODULE_PATH itself.

Arguments:
name
name of the pile, camel cased;
(optional) path
the path of this pile; both relative and absolute paths are supported.
Example:
pileInclude (SomePile)
pileInclude (SomePile "./somepile_in_nonstandard_path")

pileCreateCopyTarget

Creates a target to copy files. If base_path is provided then the path structure is going to be preserved, otherwise all files are going to be copied in same directory.

Arguments:
target_name
name of the target to be created;
target_description
a description to add to this target;
destination_path
path where to copy the files;
files_list
list of files to copy;
(optional) base_path
part of the path that is used as a reference for computing relative paths from files_list;
Example:
pileCreateCopyTarget (
  target_1 "copy some files"
  "${CMAKE_BINARY_DIR}/dump"
  ${SOME_FILES})

pileCopyHeaders

Creates a target that copies the headers from a pile to build directory. Name of the new target is copy_pile_headers. The files are copied to ${CMAKE_BINARY_DIR}/build/include It is assumed that PILE_HEADERS and PILE_PATH are defined.

Internally the macro simply calls pileCreateCopyTarget

Arguments:
name
name of the pile;
Example:
pileCopyHeaders (SomePile)

pileSetDependencies

Set dependencies for a pile. The list can be empty. Basically the macro creates a variable PILE_DEPENDENCIES and, if debugging is enabled, informs the user about them.

Arguments:
name
name of the pile;
dependencies
list of pile names that this pile depends on;
Example:
pileSetDependencies (SomePile ${LIST_OF_DEPENDENCIES})

pileSetCategory

Set the category for a pile.

The list can be empty; if there are more than one items in the list they are interpreted to be components of a path.

A pile has a single category and multiple tags. All the components of the category list are added as tags. pileSetCategory("p1" "a;b;c") is thus interpreted like a/b/c/p1 by a tool looking to store the piles or categorize.

The macro defines or changes PILE_CATEGORY and PILE_TAGS variables.

Arguments:
name
name of the pile;
category
the category as a list;
Example:
pileSetCategory (SomePile "a;b;c")

pileSetTags

Set the tags for a pile.

The list can be empty; the macro defines or changes PILE_TAGS variables.

Arguments:
name
name of the pile;
tags
the tags as a list;
Example:
pileSetTags (SomePile "a;b;c")

pileSetVersion

Set the version for a pile.

The list should contain major, minor and patch components. The macro defines or changes PILE_MAJOR_VERSION, PILE_MINOR_VERSION, PILE_PATCH_VERSION, PILE_VERSION_STRING, PILE_DEBUG and PILE_RELEASE.

Arguments:
name
name of the pile;
value
the version;
Example:
pileSetVersion (SomePile "1;0;0")
pileSetVersion (SomeOtherPile "1;0;0;d")
pileSetVersion (SomeThirdPile "1;0;0;debug")

pileSetMode

Set the use mode.

The list should contain major, minor and patch components. The macro defines or changes PILE_STATIC, PILE_PILE, PILE_SHARED with the one being selected set to ON and the others to OFF.

Arguments:
name
name of the pile;
mode
the mode;
Example:
pileSetMode (SomePile "STATIC")
pileSetMode (SomeOtherPile "PILE")
pileSetMode (SomeThirdPile "PILE_SHARED")
pileSetMode (SomeFourthPile "SHARED")

pileSetCommon

Set common properties.

This is just a wrapper around the other macros: pileSetDependencies, pileSetCategory, pileSetTags, pileSetVersion, pileSetMode.

Arguments:
name
name of the pile;
version
the version;
mode
the mode;
dependencies
the list of piles this pile depends on;
category
the list for category;
tags
the list of tags;
Example:
pileSetCommon (SomePile
  "1;0;1"
  "STATIC"
  "APile;Another"
  "cat1;cat11"
  "tag1;tag2")

pileConfigFile

Configures the file for a pile.

The input file is pile-config.h.in an the output is pile-config.h.

Arguments:
name
name of the pile;
Example:
pileConfigFile (SomePile)

pileSetSources

Set the list of sources.

Arguments:
name
name of the pile;
headers
the list of headers;
sources
the list of sources;
Example:
pileSetSources (SomePile ${HEADERS} ${SOURCES})