From 0df9b782bb142c4d954de3fe515cf3be79c5b6df Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Wed, 14 Oct 2026 15:36:54 -0500 Subject: [PATCH] Remove unused CMake modules (#16452) * Remove unused CMake modules FindAlienWx.cmake and FindPerlEmbed.cmake came over from the Slic3r Perl build. Nothing calls find_package(AlienWx) or find_package(PerlEmbed). LibFindMacros.cmake was only included by those two modules. bin2h.cmake lost its last caller when the avrdude sources were removed in e6fcbfae07. * ci: build changes under cmake/ The Build all path filters did not include cmake/, so a change to a find module or to ClangClShowIncludes.cmake ran no build on a pull request or on a push to main. --- .github/workflows/build_all.yml | 2 + cmake/modules/FindAlienWx.cmake | 109 ------------ cmake/modules/FindPerlEmbed.cmake | 88 ---------- cmake/modules/LibFindMacros.cmake | 265 ------------------------------ cmake/modules/bin2h.cmake | 89 ---------- 5 files changed, 2 insertions(+), 551 deletions(-) delete mode 100644 cmake/modules/FindAlienWx.cmake delete mode 100644 cmake/modules/FindPerlEmbed.cmake delete mode 100644 cmake/modules/LibFindMacros.cmake delete mode 100644 cmake/modules/bin2h.cmake diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index 8fa7901623..ff07d1efb7 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -8,6 +8,7 @@ on: paths: - 'deps/**' - 'deps_src/**' + - 'cmake/**' - 'src/**' - '**/CMakeLists.txt' - 'version.inc' @@ -31,6 +32,7 @@ on: paths: - 'deps/**' - 'deps_src/**' + - 'cmake/**' - 'src/**' - '**/CMakeLists.txt' - 'version.inc' diff --git a/cmake/modules/FindAlienWx.cmake b/cmake/modules/FindAlienWx.cmake deleted file mode 100644 index 65221172be..0000000000 --- a/cmake/modules/FindAlienWx.cmake +++ /dev/null @@ -1,109 +0,0 @@ -# Find the wxWidgets module based on the information provided by the Perl Alien::wxWidgets module. - -# Check for the Perl & PerlLib modules -include(LibFindMacros) -libfind_package(AlienWx Perl) -libfind_package(AlienWx PerlLibs) - -if (AlienWx_DEBUG) - message(STATUS " AlienWx_FIND_COMPONENTS=${AlienWx_FIND_COMPONENTS}") -endif() - -# Execute an Alien::Wx module to find the relevant information regarding -# the wxWidgets used by the Perl interpreter. -# Perl specific stuff -set(AlienWx_TEMP_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/AlienWx_TEMP_INCLUDE.txt) -execute_process( - COMMAND ${PERL_EXECUTABLE} -e " -# Import Perl modules. -use strict; -use warnings; -use Text::ParseWords; - -BEGIN { - # CMake sets the environment variables CC and CXX to the detected C compiler. - # There is an issue with the Perl ExtUtils::CBuilder, which does not handle whitespaces - # in the paths correctly on Windows, so we rather drop the CMake auto-detected paths. - delete \$ENV{CC}; - delete \$ENV{CXX}; -} - -use Alien::wxWidgets; -use ExtUtils::CppGuess; - -# Test for a Visual Studio compiler -my \$cpp_guess = ExtUtils::CppGuess->new; -my \$mswin = \$^O eq 'MSWin32'; -my \$msvc = \$cpp_guess->is_msvc; - -# List of wxWidgets components to be used. -my @components = split /;/, '${AlienWx_FIND_COMPONENTS}'; - -# Query the available data from Alien::wxWidgets. -my \$version = Alien::wxWidgets->version; -my \$config = Alien::wxWidgets->config; -my \$compiler = Alien::wxWidgets->compiler; -my \$linker = Alien::wxWidgets->linker; -my \$include_path = ' ' . Alien::wxWidgets->include_path; -my \$defines = ' ' . Alien::wxWidgets->defines; -my \$cflags = Alien::wxWidgets->c_flags; -my \$linkflags = Alien::wxWidgets->link_flags; -my \$libraries = ' ' . Alien::wxWidgets->libraries(@components); -my \$gui_toolkit = Alien::wxWidgets->config->{toolkit}; -#my @libraries = Alien::wxWidgets->link_libraries(@components); -#my @implib = Alien::wxWidgets->import_libraries(@components); -#my @shrlib = Alien::wxWidgets->shared_libraries(@components); -#my @keys = Alien::wxWidgets->library_keys; # 'gl', 'adv', ... -#my \$library_path = Alien::wxWidgets->shared_library_path; -#my \$key = Alien::wxWidgets->key; -#my \$prefix = Alien::wxWidgets->prefix; - -my \$filename = '${AlienWx_TEMP_INCLUDE}'; -open(my $fh, '>', \$filename) or die \"Could not open file '\$filename' \$!\"; - -# Convert a space separated lists to CMake semicolon separated lists, -# escape the backslashes, -# export the resulting list to a temp file. -sub cmake_set_var { - my (\$varname, \$content) = @_; - # Remove line separators. - \$content =~ s/\\r|\\n//g; - # Escape the path separators. - \$content =~ s/\\\\/\\\\\\\\\\\\\\\\/g; - my @words = shellwords(\$content); - print \$fh \"set(AlienWx_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\"; -} -cmake_set_var('VERSION', \$version); -\$include_path =~ s/ -I/ /g; -cmake_set_var('INCLUDE_DIRS', \$include_path); -\$libraries =~ s/ -L/ -LIBPATH:/g if \$msvc; -cmake_set_var('LIBRARIES', \$libraries); -#cmake_set_var('LIBRARY_DIRS', ); -#\$defines =~ s/ -D/ /g; -cmake_set_var('DEFINITIONS', \$defines); -#cmake_set_var('DEFINITIONS_DEBUG', ); -cmake_set_var('CXX_FLAGS', \$cflags); -cmake_set_var('GUI_TOOLKIT', \$gui_toolkit); -close \$fh; -") -include(${AlienWx_TEMP_INCLUDE}) -file(REMOVE ${AlienWx_TEMP_INCLUDE}) -unset(AlienWx_TEMP_INCLUDE) - -if (AlienWx_DEBUG) - message(STATUS " AlienWx_VERSION = ${AlienWx_VERSION}") - message(STATUS " AlienWx_INCLUDE_DIRS = ${AlienWx_INCLUDE_DIRS}") - message(STATUS " AlienWx_LIBRARIES = ${AlienWx_LIBRARIES}") - message(STATUS " AlienWx_LIBRARY_DIRS = ${AlienWx_LIBRARY_DIRS}") - message(STATUS " AlienWx_DEFINITIONS = ${AlienWx_DEFINITIONS}") - message(STATUS " AlienWx_DEFINITIONS_DEBUG = ${AlienWx_DEFINITIONS_DEBUG}") - message(STATUS " AlienWx_CXX_FLAGS = ${AlienWx_CXX_FLAGS}") - message(STATUS " AlienWx_GUI_TOOLKIT = ${AlienWx_GUI_TOOLKIT}") -endif() - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(AlienWx - REQUIRED_VARS AlienWx_INCLUDE_DIRS AlienWx_LIBRARIES -# HANDLE_COMPONENTS - VERSION_VAR AlienWx_VERSION) diff --git a/cmake/modules/FindPerlEmbed.cmake b/cmake/modules/FindPerlEmbed.cmake deleted file mode 100644 index b12fc40634..0000000000 --- a/cmake/modules/FindPerlEmbed.cmake +++ /dev/null @@ -1,88 +0,0 @@ -# Find the dependencies for linking with the Perl runtime library. - -# Check for the Perl & PerlLib modules -include(LibFindMacros) -libfind_package(PerlEmbed Perl) -libfind_package(PerlEmbed PerlLibs) - -# Execute an Alien::Wx module to find the relevant information regarding -# the wxWidgets used by the Perl interpreter. -# Perl specific stuff -set(PerlEmbed_TEMP_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/PerlEmbed_TEMP_INCLUDE.txt) -execute_process( - COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e " -# Import Perl modules. -use strict; -use warnings; -use Config; -use Text::ParseWords; -use ExtUtils::CppGuess; - -# Test for a Visual Studio compiler -my \$cpp_guess = ExtUtils::CppGuess->new; -my \$mswin = \$^O eq 'MSWin32'; -my \$msvc = \$cpp_guess->is_msvc; - -# Query the available data from Alien::wxWidgets. -my \$ccflags; -my \$ldflags; -{ local *STDOUT; open STDOUT, '>', \\\$ccflags; ccflags; } -{ local *STDOUT; open STDOUT, '>', \\\$ldflags; ldopts; } -\$ccflags = ' ' . \$ccflags; -\$ldflags = ' ' . \$ldflags; - -my \$filename = '${PerlEmbed_TEMP_INCLUDE}'; -open(my $fh, '>', \$filename) or die \"Could not open file '\$filename' \$!\"; - -# Convert a space separated lists to CMake semicolon separated lists, -# escape the backslashes, -# export the resulting list to a temp file. -sub cmake_set_var { - my (\$varname, \$content) = @_; - # Remove line separators. - \$content =~ s/\\r|\\n//g; - # Escape the path separators. - \$content =~ s/\\\\/\\\\\\\\\\\\\\\\/g; - my @words = shellwords(\$content); - print \$fh \"set(PerlEmbed_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\"; -} -cmake_set_var('ARCHNAME', \$Config{archname}); -cmake_set_var('CCFLAGS', \$ccflags); -\$ldflags =~ s/ -L/ -LIBPATH:/g if \$msvc; -cmake_set_var('LD', \$Config{ld}); -cmake_set_var('LDFLAGS', \$ldflags); -cmake_set_var('CCCDLFLAGS', \$Config{cccdlflags}); -cmake_set_var('LDDLFLAGS', \$Config{lddlflags}); -cmake_set_var('DLEXT', \$Config{dlext}); -close \$fh; -") -include(${PerlEmbed_TEMP_INCLUDE}) -file(REMOVE ${PerlEmbed_TEMP_INCLUDE}) -unset(PerlEmbed_TEMP_INCLUDE) - -if (PerlEmbed_DEBUG) - # First show the configuration extracted by FindPerl & FindPerlLibs: - message(STATUS " PERL_INCLUDE_PATH = ${PERL_INCLUDE_PATH}") - message(STATUS " PERL_LIBRARY = ${PERL_LIBRARY}") - message(STATUS " PERL_EXECUTABLE = ${PERL_EXECUTABLE}") - message(STATUS " PERL_SITESEARCH = ${PERL_SITESEARCH}") - message(STATUS " PERL_SITELIB = ${PERL_SITELIB}") - message(STATUS " PERL_VENDORARCH = ${PERL_VENDORARCH}") - message(STATUS " PERL_VENDORLIB = ${PERL_VENDORLIB}") - message(STATUS " PERL_ARCHLIB = ${PERL_ARCHLIB}") - message(STATUS " PERL_PRIVLIB = ${PERL_PRIVLIB}") - message(STATUS " PERL_EXTRA_C_FLAGS = ${PERL_EXTRA_C_FLAGS}") - # Second show the configuration extracted by this module (FindPerlEmbed): - message(STATUS " PerlEmbed_ARCHNAME = ${PerlEmbed_ARCHNAME}") - message(STATUS " PerlEmbed_CCFLAGS = ${PerlEmbed_CCFLAGS}") - message(STATUS " PerlEmbed_CCCDLFLAGS = ${PerlEmbed_CCCDLFLAGS}") - message(STATUS " LD = ${PerlEmbed_LD}") - message(STATUS " PerlEmbed_LDFLAGS = ${PerlEmbed_LDFLAGS}") - message(STATUS " PerlEmbed_LDDLFLAGS = ${PerlEmbed_LDDLFLAGS}") -endif() - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(PerlEmbed - REQUIRED_VARS PerlEmbed_CCFLAGS PerlEmbed_LDFLAGS - VERSION_VAR PERL_VERSION) diff --git a/cmake/modules/LibFindMacros.cmake b/cmake/modules/LibFindMacros.cmake deleted file mode 100644 index f6800aa7bd..0000000000 --- a/cmake/modules/LibFindMacros.cmake +++ /dev/null @@ -1,265 +0,0 @@ -# Version 2.2 -# Public Domain, originally written by Lasse Kärkkäinen -# Maintained at https://github.com/Tronic/cmake-modules -# Please send your improvements as pull requests on Github. - -# Find another package and make it a dependency of the current package. -# This also automatically forwards the "REQUIRED" argument. -# Usage: libfind_package( [extra args to find_package]) -macro (libfind_package PREFIX PKG) - set(${PREFIX}_args ${PKG} ${ARGN}) - if (${PREFIX}_FIND_REQUIRED) - set(${PREFIX}_args ${${PREFIX}_args} REQUIRED) - endif() - find_package(${${PREFIX}_args}) - set(${PREFIX}_DEPENDENCIES ${${PREFIX}_DEPENDENCIES};${PKG}) - unset(${PREFIX}_args) -endmacro() - -# A simple wrapper to make pkg-config searches a bit easier. -# Works the same as CMake's internal pkg_check_modules but is always quiet. -macro (libfind_pkg_check_modules) - find_package(PkgConfig QUIET) - if (PKG_CONFIG_FOUND) - pkg_check_modules(${ARGN} QUIET) - endif() -endmacro() - -# Avoid useless copy&pasta by doing what most simple libraries do anyway: -# pkg-config, find headers, find library. -# Usage: libfind_pkg_detect( FIND_PATH [other args] FIND_LIBRARY [other args]) -# E.g. libfind_pkg_detect(SDL2 sdl2 FIND_PATH SDL.h PATH_SUFFIXES SDL2 FIND_LIBRARY SDL2) -function (libfind_pkg_detect PREFIX) - # Parse arguments - set(argname pkgargs) - foreach (i ${ARGN}) - if ("${i}" STREQUAL "FIND_PATH") - set(argname pathargs) - elseif ("${i}" STREQUAL "FIND_LIBRARY") - set(argname libraryargs) - else() - set(${argname} ${${argname}} ${i}) - endif() - endforeach() - if (NOT pkgargs) - message(FATAL_ERROR "libfind_pkg_detect requires at least a pkg_config package name to be passed.") - endif() - # Find library - libfind_pkg_check_modules(${PREFIX}_PKGCONF ${pkgargs}) - if (pathargs) - find_path(${PREFIX}_INCLUDE_DIR NAMES ${pathargs} HINTS ${${PREFIX}_PKGCONF_INCLUDE_DIRS}) - endif() - if (libraryargs) - find_library(${PREFIX}_LIBRARY NAMES ${libraryargs} HINTS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}) - endif() -endfunction() - -# Extracts a version #define from a version.h file, output stored to _VERSION. -# Usage: libfind_version_header(Foobar foobar/version.h FOOBAR_VERSION_STR) -# Fourth argument "QUIET" may be used for silently testing different define names. -# This function does nothing if the version variable is already defined. -function (libfind_version_header PREFIX VERSION_H DEFINE_NAME) - # Skip processing if we already have a version or if the include dir was not found - if (${PREFIX}_VERSION OR NOT ${PREFIX}_INCLUDE_DIR) - return() - endif() - set(quiet ${${PREFIX}_FIND_QUIETLY}) - # Process optional arguments - foreach(arg ${ARGN}) - if (arg STREQUAL "QUIET") - set(quiet TRUE) - else() - message(AUTHOR_WARNING "Unknown argument ${arg} to libfind_version_header ignored.") - endif() - endforeach() - # Read the header and parse for version number - set(filename "${${PREFIX}_INCLUDE_DIR}/${VERSION_H}") - if (NOT EXISTS ${filename}) - if (NOT quiet) - message(AUTHOR_WARNING "Unable to find ${${PREFIX}_INCLUDE_DIR}/${VERSION_H}") - endif() - return() - endif() - file(READ "${filename}" header) - string(REGEX REPLACE ".*#[ \t]*define[ \t]*${DEFINE_NAME}[ \t]*\"([^\n]*)\".*" "\\1" match "${header}") - # No regex match? - if (match STREQUAL header) - if (NOT quiet) - message(AUTHOR_WARNING "Unable to find \#define ${DEFINE_NAME} \"\" from ${${PREFIX}_INCLUDE_DIR}/${VERSION_H}") - endif() - return() - endif() - # Export the version string - set(${PREFIX}_VERSION "${match}" PARENT_SCOPE) -endfunction() - -# Do the final processing once the paths have been detected. -# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain -# all the variables, each of which contain one include directory. -# Ditto for ${PREFIX}_PROCESS_LIBS and library files. -# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. -# Also handles errors in case library detection was required, etc. -function (libfind_process PREFIX) - # Skip processing if already processed during this configuration run - if (${PREFIX}_FOUND) - return() - endif() - - set(found TRUE) # Start with the assumption that the package was found - - # Did we find any files? Did we miss includes? These are for formatting better error messages. - set(some_files FALSE) - set(missing_headers FALSE) - - # Shorthands for some variables that we need often - set(quiet ${${PREFIX}_FIND_QUIETLY}) - set(required ${${PREFIX}_FIND_REQUIRED}) - set(exactver ${${PREFIX}_FIND_VERSION_EXACT}) - set(findver "${${PREFIX}_FIND_VERSION}") - set(version "${${PREFIX}_VERSION}") - - # Lists of config option names (all, includes, libs) - unset(configopts) - set(includeopts ${${PREFIX}_PROCESS_INCLUDES}) - set(libraryopts ${${PREFIX}_PROCESS_LIBS}) - - # Process deps to add to - foreach (i ${PREFIX} ${${PREFIX}_DEPENDENCIES}) - if (DEFINED ${i}_INCLUDE_OPTS OR DEFINED ${i}_LIBRARY_OPTS) - # The package seems to export option lists that we can use, woohoo! - list(APPEND includeopts ${${i}_INCLUDE_OPTS}) - list(APPEND libraryopts ${${i}_LIBRARY_OPTS}) - else() - # If plural forms don't exist or they equal singular forms - if ((NOT DEFINED ${i}_INCLUDE_DIRS AND NOT DEFINED ${i}_LIBRARIES) OR - ({i}_INCLUDE_DIR STREQUAL ${i}_INCLUDE_DIRS AND ${i}_LIBRARY STREQUAL ${i}_LIBRARIES)) - # Singular forms can be used - if (DEFINED ${i}_INCLUDE_DIR) - list(APPEND includeopts ${i}_INCLUDE_DIR) - endif() - if (DEFINED ${i}_LIBRARY) - list(APPEND libraryopts ${i}_LIBRARY) - endif() - else() - # Oh no, we don't know the option names - message(FATAL_ERROR "We couldn't determine config variable names for ${i} includes and libs. Aieeh!") - endif() - endif() - endforeach() - - if (includeopts) - list(REMOVE_DUPLICATES includeopts) - endif() - - if (libraryopts) - list(REMOVE_DUPLICATES libraryopts) - endif() - - string(REGEX REPLACE ".*[ ;]([^ ;]*(_INCLUDE_DIRS|_LIBRARIES))" "\\1" tmp "${includeopts} ${libraryopts}") - if (NOT tmp STREQUAL "${includeopts} ${libraryopts}") - message(AUTHOR_WARNING "Plural form ${tmp} found in config options of ${PREFIX}. This works as before but is now deprecated. Please only use singular forms INCLUDE_DIR and LIBRARY, and update your find scripts for LibFindMacros > 2.0 automatic dependency system (most often you can simply remove the PROCESS variables entirely).") - endif() - - # Include/library names separated by spaces (notice: not CMake lists) - unset(includes) - unset(libs) - - # Process all includes and set found false if any are missing - foreach (i ${includeopts}) - list(APPEND configopts ${i}) - if (NOT "${${i}}" STREQUAL "${i}-NOTFOUND") - list(APPEND includes "${${i}}") - else() - set(found FALSE) - set(missing_headers TRUE) - endif() - endforeach() - - # Process all libraries and set found false if any are missing - foreach (i ${libraryopts}) - list(APPEND configopts ${i}) - if (NOT "${${i}}" STREQUAL "${i}-NOTFOUND") - list(APPEND libs "${${i}}") - else() - set (found FALSE) - endif() - endforeach() - - # Version checks - if (found AND findver) - if (NOT version) - message(WARNING "The find module for ${PREFIX} does not provide version information, so we'll just assume that it is OK. Please fix the module or remove package version requirements to get rid of this warning.") - elseif (version VERSION_LESS findver OR (exactver AND NOT version VERSION_EQUAL findver)) - set(found FALSE) - set(version_unsuitable TRUE) - endif() - endif() - - # If all-OK, hide all config options, export variables, print status and exit - if (found) - foreach (i ${configopts}) - mark_as_advanced(${i}) - endforeach() - if (NOT quiet) - message(STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") - if (LIBFIND_DEBUG) - message(STATUS " ${PREFIX}_DEPENDENCIES=${${PREFIX}_DEPENDENCIES}") - message(STATUS " ${PREFIX}_INCLUDE_OPTS=${includeopts}") - message(STATUS " ${PREFIX}_INCLUDE_DIRS=${includes}") - message(STATUS " ${PREFIX}_LIBRARY_OPTS=${libraryopts}") - message(STATUS " ${PREFIX}_LIBRARIES=${libs}") - endif() - set (${PREFIX}_INCLUDE_OPTS ${includeopts} PARENT_SCOPE) - set (${PREFIX}_LIBRARY_OPTS ${libraryopts} PARENT_SCOPE) - set (${PREFIX}_INCLUDE_DIRS ${includes} PARENT_SCOPE) - set (${PREFIX}_LIBRARIES ${libs} PARENT_SCOPE) - set (${PREFIX}_FOUND TRUE PARENT_SCOPE) - endif() - return() - endif() - - # Format messages for debug info and the type of error - set(vars "Relevant CMake configuration variables:\n") - foreach (i ${configopts}) - mark_as_advanced(CLEAR ${i}) - set(val ${${i}}) - if ("${val}" STREQUAL "${i}-NOTFOUND") - set (val "") - elseif (val AND NOT EXISTS ${val}) - set (val "${val} (does not exist)") - else() - set(some_files TRUE) - endif() - set(vars "${vars} ${i}=${val}\n") - endforeach() - set(vars "${vars}You may use CMake GUI, cmake -D or ccmake to modify the values. Delete CMakeCache.txt to discard all values and force full re-detection if necessary.\n") - if (version_unsuitable) - set(msg "${PREFIX} ${${PREFIX}_VERSION} was found but") - if (exactver) - set(msg "${msg} only version ${findver} is acceptable.") - else() - set(msg "${msg} version ${findver} is the minimum requirement.") - endif() - else() - if (missing_headers) - set(msg "We could not find development headers for ${PREFIX}. Do you have the necessary dev package installed?") - elseif (some_files) - set(msg "We only found some files of ${PREFIX}, not all of them. Perhaps your installation is incomplete or maybe we just didn't look in the right place?") - if(findver) - set(msg "${msg} This could also be caused by incompatible version (if it helps, at least ${PREFIX} ${findver} should work).") - endif() - else() - set(msg "We were unable to find package ${PREFIX}.") - endif() - endif() - - # Fatal error out if REQUIRED - if (required) - set(msg "REQUIRED PACKAGE NOT FOUND\n${msg} This package is REQUIRED and you need to install it or adjust CMake configuration in order to continue building ${CMAKE_PROJECT_NAME}.") - message(FATAL_ERROR "${msg}\n${vars}") - endif() - # Otherwise just print a nasty warning - if (NOT quiet) - message(WARNING "WARNING: MISSING PACKAGE\n${msg} This package is NOT REQUIRED and you may ignore this warning but by doing so you may miss some functionality of ${CMAKE_PROJECT_NAME}. \n${vars}") - endif() -endfunction() diff --git a/cmake/modules/bin2h.cmake b/cmake/modules/bin2h.cmake deleted file mode 100644 index b838650f32..0000000000 --- a/cmake/modules/bin2h.cmake +++ /dev/null @@ -1,89 +0,0 @@ -# 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