pycmake package

Module contents

PyCMake

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

Submodules

pycmake.cmake

class pycmake.cmake.CMake

Bases: object

CMake is root module of PyCMake. He manage all to provide CMake project.

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

    supported compiler_id.

    • [GCC or G++],
    • [CLANG or CLANG++],
    • [MSVC or MSVC++]
  • 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

class pycmake.cmakelists.CMakeLists

Bases: object

CMakeLists create and generate 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_project_data(language, definitions)

Write project and definitions.

Parameters:
  • language (str) – language of project.
  • definitions (tuple) – definitions of project.
write_targets(project)

Write Targets and add sources Variables.

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

Write Project variables and data.

Parameters:project (Project) – project to build.

pycmake.compiler

class pycmake.compiler.Compiler

Bases: object

Compilers define a compiler.

static check_compiler_options(language, compiler_id)

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

Parameters:
  • language (str) – language of compiler (C or CXX)
  • compiler_id (str) – compiler_id (GCC, G++, CLANG, CLANG++, MSVC or MSVC++)
create(name, language, compiler_id, version, executable)

Create a compiler.

Parameters:
  • name (str) – name of compiler.
  • language (str) – language of compiler
  • compiler_id (str) – compiler (GCC, G++, CLANG, CLANG++, MSVC or MSVC++)
  • version (int or float) – version of the compiler.
  • executable (str) – full path to the executable.

pycmake.externals

class pycmake.externals.Externals

Bases: object

Externals contains all dependencies related to project.

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

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

Bases: object

Flags for general, debug and release compilations

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

class pycmake.project.Project

Bases: object

CMakeProject contains all data related to project.

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_source_directories(dirs_id, target, recursive, from_proj, *sources)

Add one or many sources directories to project.

Parameters:
  • dirs_id (str) – id of the directories.
  • target (str) – add directories to a specific target.
  • recursive (bool) – recursive or not
  • from_proj (bool) – if True, append to ${PROJECT_DIR} variable, see project_dir()
  • sources (tuple) – source directories to add.
add_source_files(files_id, target, from_proj=False, *files)

Add one or many sources files to project.

Parameters:
  • files_id (str) – id of the files.
  • target (str) – add files to a specific target.
  • from_proj (bool) – add ${PROJECT_DIR} to source files if True.
  • files (tuple) – files 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: FOO BAR

pycmake.supported

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

pycmake.variables

class pycmake.variables.Variables

Bases: object

Variables hold all project 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.