PyCMake Package

Module contents

PyCMake

This module is a tool for CMake to help create, manage and build CMake Projects.

Submodules

pycmake.cmake

CMake manage all common settings to provide CMake project.

class pycmake.cmake.CMake

Bases: object

Class to manage all common settings.

add_settings(min_required, policy)

Set cmake_minimum_required and cmake_policy.

Parameters:
  • min_required (str) – the cmake version minimum required.
  • policy (str) – the policies of project.
clang_compiler(compiler)

Add a Clang Compiler to CMake.

Parameters:compiler (Compiler) – Clang Compiler to add. Must be created before.
flags_to_compiler(compiler_id, flags)

Add Flags to a specific compiler.

Parameters:
  • compiler_id (str) – id of compiler. For more details, see C_COMPILER or CXX_COMPILER.
  • flags (Flags) – Flags to add to the compiler.
gnu_compiler(compiler)

Add a GNU Compiler to CMake.

Parameters:compiler (Compiler) – Gnu Compiler to add. Must be created before.
msvc_compiler(compiler)

Add a MSVC Compiler to CMake object.

Parameters:compiler (Compiler) – MSVC Compiler to add. Must be created before.

pycmake.cmakelists

CMakeLists create and generate CMakeLists.txt from a Project object.

class pycmake.cmakelists.CMakeLists

Bases: object

Class who manage CMakeLists.txt.

init_file(path)

Create folders and CMakeLists.txt.

Parameters:path (str) – path where to create CMakeLists.txt.
write_clang_flags(clang_flags)

Write Flags for compilers.

Parameters:clang_flags (dict) – Flags for Clang compiler.
write_cmakelists(cmake, project)

Write CMakeLists.txt from the CMake data.

Parameters:
write_dependencies(dependencies)

Write dependencies of project.

Parameters:dependencies (Externals) – Dependencies of the project.
write_directory_files(sources_dirs)

Write different variables for directories of project.

Parameters:sources_dirs (dict) – Sources Directories.
write_global_settings(settings)

Write settings of CMake.

Parameters:settings (dict) – global settings of CMake
write_gnu_flags(gnu_flags)

Write Flags for compilers.

Parameters:gnu_flags (dict) – Flags for GNU compiler.
write_info()

Write global informations.

Write Links for dependencies of project.

Parameters:dependencies (Externals) – Dependencies of the project.
write_msvc_flags(msvc_flags)

Write Flags for compilers.

Parameters:msvc_flags (dict) – Flags for MSVC compiler.
write_preprocessor_definitions(definitions)

Write preprocessor definitions of project.

Parameters:definitions (tuple) – preprocessor definitions.
write_project(language)

Write project and definitions.

Parameters:language (str) – language of project.
write_targets(project)

Write Targets and add sources Variables.

Parameters:project (Project) – CMake Project.
write_title(title)

Write title of each section in CMakeLists.txt

Parameters:title (str) – title to write
write_variables(project)

Write Project variables and data.

Parameters:project (Project) – project to build.
write_version(version)

Write version variables.

Parameters:version (dict) – version numbers of project.

pycmake.compiler

Compiler define every supported compilers.

class pycmake.compiler.Compiler

Bases: object

Class to define a compiler.

static check_compiler_options(language, compiler_id)

Check if compiler is valid. Used for each create().

Parameters:
  • language (str) – language of project. For more details, see LANGUAGE.
  • compiler_id (str) – id of compiler. For more details, see C_COMPILER or CXX_COMPILER.
create(name, language, compiler_id, version, executable)

Create a compiler.

Parameters:
  • name (str) – name of compiler.
  • language (str) – language of project. For more details, see LANGUAGE.
  • compiler_id (str) – id of compiler. For more details, see C_COMPILER or CXX_COMPILER.
  • version (int or float) – version of the compiler.
  • executable (str) – full path to the executable.

pycmake.externals

Externals contains all dependencies related to project.

class pycmake.externals.Externals

Bases: object

Class to manage dependencies.

Link with the specified directories.

Parameters:directories (tuple) – directories in which the linker will look for libraries.
add_subdirectory(subdir_id, source_dir, binary_dir)

Add one subdirectory to the build.

