forked from weaselab/weaseljson
schemagen: move test configuration into contrib/schemagen/CMakeLists.txt
Addresses review feedback: keep the schemagen-specific CMake rules close to the tool instead of inline in the top-level CMakeLists.txt. The subdirectory file is added from the root and guarded by the same Python3 availability check that was already in use.
This commit is contained in:
+1
-31
@@ -170,37 +170,7 @@ if(Python3_Interpreter_FOUND)
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_python_bindings.py)
|
${CMAKE_CURRENT_SOURCE_DIR}/test_python_bindings.py)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# schemagen tests
|
add_subdirectory(contrib/schemagen)
|
||||||
add_test(
|
|
||||||
NAME schemagen_python_tests
|
|
||||||
COMMAND python3 contrib/schemagen/test_schemagen.py
|
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
|
||||||
|
|
||||||
set(SCHEMAGEN_DIR ${CMAKE_SOURCE_DIR}/contrib/schemagen)
|
|
||||||
set(SCHEMAGEN_SCRIPT ${SCHEMAGEN_DIR}/weaseljson_schemagen.py)
|
|
||||||
set(EXAMPLE_SCHEMA ${SCHEMAGEN_DIR}/example.schema.json)
|
|
||||||
set(GEN_H ${CMAKE_BINARY_DIR}/gen.h)
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${GEN_H}
|
|
||||||
COMMAND python3 ${SCHEMAGEN_SCRIPT} ${EXAMPLE_SCHEMA} -o ${GEN_H} --namespace
|
|
||||||
weasel_schema
|
|
||||||
DEPENDS ${SCHEMAGEN_SCRIPT} ${EXAMPLE_SCHEMA}
|
|
||||||
COMMENT "Generating gen.h from example.schema.json")
|
|
||||||
|
|
||||||
add_custom_target(schemagen_gen_h DEPENDS ${GEN_H})
|
|
||||||
|
|
||||||
add_executable(schemagen_example ${SCHEMAGEN_DIR}/test_gen.cpp)
|
|
||||||
target_include_directories(schemagen_example PRIVATE include
|
|
||||||
${CMAKE_BINARY_DIR})
|
|
||||||
target_link_libraries(schemagen_example PRIVATE ${PROJECT_NAME})
|
|
||||||
target_compile_options(schemagen_example PRIVATE -Wno-switch-enum)
|
|
||||||
add_dependencies(schemagen_example schemagen_gen_h)
|
|
||||||
|
|
||||||
add_test(
|
|
||||||
NAME schemagen_example
|
|
||||||
COMMAND schemagen_example
|
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
||||||
|
|
||||||
include(CMakePushCheckState)
|
include(CMakePushCheckState)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Tests for contrib/schemagen
|
||||||
|
|
||||||
|
if(NOT Python3_Interpreter_FOUND)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME schemagen_python_tests
|
||||||
|
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_schemagen.py
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
set(SCHEMAGEN_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/weaseljson_schemagen.py)
|
||||||
|
set(EXAMPLE_SCHEMA ${CMAKE_CURRENT_SOURCE_DIR}/example.schema.json)
|
||||||
|
set(GEN_H ${CMAKE_CURRENT_BINARY_DIR}/gen.h)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_H}
|
||||||
|
COMMAND ${Python3_EXECUTABLE} ${SCHEMAGEN_SCRIPT} ${EXAMPLE_SCHEMA} -o
|
||||||
|
${GEN_H} --namespace weasel_schema
|
||||||
|
DEPENDS ${SCHEMAGEN_SCRIPT} ${EXAMPLE_SCHEMA}
|
||||||
|
COMMENT "Generating gen.h from example.schema.json")
|
||||||
|
|
||||||
|
add_custom_target(schemagen_gen_h DEPENDS ${GEN_H})
|
||||||
|
|
||||||
|
add_executable(schemagen_example ${CMAKE_CURRENT_SOURCE_DIR}/test_gen.cpp)
|
||||||
|
target_include_directories(schemagen_example
|
||||||
|
PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
target_link_libraries(schemagen_example PRIVATE ${PROJECT_NAME})
|
||||||
|
target_compile_options(schemagen_example PRIVATE -Wno-switch-enum)
|
||||||
|
add_dependencies(schemagen_example schemagen_gen_h)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME schemagen_example
|
||||||
|
COMMAND schemagen_example
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
Reference in New Issue
Block a user