Skip to main content

A CMake reimplementation in Python with Ninja generator

Project description

cja

A CMake reimplementation in Python that generates Ninja build files.

Usage

# Configure in current directory
cja

# Specify build directory
cja -B build-release

# Set CMake variables
cja -DCMAKE_BUILD_TYPE=Release
cja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON

After configuration, build with Ninja:

ninja

Build Subcommand

cja supports a build subcommand that works similar to cargo:

cja build

Equivalent to calling:

cja -Bbuild
ninja

cja build --release

Equivalent to calling:

cja -Bbuild-release -DCMAKE_BUILD_TYPE=Release
ninja -f build-release.ninja

Test Subcommand

cja test

Equivalent to calling:

cja build
ninja -f build.ninja test

cja test --release

Equivalent to calling:

cja build --release
ninja -f build-release.ninja test

Run Subcommand

cja generates a "run" phony target which executes the first executable (or the one set via VS_STARTUP_PROJECT) in your CMakeLists.txt.

cja run

Equivalent to calling:

cja build
ninja -f build.ninja run

cja run --release

Equivalent to calling:

cja build --release
ninja -f build-release.ninja run

Supported CMake Commands

Project Structure

  • cmake_minimum_required(VERSION x.y)
  • project(name)
  • add_executable(name sources...)
  • add_library(name [STATIC|SHARED|OBJECT] sources...)
  • add_subdirectory(dir)
  • install(TARGETS targets... [DESTINATION dir]) (defaults to $HOME/.local/bin for TARGETS)

Variables

  • set(VAR value...)
  • set(VAR value CACHE TYPE "doc" [FORCE])
  • option(VAR "description" [ON|OFF])

Control Flow

  • if() / elseif() / else() / endif()
  • foreach() / endforeach() (with RANGE, IN LISTS, IN ITEMS)

Target Properties

  • target_link_libraries(target [PUBLIC|PRIVATE|INTERFACE] libs...)
  • target_sources(target [PUBLIC|PRIVATE|INTERFACE] sources...)
  • target_compile_features(target [PUBLIC|PRIVATE|INTERFACE] features...)
  • target_compile_definitions(target [PUBLIC|PRIVATE|INTERFACE] defs...)
  • target_include_directories(target [PUBLIC|PRIVATE|INTERFACE] [SYSTEM] dirs...)
  • set_source_files_properties(files... PROPERTIES prop value...) (supports OBJECT_DEPENDS, INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS)

Finding Dependencies

  • find_program(VAR name [NAMES ...] [REQUIRED])
  • find_package(name [REQUIRED]) - supports GTest and Threads via pkg-config

Testing

  • add_test(NAME name COMMAND cmd args...) or add_test(name cmd args...)
  • include(CTest) - adds a test target (or use include(module) for other modules)

Other

  • message([STATUS|WARNING|FATAL_ERROR] "text")
  • add_compile_definitions(defs...)
  • add_compile_options(options...)
  • add_custom_command(OUTPUT ... COMMAND ... DEPENDS ...)

Build Types

Set CMAKE_BUILD_TYPE to control optimization:

Build Type Flags
Debug -g -O0
Release -O3 -DNDEBUG
RelWithDebInfo -O2 -g -DNDEBUG
MinSizeRel -Os -DNDEBUG

Example

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(myapp)

add_executable(myapp main.cpp)
target_compile_features(myapp PUBLIC cxx_std_17)

Build:

cja -DCMAKE_BUILD_TYPE=Release
ninja
./build/myapp

Limitations

  • Only supports Ninja generator (by design)
  • Limited find_package support (GTest, Threads via pkg-config)
  • No generator expressions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cja-0.1.0.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cja-0.1.0-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

Details for the file cja-0.1.0.tar.gz.

File metadata

  • Download URL: cja-0.1.0.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Nobara Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cja-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d5403124efdab50db5201d3fa018ac78f9996bd820e2ca977975f70227d2c11f
MD5 9863944dbcdd194d9120026cbc44ddfc
BLAKE2b-256 b94457b2ef2322bafbc9962c38cdad0cb0a3d809c1fdc06277c8d6fb75e4b398

See more details on using hashes here.

File details

Details for the file cja-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cja-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 48.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Nobara Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cja-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16be4c841ac2bb725221431c756934b26a3bbd48a797b47dfc8888853ddf162e
MD5 267aac42ad7f3b95a686da2e85418d48
BLAKE2b-256 15dc36f44b52e53f00ec3af8b21483c89340b4886c9260482e2fa096b8b8da6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page