From 6f386239c43808a4a3207d62754999d400daea7e Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 29 Jan 2021 12:51:21 +0100 Subject: Fix openvdb configure process with unusable vdb_print --- cmake/modules/OpenVDBUtils.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/modules/OpenVDBUtils.cmake b/cmake/modules/OpenVDBUtils.cmake index f64eda6f2..f79862b83 100644 --- a/cmake/modules/OpenVDBUtils.cmake +++ b/cmake/modules/OpenVDBUtils.cmake @@ -157,7 +157,9 @@ function(OPENVDB_ABI_VERSION_FROM_PRINT OPENVDB_PRINT) endif() set(_OpenVDB_ABI) - string(REGEX REPLACE ".*abi([0-9]*).*" "\\1" _OpenVDB_ABI ${_VDB_PRINT_VERSION_STRING}) + if (_VDB_PRINT_VERSION_STRING) + string(REGEX REPLACE ".*abi([0-9]*).*" "\\1" _OpenVDB_ABI ${_VDB_PRINT_VERSION_STRING}) + endif () if(${_OpenVDB_ABI} STREQUAL ${_VDB_PRINT_VERSION_STRING}) set(_OpenVDB_ABI "") endif() -- cgit v1.2.3 From 4372191192119254f89a6e795e13509aabd7d9be Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 2 Feb 2021 18:08:30 +0100 Subject: Disable tests and encoding check when cross compiling --- CMakeLists.txt | 12 ++++++++++++ src/build-utils/CMakeLists.txt | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c15371c9a..c32fc6b7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,15 +35,27 @@ option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) set(SLIC3R_GTK "2" CACHE STRING "GTK version to use with wxWidgets on Linux") +set(IS_CROSS_COMPILE FALSE) + if (APPLE) set(CMAKE_FIND_FRAMEWORK LAST) set(CMAKE_FIND_APPBUNDLE LAST) + list(FIND CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR} _arch_idx) + if (CMAKE_OSX_ARCHITECTURES AND _arch_idx LESS 0) + set(IS_CROSS_COMPILE TRUE) + endif () endif () # Proposal for C++ unit tests and sandboxes option(SLIC3R_BUILD_SANDBOXES "Build development sandboxes" OFF) option(SLIC3R_BUILD_TESTS "Build unit tests" ON) +if (IS_CROSS_COMPILE) + message("Detected cross compilation setup. Tests and encoding checks will be forcedly disabled!") + set(SLIC3R_PERL_XS OFF CACHE BOOL "" FORCE) + set(SLIC3R_BUILD_TESTS OFF CACHE BOOL "" FORCE) +endif () + # Print out the SLIC3R_* cache options get_cmake_property(_cache_vars CACHE_VARIABLES) list (SORT _cache_vars) diff --git a/src/build-utils/CMakeLists.txt b/src/build-utils/CMakeLists.txt index d47e5b97f..464fd9c8f 100644 --- a/src/build-utils/CMakeLists.txt +++ b/src/build-utils/CMakeLists.txt @@ -1,6 +1,11 @@ option(SLIC3R_ENC_CHECK "Verify encoding of source files" 1) +if (IS_CROSS_COMPILE) + # Force disable due to cross compilation. This fact is already printed on cli for users + set(SLIC3R_ENC_CHECK OFF CACHE BOOL "" FORCE) +endif () + if (SLIC3R_ENC_CHECK) add_executable(encoding-check encoding-check.cpp) -- cgit v1.2.3 From 503def7710d4e2cb0fe8f848988d0812c7835910 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 26 Jan 2021 10:07:03 +0100 Subject: Replace avrdude conf generation from C to CMake code --- cmake/modules/bin2h.cmake | 89 ++++++++++++++++++++++++++++++++++++++++++++++ src/avrdude/CMakeLists.txt | 18 ++++------ src/avrdude/config.c | 2 +- 3 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 cmake/modules/bin2h.cmake diff --git a/cmake/modules/bin2h.cmake b/cmake/modules/bin2h.cmake new file mode 100644 index 000000000..b838650f3 --- /dev/null +++ b/cmake/modules/bin2h.cmake @@ -0,0 +1,89 @@ +# Source: https://gist.github.com/sivachandran/3a0de157dccef822a230#file-bin2h-cmake +# Added modifications to suit prusaslicer +include(CMakeParseArguments) + +# Function to wrap a given string into multiple lines at the given column position. +# Parameters: +# VARIABLE - The name of the CMake variable holding the string. +# AT_COLUMN - The column position at which string will be wrapped. +function(WRAP_STRING) + set(oneValueArgs VARIABLE AT_COLUMN) + cmake_parse_arguments(WRAP_STRING "${options}" "${oneValueArgs}" "" ${ARGN}) + + string(LENGTH ${${WRAP_STRING_VARIABLE}} stringLength) + math(EXPR offset "0") + + while(stringLength GREATER 0) + + if(stringLength GREATER ${WRAP_STRING_AT_COLUMN}) + math(EXPR length "${WRAP_STRING_AT_COLUMN}") + else() + math(EXPR length "${stringLength}") + endif() + + string(SUBSTRING ${${WRAP_STRING_VARIABLE}} ${offset} ${length} line) + set(lines "${lines}\n${line}") + + math(EXPR stringLength "${stringLength} - ${length}") + math(EXPR offset "${offset} + ${length}") + endwhile() + + set(${WRAP_STRING_VARIABLE} "${lines}" PARENT_SCOPE) +endfunction() + +# Function to embed contents of a file as byte array in C/C++ header file(.h). The header file +# will contain a byte array and integer variable holding the size of the array. +# Parameters +# SOURCE_FILE - The path of source file whose contents will be embedded in the header file. +# VARIABLE_NAME - The name of the variable for the byte array. The string "_SIZE" will be append +# to this name and will be used a variable name for size variable. +# HEADER_FILE - The path of header file. +# APPEND - If specified appends to the header file instead of overwriting it +# NULL_TERMINATE - If specified a null byte(zero) will be append to the byte array. This will be +# useful if the source file is a text file and we want to use the file contents +# as string. But the size variable holds size of the byte array without this +# null byte. +# Usage: +# bin2h(SOURCE_FILE "Logo.png" HEADER_FILE "Logo.h" VARIABLE_NAME "LOGO_PNG") +function(BIN2H) + set(options APPEND NULL_TERMINATE ADD_WARNING_TEXT) + set(oneValueArgs SOURCE_FILE VARIABLE_NAME HEADER_FILE) + cmake_parse_arguments(BIN2H "${options}" "${oneValueArgs}" "" ${ARGN}) + + # reads source file contents as hex string + file(READ ${BIN2H_SOURCE_FILE} hexString HEX) + string(LENGTH ${hexString} hexStringLength) + + # appends null byte if asked + if(BIN2H_NULL_TERMINATE) + set(hexString "${hexString}00") + endif() + + # wraps the hex string into multiple lines at column 32(i.e. 16 bytes per line) + wrap_string(VARIABLE hexString AT_COLUMN 32) + math(EXPR arraySize "${hexStringLength} / 2") + + # adds '0x' prefix and comma suffix before and after every byte respectively + string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " arrayValues ${hexString}) + # removes trailing comma + string(REGEX REPLACE ", $" "" arrayValues ${arrayValues}) + + # converts the variable name into proper C identifier + string(MAKE_C_IDENTIFIER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) + # string(TOUPPER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) + + # declares byte array and the length variables + set(arrayDefinition "const unsigned char ${BIN2H_VARIABLE_NAME}[] = { ${arrayValues} };") + set(arraySizeDefinition "const size_t ${BIN2H_VARIABLE_NAME}_SIZE = ${arraySize};") + set(warnTxt "") + if (BIN2H_ADD_WARNING_TEXT) + set(warnTxt "/* WARN: This file is auto-generated from ${BIN2H_SOURCE_FILE} */\n") + endif () + + set(declarations "${warnTxt}${arrayDefinition}\n\n${arraySizeDefinition}\n\n") + if(BIN2H_APPEND) + file(APPEND ${BIN2H_HEADER_FILE} "${declarations}") + else() + file(WRITE ${BIN2H_HEADER_FILE} "${declarations}") + endif() +endfunction() \ No newline at end of file diff --git a/src/avrdude/CMakeLists.txt b/src/avrdude/CMakeLists.txt index fc01b7d8d..091afc6f9 100644 --- a/src/avrdude/CMakeLists.txt +++ b/src/avrdude/CMakeLists.txt @@ -77,22 +77,16 @@ elseif (MINGW) ) endif() -add_executable(avrdude-conf-gen conf-generate.cpp) +include(bin2h) -# Config file embedding -add_custom_command( - DEPENDS avrdude-conf-gen ${CMAKE_CURRENT_SOURCE_DIR}/avrdude-slic3r.conf - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/avrdude-slic3r.conf.h - COMMAND $ avrdude-slic3r.conf avrdude_slic3r_conf ${CMAKE_CURRENT_BINARY_DIR}/avrdude-slic3r.conf.h - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_custom_target(gen_conf_h - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/avrdude-slic3r.conf.h +bin2h( + SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/avrdude-slic3r.conf + VARIABLE_NAME avrdude_slic3r_conf + HEADER_FILE ${CMAKE_CURRENT_BINARY_DIR}/avrdude-slic3r.conf.h + ADD_WARNING_TEXT ) add_library(avrdude STATIC ${AVRDUDE_SOURCES}) -add_dependencies(avrdude gen_conf_h) add_executable(avrdude-slic3r main-standalone.cpp) target_link_libraries(avrdude-slic3r avrdude) diff --git a/src/avrdude/config.c b/src/avrdude/config.c index b82fb29cb..c0ee9c25b 100644 --- a/src/avrdude/config.c +++ b/src/avrdude/config.c @@ -363,7 +363,7 @@ int read_config_builtin() // Note: Can't use yy_scan_buffer, it's buggy (?), leads to fread from a null FILE* // and so unfortunatelly we have to use the copying variant here - YY_BUFFER_STATE buffer = yy_scan_bytes((const char *)avrdude_slic3r_conf, avrdude_slic3r_conf_size); + YY_BUFFER_STATE buffer = yy_scan_bytes((const char *)avrdude_slic3r_conf, avrdude_slic3r_conf_SIZE); if (buffer == NULL) { avrdude_message(MSG_INFO, "%s: read_config_builtin: Failed to initialize parsing buffer\n", progname); return -1; -- cgit v1.2.3