mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-11 11:07:40 +00:00
Add cmake config to properly do incremental build
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
# OrcaSlicer Config Codegen CMake Module
|
# OrcaSlicer Config Codegen CMake Module
|
||||||
#
|
#
|
||||||
# Generates C++ source files from protobuf schema definitions.
|
# Generates C++ source files from protobuf schema definitions.
|
||||||
# Generated files are checked into the repo so builds work without protoc.
|
# Generated files live in src/slic3r/GUI/generated/ and are gitignored.
|
||||||
|
# Run 'python tools/run_codegen.py' (requires grpcio-tools or protoc) to regenerate.
|
||||||
#
|
#
|
||||||
# Targets:
|
# Targets:
|
||||||
# codegen_config - Custom target to regenerate C++ from .proto files
|
# codegen_config - Custom target to regenerate C++ from .proto files
|
||||||
@@ -13,59 +14,71 @@
|
|||||||
find_program(PROTOC_EXECUTABLE protoc)
|
find_program(PROTOC_EXECUTABLE protoc)
|
||||||
find_package(Python3 COMPONENTS Interpreter QUIET)
|
find_package(Python3 COMPONENTS Interpreter QUIET)
|
||||||
|
|
||||||
set(CONFIG_PROTO_DIR "${CMAKE_SOURCE_DIR}/src/proto")
|
# If generated files are missing (fresh clone), run codegen immediately at configure time.
|
||||||
set(CONFIG_PROTO_GEN_DIR "${CMAKE_SOURCE_DIR}/src/proto/generated")
|
# This allows cmake configure + build to work without a separate pre-build step.
|
||||||
set(CONFIG_CODEGEN_DIR "${CMAKE_SOURCE_DIR}/codegen/generated")
|
set(_generated_marker "${CMAKE_SOURCE_DIR}/src/slic3r/GUI/generated/PrintConfigDef_generated.cpp")
|
||||||
set(CONFIG_DESC_FILE "${CMAKE_BINARY_DIR}/config.desc")
|
if(Python3_EXECUTABLE AND NOT EXISTS "${_generated_marker}")
|
||||||
|
message(STATUS "Config codegen: generated files missing — running codegen now...")
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tools/run_codegen.py" --no-validate
|
||||||
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
|
RESULT_VARIABLE _codegen_result
|
||||||
|
)
|
||||||
|
if(NOT _codegen_result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Config codegen failed. Install grpcio-tools: pip install grpcio-tools")
|
||||||
|
endif()
|
||||||
|
message(STATUS "Config codegen: generated files created successfully")
|
||||||
|
elseif(NOT Python3_EXECUTABLE AND NOT EXISTS "${_generated_marker}")
|
||||||
|
message(FATAL_ERROR "Config codegen: generated files missing and Python3 not found.\n"
|
||||||
|
"Install Python and grpcio-tools: pip install grpcio-tools\n"
|
||||||
|
"Then run: python tools/run_codegen.py")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CODEGEN_TOOL "${CMAKE_SOURCE_DIR}/tools/config_codegen.py")
|
set(CONFIG_PROTO_DIR "${CMAKE_SOURCE_DIR}/src/PrintConfigs")
|
||||||
set(VALIDATE_TOOL "${CMAKE_SOURCE_DIR}/tools/validate_codegen.py")
|
set(CONFIG_CODEGEN_DIR "${CMAKE_SOURCE_DIR}/src/slic3r/GUI/generated")
|
||||||
set(RUN_CODEGEN_TOOL "${CMAKE_SOURCE_DIR}/tools/run_codegen.py")
|
set(CONFIG_LAYOUT_YAML "${CMAKE_SOURCE_DIR}/src/PrintConfigs/layout.yaml")
|
||||||
|
set(CONFIG_DESC_FILE "${CMAKE_BINARY_DIR}/config.desc")
|
||||||
|
|
||||||
# Generated output files
|
set(CODEGEN_TOOL "${CMAKE_SOURCE_DIR}/tools/config_codegen.py")
|
||||||
|
set(VALIDATE_TOOL "${CMAKE_SOURCE_DIR}/tools/validate_codegen.py")
|
||||||
|
set(RUN_CODEGEN_TOOL "${CMAKE_SOURCE_DIR}/tools/run_codegen.py")
|
||||||
|
|
||||||
|
# Generated output files (TabLayout_generated.cpp is also generated from layout.yaml)
|
||||||
set(CONFIG_GENERATED_SOURCES
|
set(CONFIG_GENERATED_SOURCES
|
||||||
"${CONFIG_CODEGEN_DIR}/PrintConfigDef_generated.cpp"
|
"${CONFIG_CODEGEN_DIR}/PrintConfigDef_generated.cpp"
|
||||||
"${CONFIG_CODEGEN_DIR}/Preset_options_generated.cpp"
|
"${CONFIG_CODEGEN_DIR}/Preset_options_generated.cpp"
|
||||||
"${CONFIG_CODEGEN_DIR}/Invalidation_generated.cpp"
|
"${CONFIG_CODEGEN_DIR}/Invalidation_generated.cpp"
|
||||||
"${CONFIG_CODEGEN_DIR}/OptionKeys_generated.cpp"
|
"${CONFIG_CODEGEN_DIR}/OptionKeys_generated.cpp"
|
||||||
|
"${CONFIG_CODEGEN_DIR}/TabLayout_generated.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Collect all .proto source files
|
# Collect all .proto source files (flat in src/PrintConfigs/, excluding config_metadata.proto)
|
||||||
file(GLOB CONFIG_PROTO_FILES
|
file(GLOB CONFIG_PROTO_FILES
|
||||||
|
"${CONFIG_PROTO_DIR}/filament.proto"
|
||||||
|
"${CONFIG_PROTO_DIR}/print.proto"
|
||||||
|
"${CONFIG_PROTO_DIR}/printer.proto"
|
||||||
|
)
|
||||||
|
set(CONFIG_PROTO_FILES
|
||||||
"${CONFIG_PROTO_DIR}/config_metadata.proto"
|
"${CONFIG_PROTO_DIR}/config_metadata.proto"
|
||||||
"${CONFIG_PROTO_GEN_DIR}/*.proto"
|
${CONFIG_PROTO_FILES}
|
||||||
)
|
)
|
||||||
|
|
||||||
if(PROTOC_EXECUTABLE AND Python3_EXECUTABLE)
|
if(Python3_EXECUTABLE)
|
||||||
# Step 1: Compile .proto files to descriptor set
|
# Single command: run_codegen.py handles protoc/grpcio-tools detection internally.
|
||||||
add_custom_command(
|
# Proto files → generated .cpp files. Runs automatically when any .proto changes.
|
||||||
OUTPUT ${CONFIG_DESC_FILE}
|
|
||||||
COMMAND ${PROTOC_EXECUTABLE}
|
|
||||||
--proto_path=${CONFIG_PROTO_DIR}
|
|
||||||
--proto_path=${CONFIG_PROTO_GEN_DIR}
|
|
||||||
--descriptor_set_out=${CONFIG_DESC_FILE}
|
|
||||||
--include_imports
|
|
||||||
${CONFIG_PROTO_FILES}
|
|
||||||
DEPENDS ${CONFIG_PROTO_FILES}
|
|
||||||
COMMENT "Compiling config .proto files to descriptor set"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
|
|
||||||
# Step 2: Generate C++ from descriptor set
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CONFIG_GENERATED_SOURCES}
|
OUTPUT ${CONFIG_GENERATED_SOURCES}
|
||||||
COMMAND ${Python3_EXECUTABLE} ${CODEGEN_TOOL}
|
COMMAND ${Python3_EXECUTABLE} ${RUN_CODEGEN_TOOL} --no-validate
|
||||||
${CONFIG_DESC_FILE}
|
DEPENDS ${CONFIG_PROTO_FILES} ${CONFIG_LAYOUT_YAML} ${CODEGEN_TOOL}
|
||||||
${CONFIG_CODEGEN_DIR}
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
DEPENDS ${CONFIG_DESC_FILE} ${CODEGEN_TOOL}
|
COMMENT "Re-generating config C++ from changed .proto files"
|
||||||
COMMENT "Generating C++ config code from proto descriptors"
|
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
# Named target for manual regeneration: cmake --build . --target codegen_config
|
# codegen_config is part of ALL — runs before every build, checks if protos changed.
|
||||||
add_custom_target(codegen_config
|
add_custom_target(codegen_config ALL
|
||||||
DEPENDS ${CONFIG_GENERATED_SOURCES}
|
DEPENDS ${CONFIG_GENERATED_SOURCES}
|
||||||
COMMENT "Config codegen complete"
|
COMMENT "Config codegen up to date"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validation target: cmake --build . --target validate_config
|
# Validation target: cmake --build . --target validate_config
|
||||||
@@ -77,12 +90,10 @@ if(PROTOC_EXECUTABLE AND Python3_EXECUTABLE)
|
|||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
message(STATUS "Config codegen: enabled (protoc=${PROTOC_EXECUTABLE})")
|
# Export for use by subdirectories (libslic3r, etc.)
|
||||||
|
set(CONFIG_GENERATED_SOURCES "${CONFIG_GENERATED_SOURCES}" CACHE INTERNAL "Generated config cpp files")
|
||||||
|
|
||||||
|
message(STATUS "Config codegen: enabled — proto changes auto-regenerate on next build")
|
||||||
else()
|
else()
|
||||||
if(NOT PROTOC_EXECUTABLE)
|
message(STATUS "Config codegen: Python3 not found — run: pip install grpcio-tools && python tools/run_codegen.py")
|
||||||
message(STATUS "Config codegen: disabled (protoc not found, using checked-in generated files)")
|
|
||||||
endif()
|
|
||||||
if(NOT Python3_EXECUTABLE)
|
|
||||||
message(STATUS "Config codegen: disabled (Python3 not found, using checked-in generated files)")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user