Skip to main content

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

Project description

CMakeLists Updater

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 git+https://github.com/obsqrbtz/cmakelists-autoupdater

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.0.tar.gz (4.9 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.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cmakelists_updater-1.0.0.tar.gz
Algorithm Hash digest
SHA256 54dbb1bb1e1ed127b04d8a8ffe35ea6d20c8dbb3e5d624bbb32c818d2e98bd81
MD5 61ae3d668563b10bb1cd0087f12d10b2
BLAKE2b-256 035c163bfda23794669b591e3f687347d42b631b090c6ccdd3dcd762d6b05fe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cmakelists_updater-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0abca191e00a8653ebc97c4099b990d09e378d8b889f96a8120e9c776743bad1
MD5 b5f640b5c4284af4d5d9fef9ac1ea6be
BLAKE2b-256 6c43166542c127aead1bb15fe8fc25922659c47c28a58d2fa4e6d02bdd77f828

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