Skip to content

Commit

Permalink
add new CMake macro generate_from_any and extend PythonToCPP script t…
Browse files Browse the repository at this point in the history
…o create source file from any text file
  • Loading branch information
wwmayer committed Oct 14, 2019
1 parent a785660 commit e4f8d98
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions cMake/FreeCadMacros.cmake
Expand Up @@ -161,6 +161,19 @@ macro(generate_from_py BASE_NAME OUTPUT_FILE)
COMMENT "Building files out of ${BASE_NAME}.py")
endmacro(generate_from_py)

macro(generate_from_any INPUT_FILE OUTPUT_FILE VARIABLE)
set(TOOL_PATH "${CMAKE_SOURCE_DIR}/src/Tools/PythonToCPP.py")
file(TO_NATIVE_PATH "${TOOL_PATH}" TOOL_NATIVE_PATH)
file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_FILE}" SOURCE_NATIVE_PATH)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE}"
COMMAND "${PYTHON_EXECUTABLE}" "${TOOL_NATIVE_PATH}" "${SOURCE_NATIVE_PATH}" "${OUTPUT_FILE}" "${VARIABLE}"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_FILE}"
DEPENDS "${TOOL_PATH}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Building files out of ${INPUT_FILE}")
endmacro(generate_from_any)


# generates the ui -> cpp h files
#macro(qt4_wrap_ui infiles )
Expand Down
13 changes: 9 additions & 4 deletions src/Tools/PythonToCPP.py
Expand Up @@ -9,19 +9,24 @@

file = open(sys.argv[1])

if(len(sys.argv) > 3):
sys.stderr.write("Wrong Parameter\n Usage:\n PythonToCPP Infile.py [Outfile]\n")
if(len(sys.argv) > 4):
sys.stderr.write("Wrong Parameter\n Usage:\n PythonToCPP Infile.py [Outfile][Variable]\n")

if(len(sys.argv) > 2):
out = open(sys.argv[2],"w");
else:
out = sys.stdout

if(len(sys.argv) > 3):
identifier = sys.argv[3]
else:
identifier = os.path.basename(sys.argv[1])
identifier = identifier[:-3]

lines = file.readlines()

# We want to use this script for files in another directory, so we extract the actual file name
fn = os.path.basename(sys.argv[1])
out.write("const char " + fn[:-3] + "[] =")
out.write("const char " + identifier + "[] =")

for line in lines:
# remove new line
Expand Down

0 comments on commit e4f8d98

Please sign in to comment.