2017-04-20 18:38:20 +00:00
|
|
|
# Copyright 2017 The NXT Authors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
find_package(PythonInterp REQUIRED)
|
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
|
|
|
# Check for Jinja2
|
|
|
|
message(STATUS "${PYTHON_EXECUTABLE}")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} -c "import jinja2"
|
|
|
|
RESULT_VARIABLE RET
|
|
|
|
)
|
|
|
|
if (NOT RET EQUAL 0)
|
2017-05-29 18:21:33 +00:00
|
|
|
message(FATAL_ERROR "Missing dependencies for code generation, please ensure you have python-jinja2 installed.")
|
2017-04-20 18:38:20 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
function(Generate)
|
2017-07-07 18:41:17 +00:00
|
|
|
set(oneValueArgs LIB_NAME LIB_TYPE PRINT_NAME EXECUTABLE FOLDER)
|
2017-05-30 22:06:38 +00:00
|
|
|
set(multiValueArgs COMMAND_LINE_ARGS EXTRA_DEPS EXTRA_SOURCES)
|
2017-04-20 18:38:20 +00:00
|
|
|
cmake_parse_arguments(G "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${G_COMMAND_LINE_ARGS} --print-dependencies
|
|
|
|
OUTPUT_VARIABLE DEPENDENCIES
|
|
|
|
RESULT_VARIABLE RET
|
|
|
|
)
|
|
|
|
if (NOT RET EQUAL 0)
|
|
|
|
message(STATUS ${RET})
|
|
|
|
message(FATAL_ERROR "Failed to get the dependencies for ${G_PRINT_NAME}.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${G_COMMAND_LINE_ARGS} --print-outputs
|
|
|
|
OUTPUT_VARIABLE OUTPUTS
|
|
|
|
RESULT_VARIABLE RET
|
|
|
|
)
|
|
|
|
if (NOT RET EQUAL 0)
|
|
|
|
message(FATAL_ERROR "Failed to get the outputs for ${G_PRINT_NAME}.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
COMMAND ${G_COMMAND_LINE_ARGS}
|
|
|
|
DEPENDS ${DEPENDENCIES} ${G_EXTRA_DEPS}
|
|
|
|
OUTPUT ${OUTPUTS}
|
|
|
|
COMMENT "Generating files for ${G_PRINT_NAME}."
|
|
|
|
)
|
|
|
|
|
|
|
|
add_library(${G_LIB_NAME} ${G_LIB_TYPE}
|
2017-05-30 22:06:38 +00:00
|
|
|
${G_EXTRA_SOURCES}
|
2017-04-20 18:38:20 +00:00
|
|
|
${OUTPUTS}
|
|
|
|
)
|
2017-07-07 18:41:17 +00:00
|
|
|
|
|
|
|
NXTInternalTarget("${G_FOLDER}" ${G_LIB_NAME})
|
2017-07-11 00:09:59 +00:00
|
|
|
target_compile_options(${G_LIB_NAME} PRIVATE ${NXT_GENERATED_FLAGS})
|
2017-04-20 18:38:20 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
set(GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
|
|
|
|
|
|
|
|
set(GENERATOR_COMMON_ARGS
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/main.py
|
|
|
|
${CMAKE_SOURCE_DIR}/next.json
|
|
|
|
-t ${CMAKE_CURRENT_SOURCE_DIR}/templates
|
|
|
|
-o ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
PARENT_SCOPE
|
|
|
|
)
|