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

Commit 8ffc3d6

Browse files
committed
Added utility function to get name symbol from string without file extension.
1 parent 46e496a commit 8ffc3d6

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

cmake/Platform/Sketches/SketchHeadersManager.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ function(resolve_sketch_headers _target_name _board_id _sketch_file)
3333
foreach (header ${sketch_headers})
3434
# Header name without extension (such as '.h') can represent an Arduino/Platform library
3535
# So first we should check whether it's a library
36-
string(REGEX MATCH "(.+)\\." "${header}" header_we_match)
37-
set(header_we ${CMAKE_MATCH_1})
36+
get_name_without_file_extension("${header}" header_we)
3837

3938
if (${header_we} IN_LIST ARDUINO_CMAKE_PLATFORM_LIBRARIES)
4039
link_platform_library(${_target_name} ${header_we} ${_board_id})

cmake/Platform/Sources/SourcesManager.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ endfunction()
2929
#=============================================================================#
3030
function(get_source_file_included_headers _source_file _return_var)
3131

32+
cmake_parse_arguments(headers "WE" "" "" ${ARGN})
33+
3234
file(STRINGS "${_source_file}" source_lines) # Loc = Lines of code
3335
list(FILTER source_lines INCLUDE REGEX ${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN})
3436

3537
# Extract header names from inclusion
3638
foreach (loc ${source_lines})
3739
string(REGEX MATCH ${ARDUINO_CMAKE_HEADER_NAME_REGEX_PATTERN} ${loc} match)
38-
list(APPEND headers ${CMAKE_MATCH_1})
40+
if (headers_WE)
41+
get_name_without_file_extension("${CMAKE_MATCH_1}" header_name)
42+
else ()
43+
set(header_name ${CMAKE_MATCH_1})
44+
endif ()
45+
list(APPEND headers ${header_name})
3946
endforeach ()
4047

4148
set(${_return_var} ${headers} PARENT_SCOPE)

cmake/Platform/System/DefaultsManager.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function(set_internal_search_patterns)
1212
"Regex pattern matching a header's name when wrapped in inclusion line")
1313
set(ARDUINO_CMAKE_HEADER_FILE_EXTENSION_REGEX_PATTERN ".+\\.h.*$" CACHE STRING
1414
"Regex pattern matching all header file extensions")
15+
set(ARDUINO_CMAKE_NAME_WE_REGEX_PATTERN "(.+)\\." CACHE STRING
16+
"Regex pattern matching name without file extension")
1517
set(ARDUINO_CMAKE_FUNCTION_REGEX_PATTERN "^([a-z]|[A-Z])+.*\(([a-z]|[A-Z])*\)" CACHE STRING
1618
"Regex pattern matching a function signature in a source file")
1719

cmake/Platform/Utilities/StringUtils.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ function(get_core_lib_target_name _board_id _return_var)
6666
set(${_return_var} ${core_lib_target_name} PARENT_SCOPE)
6767

6868
endfunction()
69+
70+
#=============================================================================#
71+
# Extracts a name symbol without possible file extension (marked usually by a dot ('.').
72+
# _input_string - String containing name symbol and possibly file extension.
73+
# _output_string - Name of a CMake variable that will hold the extraction result.
74+
#=============================================================================#
75+
macro(get_name_without_file_extension _input_string _output_string)
76+
string(REGEX MATCH "${ARDUINO_CMAKE_NAME_WE_REGEX_PATTERN}" "${_input_string}" match)
77+
set(${_output_string} ${CMAKE_MATCH_1})
78+
endmacro()

0 commit comments

Comments
 (0)