Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sftrabbit/cmake-transform
CMake functions for transforming files
https://github.com/sftrabbit/cmake-transform
cmake cmake-scripts
Last synced: 17 days ago
JSON representation
CMake functions for transforming files
- Host: GitHub
- URL: https://github.com/sftrabbit/cmake-transform
- Owner: sftrabbit
- License: other
- Created: 2017-05-29T13:13:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-30T21:15:03.000Z (over 7 years ago)
- Last Synced: 2024-10-29T18:22:50.413Z (2 months ago)
- Topics: cmake, cmake-scripts
- Language: CMake
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CMake Transform
CMake Transform is a collection of CMake functions for transforming files by piping them through a command.
## Usage
To add a transform target that will transform a list of source files by piping their content through a command:
add_transform(
COMMAND
SOURCES ...)This also creates targets for each transformed file. To extract the names of the transformed file targets:
get_transformed(
SOURCES ...)## Example
Given a text file `test.txt`:
The old man said "GREETING" to the dog. The dog responded in kind: "GREETING".
We can create a transform target in our `CMakeLists.txt` that substitutes the text `GREETING` with `Hello` and then, for demonstration purposes, add a post-build command that prints the transformed file contents:
include(transform.cmake)
set(input_file test.txt)
add_transform(substitute
COMMAND sed -e 's/GREETING/Hello/g'
SOURCES ${input_file})get_transformed(substitute transformed_test_file
SOURCES ${input_file})
add_custom_command(
TARGET substitute
POST_BUILD
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/${transformed_test_file})If we then run `cmake` on the directory with these files and then `make substitute`, we see the following output:
Scanning dependencies of target substitute
[100%] Generating CMakeFiles/transform_gen/substitute/test.txt
The old man said "Hello" to the dog. The dog responded in kind: "Hello".
[100%] Built target substitute