-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add cmake.py for easier location of the cmake helper files.
- Loading branch information
1 parent
f09160c
commit 0d438fe
Showing
6 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
**/.mypy_cache | ||
**/__pycache__ | ||
**/build | ||
ccgen.* | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from pathlib import Path | ||
|
||
print(Path(__file__).parent / "share" / "cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Auxiliary file for CCGEN in Cmake | ||
# | ||
# Provides a ccgen(...) function to compile all *.ccgen.yaml files to a .c/.h pair | ||
# Usage: after you define your target do: | ||
# include(ccgen.cmake) | ||
# ... | ||
# add_executable(MY_TARGET src1.c, src2.c, src3.yaml) | ||
# ... | ||
# ccgen(MY_TARGET) | ||
# target | ||
# | ||
# To use, feel free to copy this file to your CMakeLists.txt directory. | ||
|
||
function(ccgen target) | ||
get_target_property(sources ${target} SOURCES) | ||
foreach(yaml_file in ${sources}) | ||
cmake_path(GET yaml_file EXTENSION ext) | ||
if("${ext}" MATCHES ".*\.ccgen\.yaml$") | ||
cmake_path(GET yaml_file STEM gen) | ||
add_custom_command( | ||
COMMAND ${Python3_EXECUTABLE} -m ccgen "${yaml_file}" -o "${CMAKE_BINARY_DIR}" | ||
OUTPUT | ||
"${CMAKE_BINARY_DIR}/${gen}.ccgen.c" | ||
"${CMAKE_BINARY_DIR}/${gen}.ccgen.h" | ||
DEPENDS | ||
"${yaml_file}" | ||
COMMENT "CCGen - genetate files." | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
) | ||
target_sources( | ||
${target} | ||
PRIVATE | ||
"${CMAKE_BINARY_DIR}/${gen}.ccgen.c" | ||
"${CMAKE_BINARY_DIR}/${gen}.ccgen.h" | ||
) | ||
endif() | ||
endforeach() | ||
target_include_directories(${target} PUBLIC "${CMAKE_BINARY_DIR}") | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.23) | ||
project(MyProject) | ||
|
||
include(ccgen.cmake) | ||
find_package(Python3 REQUIRED COMPONENTS Interpreter) | ||
|
||
add_executable(MyExec main.c enums.ccgen.yaml) | ||
execute_process(COMMAND ${Python3_EXECUTABLE} -m ccgen.cmake OUTPUT_VARIABLE CCGEN_CMAKE OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
list(APPEND CMAKE_MODULE_PATH "${CCGEN_CMAKE}") | ||
|
||
include(ccgen) | ||
|
||
add_executable(MyExec main.c enums.ccgen.yaml) | ||
ccgen(MyExec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters