Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 9cc596c

Browse files
committed
Added utility function to convert strings to PascalCase, now also used by Arduino Library targets to support case-insensitive names given by the user.
1 parent 4cb527d commit 9cc596c

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,19 @@ endfunction()
9797
#=============================================================================#
9898
function(find_arduino_library _target_name _library_name _board_id)
9999

100-
set(library_path "${ARDUINO_SDK_LIBRARIES_PATH}/${_library_name}")
100+
convert_string_to_pascal_case(${_library_name} arduino_compliant_library_name)
101+
message("Name: ${arduino_compliant_library_name}")
102+
set(library_path "${ARDUINO_SDK_LIBRARIES_PATH}/${arduino_compliant_library_name}")
101103
set(library_properties_path "${library_path}/library.properties")
102104

103105
if (NOT EXISTS "${library_properties_path}")
104-
message(SEND_ERROR "Couldn't find library named ${_library_name}")
106+
message(SEND_ERROR "Couldn't find library named ${arduino_compliant_library_name}")
105107
else () # Library is found
106108
_get_library_architecture("${library_properties_path}" lib_arch)
107109
if (lib_arch)
108110
if ("${lib_arch}" MATCHES "UNSUPPORTED")
109111
string(CONCAT error_message
110-
"${_library_name} "
112+
"${arduino_compliant_library_name} "
111113
"library isn't supported on the platform's architecture "
112114
"${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE}")
113115
message(SEND_ERROR ${error_message})
@@ -125,7 +127,8 @@ function(find_arduino_library _target_name _library_name _board_id)
125127

126128
if (NOT library_sources)
127129
set(error_message
128-
"${_library_name} doesn't have any source file under the 'src' directory")
130+
"${arduino_compliant_library_name} doesn't have any source files \
131+
under the 'src' directory")
129132
message(SEND_ERROR "${error_message}")
130133
else ()
131134
set(sources ${library_headers} ${library_sources})

cmake/Platform/Utilities/StringUtils.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,34 @@ endfunction()
7171
# Extracts a name symbol without possible file extension (marked usually by a dot ('.').
7272
# _input_string - String containing name symbol and possibly file extension.
7373
# _return_var - Name of a CMake variable that will hold the extraction result.
74+
# Returns - String containing input name without possible file extension.
7475
#=============================================================================#
7576
function(get_name_without_file_extension _input_string _return_var)
77+
7678
string(REGEX MATCH "${ARDUINO_CMAKE_NAME_WE_REGEX_PATTERN}" match "${_input_string}")
7779
set(${_return_var} ${CMAKE_MATCH_1} PARENT_SCOPE)
80+
81+
endfunction()
82+
83+
#=============================================================================#
84+
# Converts a given string a PascalCase string, converting 1st letter to upper and remaining to lower.
85+
# _input_string - String to convert.
86+
# _return_var - Name of a CMake variable that will hold the extraction result.
87+
# Returns - PascalCase converted string.
88+
#=============================================================================#
89+
function(convert_string_to_pascal_case _input_string _return_var)
90+
91+
# Convert 1st letter to upper case
92+
string(SUBSTRING ${_input_string} 0 1 first_letter)
93+
string(TOUPPER ${first_letter} first_letter_upper)
94+
95+
# Convert remaining letters to lower case
96+
string(SUBSTRING ${_input_string} 1 -1 remaining_letters)
97+
string(TOLOWER ${remaining_letters} remaining_letters_lower)
98+
99+
# Combine first letter with remaining letters
100+
string(APPEND combined_string ${first_letter_upper} ${remaining_letters_lower})
101+
102+
set(${_return_var} ${combined_string} PARENT_SCOPE)
103+
78104
endfunction()

examples/arduino-library/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ get_board_id(board_id nano atmega328)
66
add_arduino_executable(Arduino_Library ${board_id} test.cpp)
77

88
# Find and link the Stepper library
9-
find_arduino_library(stepper_lib Stepper ${board_id})
9+
find_arduino_library(stepper_lib stePpEr ${board_id}) # Library name is case-insensitive to the user
1010
link_arduino_library(Arduino_Library stepper_lib ${board_id})
1111

1212
# Find and link the Servo library - Custom implementation for many architectures,

0 commit comments

Comments
 (0)