Skip to main content

A tool to auto-update CMakeLists.txt when source files change.

Project description

CMakeLists Updater

PyPI version License Python versions

CMakeLists Updater detects new or deleted .h, .hpp, and .cpp files and updates SET(HEADERS) and SET(SOURCES) sections in the CMakeLists.txt file. It also supports a global ignore list for files and directories that should not be monitored.

Installation

Install the package using pip:

pip install cmakelists-updater

Configuration

Create a YAML configuration file (e.g., config.yaml) with the following structure:

global_ignore_list:
    - build
    - .git
    - .vscode
cmake_files:
  path/to/first/CMakeLists.txt:
    source_dirs:
      - path/to/first/src
      - path/to/first/include
    ignore_list:
      - ignored_dir
      - ignored_file.cpp
  path/to/second/CMakeLists.txt:
    source_dirs:
      - path/to/second/src
      - path/to/second/include
    ignore_list:
      - ignored_dir
      - ignored_file.cpp
  • cmake_files: A mapping of CMake files to their respective settings.
  • source_dirs: A list of directories to monitor for source file changes.
  • ignore_list: (Optional) A list of directories or files to exclude from monitoring for each CMake file.
  • global_ignore_list: (Optional) A list of directories or files to exclude from monitoring across all CMake files.

Usage

Terminal

Run the cmakelists-updater command, providing the path to your configuration file:

cmakelists-updater config.yaml

VS Code task

Add .vscode/tasks.json file to your project root with the following contents:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run CMakeLists Updater",
      "type": "shell",
      "command": "cmakelists-updater",
      "args": ["config.yaml"],
      "problemMatcher": [],
      "presentation": {
        "reveal": "silent",
        "panel": "shared",
        "clear": true
      },
      "options": {
        "env": {
          "PYTHONUNBUFFERED": "1"
        }
      },
      "runOptions": {
        "runOn": "folderOpen"
      }
    }
  ]
}

CMake command

Check if cmake-autoupdater is installed and execute it if found:

set(AUTO_UPDATER_STARTED FALSE CACHE BOOL "" FORCE)

find_program(CMAKELISTS_UPDATER_EXEC cmakelists-updater)

if(NOT AUTO_UPDATER_STARTED AND CMAKELISTS_UPDATER_EXEC)
  execute_process(
    COMMAND ${CMAKELISTS_UPDATER_EXEC} "config.yaml"
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  )
  set(AUTO_UPDATER_STARTED TRUE CACHE BOOL "" FORCE)
endif()

Example

Assume the following directory structure:

project/
--src/
----main.cpp
----utils.cpp
----utils.hpp
--include/
----project.hpp
--CMakeLists.txt

In order to get the script working, first make sure that CMakeLists has HEADERS and SOURCES variables set and are used in add_executable/add_library:

SET(HEADERS
    include/project.hpp
)

SET(SOURCES
    src/utils.hpp
    src/utils.cpp
    src/main.cpp
    ${HEADERS}
)

add_executable(${PROJECT_NAME}
    ${HEADERS}
    ${SOURCES}
    any_external_dep.hpp)

Place a config.yaml file into the project root. It might look like:

cmake_files:
  CMakeLists.txt:
    source_dirs:
      - src
      - include
    ignore_list:
      - build

Run the following command from the project root to start monitoring and updating the CMakeLists.txt:

cmakelists-updater config.yaml

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

cmakelists_updater-1.0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

cmakelists_updater-1.0.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file cmakelists_updater-1.0.1.tar.gz.

File metadata

  • Download URL: cmakelists_updater-1.0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cmakelists_updater-1.0.1.tar.gz
Algorithm Hash digest
SHA256 73bc08fc2de2968a40b1b3cb06fa32f0145f523dd0784dd3bd534acd44b437a8
MD5 bc5146de60b95ab8574d54ed4edd9111
BLAKE2b-256 fe6f20bf95b532c65266869ee00fde0a947c1362fa60eaf02d7ff21c856f8c46

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmakelists_updater-1.0.1.tar.gz:

Publisher: pypi-publish.yml on obsqrbtz/cmakelists-autoupdater

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cmakelists_updater-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cmakelists_updater-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce43aa5b2a70c48360a5cd1aba24c2ef119dd3becde0950dde91d6586619b17e
MD5 6a011f86c64657beeac54aca325c99b7
BLAKE2b-256 ff6bf939caf0605861ca021616439c43816802c4955510d8feea96387a25942d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmakelists_updater-1.0.1-py3-none-any.whl:

Publisher: pypi-publish.yml on obsqrbtz/cmakelists-autoupdater

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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