### Install with Presets Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md To install the library after building with presets, specify an installation directory. ```bash cmake --preset default -DLibBGCode_BUILD_DEPS=ON -DCMAKE_INSTALL_PREFIX= cmake --build --preset default --target install ``` -------------------------------- ### Install Component Targets and Headers Source: https://github.com/prusa3d/libbgcode/blob/main/CMakeLists.txt Iterates through selected components to install their specific targets and headers. This ensures modular installation. ```cmake foreach(_comp ${_selected_components}) # Install targets and headers string(TOLOWER ${_comp} _comp_lower) set(_export_targets ${_libname}_${_comp_lower}) set_target_properties(${_libname}_${_comp_lower} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION}) install(TARGETS ${_export_targets} EXPORT ${PROJECT_NAME}${_comp}Targets INCLUDES DESTINATION include/${PROJECT_NAME} ) install(FILES ${_srcloc}/${_comp_lower}/${_comp_lower}.hpp DESTINATION include/${PROJECT_NAME}/${_comp_lower}) install(FILES ${PROJECT_BINARY_DIR}/${_comp_lower}/export.h DESTINATION include/${PROJECT_NAME}/${_comp_lower}/ ) install( EXPORT "${PROJECT_NAME}${_comp}Targets" NAMESPACE "${namespace}" DESTINATION "${CONFIG_INSTALL_DIR}" ) endforeach() ``` -------------------------------- ### Install Library Targets Source: https://github.com/prusa3d/libbgcode/blob/main/CMakeLists.txt Installs the library targets and headers. This is typically done once for the main library. ```cmake install(TARGETS ${_libname} EXPORT ${PROJECT_NAME}${_highest_comp}Targets INCLUDES DESTINATION include/${PROJECT_NAME} ) ``` -------------------------------- ### Configure and Install Package Configuration File Source: https://github.com/prusa3d/libbgcode/blob/main/CMakeLists.txt Configures the main package configuration file using a template and installs it. This file is essential for other projects to find and use this package. ```cmake configure_package_config_file( "cmake/Config.cmake.in" "${project_config}" INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}" NO_CHECK_REQUIRED_COMPONENTS_MACRO ) install( FILES "${project_config}" "${version_config}" DESTINATION "${CONFIG_INSTALL_DIR}" ) ``` -------------------------------- ### Install Executable for Non-Emscripten Builds Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/cmd/CMakeLists.txt Installs the built executable to the 'bin' directory and includes to 'include/' when not building for Emscripten. ```cmake if (NOT EMSCRIPTEN) install(TARGETS ${_libname}_cmd EXPORT ${PROJECT_NAME}ConvertTargets RUNTIME DESTINATION bin INCLUDES DESTINATION include/${PROJECT_NAME} ) else () target_link_libraries(${_libname}_cmd nodefs.js noderawfs.js) endif () ``` -------------------------------- ### Install WASM Executable and Related Files Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/CMakeLists.txt Installs the built WASM executable and its associated HTML file to the specified runtime and destination directories. This makes the WASM module available for deployment. ```cmake install(TARGETS ${_libname}_wasm EXPORT ${PROJECT_NAME}ConvertTargets RUNTIME DESTINATION lib/wasm INCLUDES DESTINATION include/${PROJECT_NAME} ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_libname}.wasm ${CMAKE_CURRENT_BINARY_DIR}/${_libname}.html DESTINATION lib/wasm # or wherever you want these files to be installed ) ``` -------------------------------- ### Set Convert Library Include Directories Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Configures the include directories for the convert library, specifying build-time and installation paths. ```cmake target_include_directories(${_libname}_convert PUBLIC $ $ $ $ ) ``` -------------------------------- ### Install Python Module Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Installs the '_bgcode' target as a Python module if 'PY_BUILD_CMAKE_MODULE_NAME' is defined. It also optionally installs the debug PDB file on Windows. ```cmake if (PY_BUILD_CMAKE_MODULE_NAME) # Install the Python module install(TARGETS _bgcode EXCLUDE_FROM_ALL COMPONENT python_modules DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME}) # Install the debug file for the Python module (Windows only) if (WIN32) install(FILES $ EXCLUDE_FROM_ALL COMPONENT python_modules DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME} OPTIONAL) endif () endif () ``` -------------------------------- ### Define Binarize Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/binarize/CMakeLists.txt Defines the Binarize library, specifying its source files and generating an export header. It also configures include directories for build and installation. ```cmake # Binarize component add_library(${_libname}_binarize binarize.cpp binarize.hpp meatpack.cpp meatpack.hpp ${PROJECT_BINARY_DIR}/version.rc # Add more source files here if needed ) add_library(${namespace}${_libname}_binarize ALIAS ${_libname}_binarize) generate_export_header(${_libname}_binarize EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/binarize/export.h ) target_include_directories(${_libname}_binarize PUBLIC $ $ $ $ ) ``` -------------------------------- ### Get File Name Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/index.html Extracts the base filename (without extension) from a file object. Converts the name to lowercase. ```javascript function getFileName(file) { const parts = file.name.split("."); var ret = ""; if (parts.length > 1) { ret = parts[0].toLowerCase(); } return ret; } ``` -------------------------------- ### Get File Extension Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/index.html Extracts the file extension from a file object. Handles cases with multiple dots in the filename. ```javascript function getFileExtension(file) { const parts = file.name.split("."); var ret = ""; if (parts.length > 1) { ret = parts[parts.length - 1].toLowerCase(); } return ret; } ``` -------------------------------- ### Quick Build with Presets Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md Use these commands for a fast build on any platform with default settings. Dependencies are built automatically. ```bash cmake --preset default -DLibBGCode_BUILD_DEPS=ON cmake --build --preset default ``` -------------------------------- ### Build Dependencies (Release) Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md Build the Release configuration for dependencies using CMake in the Visual Studio command prompt. ```bash c:\src\libbgcode\deps> mkdir build c:\src\libbgcode\deps> cd build c:\src\libbgcode\deps\build> cmake .. -G "Visual Studio 16 2019" -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release c:\src\libbgcode\deps\build> cmake --build . ``` -------------------------------- ### Build Python Bindings Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md Build the Python language bindings by running this command from the source directory. ```bash python -m pip install ./ ``` -------------------------------- ### Prepare Test Data Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Configures a test data file 'mini_cube_b_ref.gcode' to be available in the build directory for testing purposes. ```cmake enable_testing() set (TEST_DATA_DIR ${CMAKE_CURRENT_LIST_DIR}/../tests/data) # Prepare the test files to be available configure_file(${TEST_DATA_DIR}/mini_cube_b_ref.gcode ${CMAKE_CURRENT_BINARY_DIR}/test.gcode) ``` -------------------------------- ### Set Include Directories for Core Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Configures public include directories for the core library, specifying build-time and install-time paths. ```cmake target_include_directories(${_libname}_core PUBLIC $ $ $ $ ) ``` -------------------------------- ### Generate Visual Studio Project Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md Generate the Visual Studio solution file for libbgcode, referencing precompiled dependencies. Ensure CMAKE_PREFIX_PATH is an absolute path. ```bash c:\src\libbgcode> mkdir build c:\src\libbgcode> cd build c:\src\libbgcode\build> cmake -G "Visual Studio 16 2019" .. -A x64 -DCMAKE_PREFIX_PATH=C:\src\libbgcode\deps\build\destdir\usr\local -DCMAKE_INSTALL_PREFIX=C:\src\libbgcode\retail ``` -------------------------------- ### Initialize File Processing and Download Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/index.html Sets up event listeners for file upload, processing, and download. It handles the conversion between BGCode binary and ASCII formats using the LibBGCode WASM module. ```javascript document.addEventListener("DOMContentLoaded", function () { const uploadForm = document.getElementById("upload-form"); const fileInput = document.getElementById("file-input"); const processButton = document.getElementById("process-button"); const processingStatus = document.getElementById("processing-status"); const downloadLink = document.getElementById("download-link"); const downloadButton = document.getElementById("download-button"); var binaryGcode = null; var asciiGcode = null; var jsfile = null; processButton.addEventListener("click", function () { // Simulate processing by adding a timeout (replace with your actual processing logic) processingStatus.style.display = "block"; binaryGcode = null; asciiGcode = null; if (fileInput.files.length > 0) { jsfile = fileInput.files.item(0); let processAscii = function (data) { let config = Module.get_config(); config.compression.file_metadata = Module.BGCode_CompressionType.Heatshrink_11_4; let outbuf = Module.ascii2bgcode_cfg(data, config); binaryGcode = new Uint8Array(outbuf); } let processBinary = function (data) { asciiGcode = Module.bgcode2ascii_and_verify(data); } let processFn = getFileExtension(jsfile) === "bgcode" ? processBinary : processAscii; jsfile.arrayBuffer().then((data) => { processFn(data); processingStatus.style.display = "none"; downloadLink.style.display = "block"; }); } }); downloadButton.addEventListener("click", function () { var url = null; if (binaryGcode) { const blob = new Blob([binaryGcode], { type: "application/octet-stream" }); url = window.URL.createObjectURL(blob); downloadLink.download = getFileName(jsfile) + ".bgcode"; } else if (asciiGcode) { const blob = new Blob([asciiGcode], { type: "text/plain" }); url = window.URL.createObjectURL(blob); downloadLink.download = getFileName(jsfile) + ".gcode"; } // Set the href and click the link to trigger the download downloadLink.href = url; }); }); ``` -------------------------------- ### Build Dependencies (Debug) Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md Build the Debug configuration for dependencies using CMake in the Visual Studio command prompt. ```bash c:\src\libbgcode\deps\build> cmake .. -G "Visual Studio 16 2019" -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug c:\src\libbgcode\deps\build> cmake --build . ``` -------------------------------- ### Clone libbgcode Repository Source: https://github.com/prusa3d/libbgcode/blob/main/doc/building.md Clone the libbgcode repository to a local directory on Windows. ```bash c:> mkdir src c:> cd src c:\src> git clone https://github.com/prusa3d/libbgcode.git ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/cmd/CMakeLists.txt Defines the main executable target and links it with the libbgcode library and Boost.Nowide. Handles MSVC-specific configuration for Boost.Nowide. ```cmake add_executable(${_libname}_cmd main.cpp ) find_package(Boost ${Boost_VER} REQUIRED COMPONENTS nowide) if (MSVC) set_target_properties(Boost::nowide PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release) endif () set_target_properties(${_libname}_cmd PROPERTIES OUTPUT_NAME ${_libname}) target_link_libraries(${_libname}_cmd ${_libname}_convert Boost::nowide) ``` -------------------------------- ### Convert ASCII G-code to Binary with Default Settings Source: https://github.com/prusa3d/libbgcode/blob/main/doc/bgcode.md Convert an ASCII G-code file to binary format using the default compression and encoding settings. This is a simpler way to perform the conversion when custom parameters are not required. ```bash bgcode my_gcode.gcode ``` -------------------------------- ### Copy Source and Test Directories Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Copies the 'pybgcode' and 'tests' directories from the source to the binary directory. This is likely for build or testing convenience. ```cmake file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pybgcode DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Configure HTML File Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/CMakeLists.txt Configures the index.html file, copying it to the build directory. This is often used to serve the WASM module. ```cmake configure_file(index.html ${CMAKE_CURRENT_BINARY_DIR}/${_libname}.html) ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/prusa3d/libbgcode/blob/main/tests/convert/CMakeLists.txt Defines the 'convert_tests' executable and links it with required libraries including 'convert', 'test_common', and 'Boost::nowide'. ```cmake add_executable(convert_tests convert_tests.cpp) target_link_libraries(convert_tests ${_libname}_convert test_common Boost::nowide) ``` -------------------------------- ### Convert Binary G-code to ASCII Source: https://github.com/prusa3d/libbgcode/blob/main/doc/bgcode.md Use this command to convert a binary G-code file to its ASCII representation. A new .gcode file will be generated. ```bash bgcode my_gcode.bgcode ``` -------------------------------- ### Find and Link Dependencies Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/binarize/CMakeLists.txt Configures the build to find and link against heatshrink and ZLIB libraries. It conditionally appends these dependencies to a list if static libraries are being built. ```cmake set(Binarize_DOWNSTREAM_DEPS "") set(heatshrink_VER 0.4) set(ZLIB_VER 1.0) find_package(heatshrink ${heatshrink_VER} REQUIRED) find_package(ZLIB ${ZLIB_VER} REQUIRED) if (NOT BUILD_SHARED_LIBS) list(APPEND Binarize_DOWNSTREAM_DEPS "heatshrink_${heatshrink_VER}") list(APPEND Binarize_DOWNSTREAM_DEPS "ZLIB_${ZLIB_VER}") # append all the libs that are required privately for Core endif () ``` -------------------------------- ### Configure Convert Component Dependencies Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Sets up downstream dependencies for the convert component, conditionally adding Boost libraries if shared libraries are not being built. ```cmake set(Convert_DOWNSTREAM_DEPS "") set(Boost_VER 1.78) find_package(Boost ${Boost_VER} REQUIRED) if (NOT BUILD_SHARED_LIBS) list(APPEND Convert_DOWNSTREAM_DEPS "Boost_${Boost_VER}") # append all the libs that are required privately for Core endif () ``` -------------------------------- ### Convert ASCII G-code to Binary with Custom Settings Source: https://github.com/prusa3d/libbgcode/blob/main/doc/bgcode.md Convert an ASCII G-code file to binary format using specific compression and encoding settings. This command allows fine-tuning of the conversion process for different metadata and G-code blocks. ```bash bgcode my_gcode.gcode --slicer_metadata_compression=1 --gcode_compression=3 --gcode_encoding=2 ``` -------------------------------- ### Create Convert Library Alias Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Creates an alias for the convert library, allowing it to be referenced with a namespace prefix. ```cmake add_library(${namespace}${_libname}_convert ALIAS ${_libname}_convert) ``` -------------------------------- ### Add Core Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Defines the core library target, listing its source files and generated version resource. ```cmake add_library(${_libname}_core core.cpp core.hpp core_impl.hpp ${PROJECT_BINARY_DIR}/version.rc # Add more source files here if needed ) ``` -------------------------------- ### Define Convert Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Defines the static library for the convert component, listing its source files and generated resource file. ```cmake # Convert component add_library(${_libname}_convert convert.cpp convert.hpp ${PROJECT_BINARY_DIR}/version.rc # Add more source files here if needed ) ``` -------------------------------- ### Discover Core Tests with Catch2 Source: https://github.com/prusa3d/libbgcode/blob/main/tests/core/CMakeLists.txt Configures Catch2 to discover and run tests for the 'core_tests' executable, passing any extra arguments. This command is essential for integrating Catch2's testing framework into the build process. ```cmake catch_discover_tests(core_tests EXTRA_ARGS ${CATCH_EXTRA_ARGS}) ``` -------------------------------- ### Add Build and Test Target Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Creates a custom target 'build_and_test' that depends on the '_bgcode' target and executes 'ctest --verbose'. This allows building the module and running tests with a single command. ```cmake add_custom_target(build_and_test COMMAND ${CMAKE_CTEST_COMMAND} --verbose DEPENDS _bgcode) ``` -------------------------------- ### Link Libraries for Binarize Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/binarize/CMakeLists.txt Links the Binarize library against necessary private and public dependencies, including heatshrink, ZLIB, and the core library. ```cmake target_link_libraries(${_libname}_binarize PRIVATE heatshrink::heatshrink_dynalloc ZLIB::ZLIB) target_link_libraries(${_libname}_binarize PUBLIC ${_libname}_core) ``` -------------------------------- ### Link System libbgcode Option Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Defines an option to control whether to link against a system-installed libbgcode. Defaults to ON. ```cmake option(PyBGCode_LINK_SYSTEM_LIBBGCODE "Link libbgcode installed in the system" ON) ``` -------------------------------- ### Generate Package Version File Source: https://github.com/prusa3d/libbgcode/blob/main/CMakeLists.txt Creates a basic package version file required for CMake's package management system. Ensures version compatibility. ```cmake write_basic_package_version_file( "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) ``` -------------------------------- ### Link Libraries and Compile Definitions Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Links the '_bgcode' target with 'LibBGCode::bgcode_convert' and 'Boost::nowide'. It also sets compile definitions for the module name and version. ```cmake target_link_libraries(_bgcode PRIVATE LibBGCode::bgcode_convert Boost::nowide) target_compile_definitions(_bgcode PRIVATE MODULE_NAME=$ VERSION_INFO="${PY_FULL_VERSION}" ) ``` -------------------------------- ### Set C++ Standard Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Configures the C++ standard to C++17 for the project. Ensures the standard is required. ```cmake set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) ``` -------------------------------- ### Find Required Python and pybind11 Packages Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Finds the required Python 3 interpreter and development headers, as well as the pybind11 package. These are essential for building the Python extension. ```cmake find_package(Python3 REQUIRED COMPONENTS Interpreter Development) find_package(pybind11 REQUIRED) ``` -------------------------------- ### Default libbgcode Subproject Options Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Sets default options for the libbgcode subproject, controlling the build of command-line tools, tests, and dependencies. LibBGCode_DEPS_PRESET is set to 'python-module'. ```cmake option(LibBGCode_BUILD_CMD_TOOL "" OFF) option(LibBGCode_BUILD_TESTS "" OFF) option(LibBGCode_BUILD_DEPS "" ON) set(LibBGCode_DEPS_PRESET "python-module" CACHE STRING "" ) ``` -------------------------------- ### Set Target Properties for Visibility and Output Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Configures target properties for the '_bgcode' module, setting C++ visibility to 'hidden' and enabling 'VISIBILITY_INLINES_HIDDEN'. It also specifies the library output directory. ```cmake set_target_properties(_bgcode PROPERTIES CXX_VISIBILITY_PRESET "hidden" VISIBILITY_INLINES_HIDDEN true LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pybgcode) if (CMAKE_SYSTEM_NAME MATCHES "Linux") target_link_options(_bgcode PRIVATE "LINKER:--exclude-libs,ALL") endif() ``` -------------------------------- ### Link Libraries for Convert Component Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Links the convert library to its required public and private dependencies, including other internal libraries and Boost. ```cmake target_link_libraries(${_libname}_convert PUBLIC ${_libname}_binarize ${_libname}_core) target_link_libraries(${_libname}_convert PRIVATE Boost::boost) ``` -------------------------------- ### Link Libraries and Set Target Options Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/CMakeLists.txt Links the WASM executable to required libraries like 'bgcode_convert' and 'embind'. It also sets WASM-specific linker options, such as total memory allocation. ```cmake target_link_libraries(${_libname}_wasm bgcode_convert embind) target_link_options(${_libname}_wasm PUBLIC -s TOTAL_MEMORY=512MB # -sEXPORTED_RUNTIME_METHODS=stringToNewUTF8,FS # -sEXPORTED_FUNCTIONS=_free ) ``` -------------------------------- ### Configure Sanitizers for Core Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Conditionally adds compiler and linker options for AddressSanitizer (ASan) based on the compiler and build configuration. ```cmake if (${PROJECT_NAME}_BUILD_SANITIZERS) if (CMAKE_COMPILER_IS_GNUCC) target_compile_options(${_libname}_core PUBLIC -g -Wstrict-aliasing -fsanitize=address ) target_link_options(${_libname}_core PUBLIC -fsanitize=address) elseif (MSVC) target_compile_options(${_libname}_core PUBLIC /fsanitize=address /Zi) target_link_options(${_libname}_core PUBLIC /DEBUG) endif () endif () ``` -------------------------------- ### Discover Tests with CTest Source: https://github.com/prusa3d/libbgcode/blob/main/tests/convert/CMakeLists.txt Configures CTest to discover and run tests for the 'convert_tests' executable, passing any extra arguments. ```cmake catch_discover_tests(convert_tests EXTRA_ARGS ${CATCH_EXTRA_ARGS}) ``` -------------------------------- ### Discover Binarize Tests with CTest Source: https://github.com/prusa3d/libbgcode/blob/main/tests/binarize/CMakeLists.txt Configures CTest to discover and run tests for the binarize_tests executable, passing any extra arguments. ```cmake catch_discover_tests(binarize_tests EXTRA_ARGS ${CATCH_EXTRA_ARGS}) ``` -------------------------------- ### Define Binarize Test Executable Source: https://github.com/prusa3d/libbgcode/blob/main/tests/binarize/CMakeLists.txt Defines the executable for the binarize tests and specifies its source file. ```cmake add_executable(binarize_tests binarize_tests.cpp) ``` -------------------------------- ### Link Core Tests with Libraries Source: https://github.com/prusa3d/libbgcode/blob/main/tests/core/CMakeLists.txt Links the 'core_tests' executable against the '_libname_core' and 'test_common' libraries. This ensures that the test executable has access to the necessary code from these libraries. ```cmake target_link_libraries(core_tests ${_libname}_core test_common) ``` -------------------------------- ### Link Binarize Tests Libraries Source: https://github.com/prusa3d/libbgcode/blob/main/tests/binarize/CMakeLists.txt Links the binarize tests executable against necessary libraries, including a specific libname binarize library and a test_common library. ```cmake target_link_libraries(binarize_tests ${_libname}_binarize test_common) ``` -------------------------------- ### BGCode Encoding Types Source: https://github.com/prusa3d/libbgcode/blob/main/doc/specifications.md Defines the possible values for the `Encoding` parameter in BGCode. Use `0` for no encoding, `1` for the standard MeatPack algorithm, or `2` for a modified MeatPack algorithm that preserves comment lines. ```text 0 = No encoding 1 = MeatPack algorithm 2 = MeatPack algorithm modified to keep comment lines ``` -------------------------------- ### Define Core Tests Executable Source: https://github.com/prusa3d/libbgcode/blob/main/tests/core/CMakeLists.txt Defines the 'core_tests' executable and specifies its source file. This is a standard CMake command for building executables. ```cmake add_executable(core_tests core_tests.cpp) ``` -------------------------------- ### Thumbnail Format Values Source: https://github.com/prusa3d/libbgcode/blob/main/doc/specifications.md Lists the possible values for the Format parameter in the Thumbnail block, indicating the image encoding. ```plaintext 0 = PNG format 1 = JPG format 2 = QOI format ``` -------------------------------- ### Version Matching Check Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Ensures that the project version defined in CMake matches the version expected by the Python build system. If they do not match, the build fails with a fatal error. ```cmake if (DEFINED PY_BUILD_CMAKE_PACKAGE_VERSION) if (NOT "${PY_BUILD_CMAKE_PACKAGE_VERSION}" MATCHES "^${PY_FULL_VERSION}$") message(FATAL_ERROR "Version number does not match " "(${PY_BUILD_CMAKE_PACKAGE_VERSION} - ${PY_FULL_VERSION}).") endif() endif() ``` -------------------------------- ### Generate Export Header Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Generates an export header file for the convert library, specifying the export file name. ```cmake generate_export_header(${_libname}_convert EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/convert/export.h ) ``` -------------------------------- ### Define Python Module Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Defines the Python extension module '_bgcode' using pybind11. The source file for the module is 'pybgcode.cpp'. ```cmake pybind11_add_module(_bgcode MODULE pybgcode.cpp) ``` -------------------------------- ### Define WASM Executable and Properties Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/wasm/CMakeLists.txt Defines the WASM executable target and sets its output name. This is the primary step in building the WASM module. ```cmake add_executable(${_libname}_wasm bgcode_wa.cpp index.html) set_target_properties(${_libname}_wasm PROPERTIES OUTPUT_NAME ${_libname}) ``` -------------------------------- ### Create Alias for Core Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Creates an alias target for the core library, allowing it to be referenced by a potentially different name within the build system. ```cmake add_library(${namespace}${_libname}_core ALIAS ${_libname}_core) ``` -------------------------------- ### Compression Algorithm Values Source: https://github.com/prusa3d/libbgcode/blob/main/doc/specifications.md Specifies the possible values for the Compression field in the block header, indicating the compression method used for the block data. ```plaintext 0 = No compression 1 = Deflate algorithm 2 = Heatshrink algorithm with window size 11 and lookahead size 4 3 = Heatshrink algorithm with window size 12 and lookahead size 4 ``` -------------------------------- ### Generate Export Header for Core Library Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Generates an export header file for the core library, typically used for managing symbol visibility across different platforms. ```cmake generate_export_header(${_libname}_core EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/core/export.h ) ``` -------------------------------- ### Find Boost Package Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Finds the Boost library, specifically requiring the 'nowide' component. This is necessary for using Boost functionalities within the project. ```cmake find_package(Boost ${Boost_VER} REQUIRED COMPONENTS nowide) ``` -------------------------------- ### Export Convert Downstream Dependencies Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/convert/CMakeLists.txt Exports the list of downstream dependencies for the convert component to the parent scope. ```cmake set(Convert_DOWNSTREAM_DEPS ${Convert_DOWNSTREAM_DEPS} PARENT_SCOPE) ``` -------------------------------- ### Checksum Type Values Source: https://github.com/prusa3d/libbgcode/blob/main/doc/specifications.md Defines the possible values for the Checksum type field in the file header. ```plaintext 0 = None 1 = CRC32 ``` -------------------------------- ### Set Core Library Version Definition Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Adds a private compile definition to the core library target, embedding the LibBGCode version. ```cmake target_compile_definitions(${_libname}_core PRIVATE LibBGCode_VERSION=R"(${LibBGCode_VERSION})") ``` -------------------------------- ### Conditional libbgcode Subdirectory Inclusion Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Conditionally includes the libbgcode subdirectory based on the PyBGCode_LINK_SYSTEM_LIBBGCODE option. If linking to a system library, it finds the package; otherwise, it adds the subdirectory. ```cmake if (PyBGCode_LINK_SYSTEM_LIBBGCODE) find_package(LibBGCode REQUIRED COMPONENTS Convert) else () set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/upstream) endif () ``` -------------------------------- ### Block Type Values Source: https://github.com/prusa3d/libbgcode/blob/main/doc/specifications.md Lists the possible values for the Type field in the block header, indicating the kind of data within the block. ```plaintext 0 = File Metadata Block 1 = GCode Block 2 = Slicer Metadata Block 3 = Printer Metadata Block 4 = Print Metadata Block 5 = Thumbnail Block ``` -------------------------------- ### Define PyBGCode Test with CTest Source: https://github.com/prusa3d/libbgcode/blob/main/pybgcode/CMakeLists.txt Defines a CTest test named 'test_pybgcode' that runs pytest. It sets the working directory and injects the PYTHONPATH environment variable to ensure the Python module can be found at runtime. ```cmake # Define the test for ctest and inject the correct PYTHONPATH env var for its runtime add_test(NAME test_pybgcode COMMAND ${Python3_EXECUTABLE} -m pytest -v tests/test_convert.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES}) #$: #set_property(TEST test_pybgcode PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Propagate Core Downstream Dependencies Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/core/CMakeLists.txt Sets a variable to include the core library's downstream dependencies in the parent scope. ```cmake set(Core_DOWNSTREAM_DEPS ${Core_DOWNSTREAM_DEPS} PARENT_SCOPE) ``` -------------------------------- ### Export Downstream Dependencies Source: https://github.com/prusa3d/libbgcode/blob/main/src/LibBGCode/binarize/CMakeLists.txt Sets the Binarize_DOWNSTREAM_DEPS variable to be available in the parent scope, ensuring downstream projects can access these dependencies. ```cmake set(Binarize_DOWNSTREAM_DEPS ${Binarize_DOWNSTREAM_DEPS} PARENT_SCOPE) ``` -------------------------------- ### Encoding Type Values Source: https://github.com/prusa3d/libbgcode/blob/main/doc/specifications.md Defines the possible values for the Encoding parameter in various metadata blocks, specifying the format of the key-value pairs. ```plaintext 0 = INI encoding ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.