Parameters:
  • subdir_id (str) – id of the subdir.
  • source_dir (str) – directory in which the source CMakeLists.txt is located
  • binary_dir (str) – directory in which to place the output files.

Link the libraries specified to the associated target.

Parameters:
  • target (str) – relevant target.
  • libraries (tuple) – libraries to link to target.

pycmake.flags

Flags for compilers.

class pycmake.flags.Flags(flags_id, general, debug='', release='')

Bases: object

Class to manage general, debug and release flags.

debug = None
Parameters:debug (str) – flags for debug target
flags_id = None
Parameters:flags_id (str) – id of flags
general = None
Parameters:general (str) – flags for all targets.
release = None
Parameters:release (str) – flags for release target.

pycmake.project

Project contains all data related to project.

class pycmake.project.Project

Bases: object

Class to manage project data.

add_dependencies(dependencies)

Add some dependencies to project.

Parameters:dependencies (Externals) – dependencies of the project, like subdirectories or external link.
add_executable_target(name)

Add an executable target.

Parameters:name (str) – name of the executable.
add_library_target(name, shared=False)

Add a Library target.

Parameters:
  • name (str) – the library name.
  • shared (bool) – shared library or not.
add_sources_to_target(target, src)

Add sources directory or files to a specific target.

Parameters:
  • target (str) – existing target.
  • src (Sources) – the sources to add.
add_version(major, minor, patch, tweak=0)
Parameters:
  • major (int) – number of Major Version
  • minor (int) – Number of Minor Version
  • patch (int) – Number of Patch version
  • tweak (int) – Number of Tweak version.
create(name, language)

Create a project.

Parameters:
  • name (str) – name of the project.
  • language (str) – language of the project.
get_variable(name)

Returns the contents of the specified variable. Will look into Variables

Parameters:name (str) – the name of the desired variable.
Returns:a variable of the project.
Return type:dict
preprocessor_definitions(*definitions)

Add Preprocessor Definitions.

Parameters:definitions (tuple) – add preprocessor definitions to project. Ex: UNICODE

pycmake.sources

Sources contains files or directory for a Project.

class pycmake.sources.Sources

Bases: object

Class to manage project sources.

add(name, src_type, sources, from_proj=False)

Add sources with a specific type.

Parameters:
  • name (str) – name of the sources.
  • src_type (SRC_TYPE) – type of the sources: DIR or FILE
  • from_proj (bool) – sources relative from project directory.
  • sources (list) – sources to add.
is_recursive()

Check if sources are recursive are not.

make_recursive(recursive)

Make sources directory recursive.

Parameters:recursive (bool) – recursive or not. Default: False.

pycmake.supported

This file is only to tell what’s compatible or not with PyCMake.

pycmake.supported.CXX_COMPILER = ('G++', 'CLANG++', 'MSVC++')
Variables:CXX_COMPILER – supported C++ Compiler.
pycmake.supported.C_COMPILER = ('GCC', 'CLANG', 'MSVC')
Variables:C_COMPILER – supported C Compilers.
pycmake.supported.LANGUAGE = ('C', 'C++')
Variables:LANGUAGE – supported languages.
pycmake.supported.SRC_TYPE = ('DIR', 'FILE')
Variables:SRC_TYPE – supported Sources.

pycmake.variables

Variables hold all project variables.

class pycmake.variables.Variables

Bases: object

Class to manage variables.

add(name, value, option='set')

Add a variable.

Parameters:
  • name (str) – Name of the variable.
  • value (str) – Value of variable.
  • option (str) – option for variable: ‘set’ or ‘get_filename_component’
archive_output_path(path)

Add ARCHIVE_OUTPUT_PATH variable for Static libraries.

Parameters:path (str) – path where build Static libraries.
executable_output_path(path)

Add EXECUTABLE_OUTPUT_PATH variable for executables.

Parameters:path (str) – path where build executables.
library_output_path(path)

Add LIBRARY_OUTPUT_PATH variable for Shared libraries.

Parameters:path (str) – path where build Shared libraries.
project_dir(path)

Defines the main project directory in a variable named: PROJECT_DIR.

Parameters:path (str) – relative path from CMakeLists.txt.