From 859fa41ecbed8cd3020dfd734d8ef425d04e369f Mon Sep 17 00:00:00 2001 From: Weaselbot Date: Thu, 18 Jun 2026 15:26:55 -0400 Subject: [PATCH] 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. --- CMakeLists.txt | 32 +---------------------------- contrib/schemagen/CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 contrib/schemagen/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d364b9..eafe77b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,37 +170,7 @@ if(Python3_Interpreter_FOUND) ${CMAKE_CURRENT_SOURCE_DIR}/test_python_bindings.py) endif() -# schemagen tests -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}) +add_subdirectory(contrib/schemagen) include(CMakePushCheckState) include(CheckCXXCompilerFlag) diff --git a/contrib/schemagen/CMakeLists.txt b/contrib/schemagen/CMakeLists.txt new file mode 100644 index 0000000..7cae8eb --- /dev/null +++ b/contrib/schemagen/CMakeLists.txt @@ -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})