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

Commit e9f7edb

Browse files
committed
Removed the need for the 'library_root_dir' argument in all functions.
Everything related to the library properties file is now passed using the 'LIB_PROPS_FILE' optional argument. Also added utility function to get a library's properties file based on a given root directory - It simply appends the properties file name (which is now stored as a default cache variable) and checks for existence before returning.
1 parent 0720c5d commit e9f7edb

File tree

5 files changed

+62
-42
lines changed

5 files changed

+62
-42
lines changed

cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
#=============================================================================#
2-
# Attempts to retrieve a library's properties file based on its' root directory.
3-
# If couldn't be found, CMake generates a warning and returns an empty string.
4-
# _library_root_directory - Path to library's root directory. Can be relative.
5-
# _return_var - Name of variable in parent-scope holding the return value.
6-
# Returns - Full path to library's properties file.
7-
#=============================================================================#
8-
function(_get_library_properties_file _library_root_directory _return_var)
9-
10-
# Get the absolute root directory (full path)
11-
get_filename_component(absolute_lib_root_dir ${_library_root_directory} ABSOLUTE)
12-
13-
if (EXISTS ${absolute_lib_root_dir}/library.properties)
14-
set(lib_props_file ${absolute_lib_root_dir}/library.properties)
15-
else () # Properties file can't be found
16-
17-
# Warn user and assume library is arch-agnostic
18-
get_filename_component(library_name ${absolute_lib_root_dir} NAME)
19-
message(WARNING "\"${library_name}\" library's properties file can't be found "
20-
"under its' root directory - Assuming the library "
21-
"is architecture-agnostic (supports all architectures)")
22-
set(lib_props_file "")
23-
24-
endif ()
25-
26-
set(${_return_var} ${lib_props_file} PARENT_SCOPE)
27-
28-
endfunction()
29-
301
#=============================================================================#
312
# Filters sources that relate to an architecture from the given list of unsupported architectures.
323
# _unsupported_archs_regex - List of unsupported architectures as a regex-pattern string.
@@ -52,26 +23,27 @@ endfunction()
5223
# 2. Filtering out any library sources that relate to unsupported architectures, i.e
5324
# architectures other than the platform's.
5425
# If the platform's architecture isn't supported by the library, CMake generates an error and stops.
55-
# _library_root_dir - Path to library's root directory. Can be relative.
5626
# _library_sources - List of library's sources to check and potentially filter.
27+
# [LIB_PROPS_FILE] - Full path to the library's properties file. Optional.
5728
# _return_var - Name of variable in parent-scope holding the return value.
5829
# Returns - Filtered list of sources containing only those that don't relate to
5930
# any unsupported architecture.
6031
#=============================================================================#
61-
function(resolve_library_architecture _library_root_dir _library_sources _return_var)
32+
function(resolve_library_architecture _library_sources _return_var)
6233

6334
cmake_parse_arguments(parsed_args "" "LIB_PROPS_FILE" "" ${ARGN})
6435

6536
if (parsed_args_LIB_PROPS_FILE) # Library properties file is given
6637
set(lib_props_file ${parsed_args_LIB_PROPS_FILE})
6738
else ()
68-
# Try to automatically find file from sources
69-
_get_library_properties_file(${_library_root_dir} lib_props_file)
7039

71-
if ("${lib_props_file}" STREQUAL "") # Properties file couldn't be found
72-
set(${_return_var} "${_library_sources}" PARENT_SCOPE)
73-
return()
74-
endif ()
40+
# Warn user and assume library is arch-agnostic
41+
message(STATUS "Library's properties file can't be found "
42+
"under its' root directory - Assuming the library "
43+
"is architecture-agnostic (supports all architectures)")
44+
set(${_return_var} "${_library_sources}" PARENT_SCOPE)
45+
return()
46+
7547
endif ()
7648

7749
get_arduino_library_supported_architectures("${lib_props_file}" lib_archs)

cmake/Platform/System/DefaultsManager.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ function(set_default_arduino_cmake_options)
5757

5858
endfunction()
5959

60+
function(set_default_paths)
61+
62+
set(ARDUINO_CMAKE_LIBRARY_PROPERTIES_FILE_NAME "library.properties" CACHE STRING
63+
"Name of the libraries' properties file")
64+
65+
endfunction()
66+
6067
#=============================================================================#
6168
# Sets various defaults used throughout the platform.
6269
#=============================================================================#
@@ -65,5 +72,6 @@ function(set_arduino_cmake_defaults)
6572
set_internal_search_patterns()
6673
set_source_files_patterns()
6774
set_default_arduino_cmake_options()
75+
set_default_paths()
6876

6977
endfunction()

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@
33
# As it's an Arduino library, it also finds and links all dependent platform libraries (if any).
44
# _target_name - Name of the library target to be created. Usually library's real name.
55
# _board_id - Board ID associated with the linked Core Lib.
6-
# _sources - Source and header files to create target from.
76
# [LIB_PROPS_FILE] - Full path to the library's properties file. Optional.
7+
# [Sources] - List of source files (Could also be headers for code-inspection in some IDEs)
8+
# to create the executable from, similar to CMake's built-in add_executable.
89
#=============================================================================#
910
function(add_arduino_library _target_name _board_id)
1011

1112
cmake_parse_arguments(parsed_args "" "LIB_PROPS_FILE" "" ${ARGN})
1213
parse_sources_arguments(parsed_sources "" "LIB_PROPS_FILE" "" "${ARGN}")
1314

14-
get_sources_root_directory("${parsed_sources}" library_root_dir)
15-
1615
if (parsed_args_LIB_PROPS_FILE)
17-
resolve_library_architecture(${library_root_dir} "${parsed_sources}" arch_resolved_sources
16+
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
1817
LIB_PROPS_FILE ${parsed_args_LIB_PROPS_FILE})
1918
else ()
20-
resolve_library_architecture(${library_root_dir} "${parsed_sources}" arch_resolved_sources)
19+
20+
get_sources_root_directory("${parsed_sources}" library_root_dir)
21+
22+
get_library_properties_file(${library_root_dir} library_properties_file)
23+
24+
if (library_properties_file) # Properties file has been found
25+
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
26+
LIB_PROPS_FILE ${library_properties_file})
27+
else ()
28+
resolve_library_architecture("${parsed_sources}" arch_resolved_sources)
29+
endif ()
30+
2131
endif ()
2232

2333
_add_arduino_cmake_library(${_target_name} ${_board_id} "${arch_resolved_sources}")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#=============================================================================#
2+
# Gets the full path to a library's properties file based on the given library root directory.
3+
# If the root ditectory doesn't exist, CMake generates an error and stops.
4+
# If the properties file doesn't exist under the given root directory,
5+
# CMake generates a warning and returns an empty string.
6+
# _library_root_directory - Path to library's root directory. Can be relative.
7+
# _return_var - Name of a CMake variable that will hold the extraction result.
8+
# Returns - Full path to library's properties file if found, otherwise nothing.
9+
#=============================================================================#
10+
function(get_library_properties_file _library_root_directory _return_var)
11+
12+
get_filename_component(absolute_lib_root_dir ${_library_root_directory} ABSOLUTE)
13+
14+
if (NOT EXISTS ${absolute_lib_root_dir})
15+
message(SEND_ERROR "Can't get library's properties file - Root directory doesn't exist.\n"
16+
"Root directory: ${absolute_lib_root_dir}")
17+
endif ()
18+
19+
set(lib_props_file ${absolute_lib_root_dir}/${ARDUINO_CMAKE_LIBRARY_PROPERTIES_FILE_NAME})
20+
21+
if (NOT EXISTS ${lib_props_file})
22+
message(WARNING "Library's properties file doesn't exist under the given root directory.\n"
23+
"Root directory: ${absolute_lib_root_dir}")
24+
return()
25+
endif ()
26+
27+
set(${_return_var} ${lib_props_file} PARENT_SCOPE)
28+
29+
endfunction()

cmake/Platform/Utilities/Utilities.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ include(ListUtils)
33
include(StringUtils)
44
include(PathUtils)
55
include(PropertyUtils)
6+
include(LibraryUtils)
67
include(PlatformLibraryUtils)
78
include(CMakeArgumentsUtils)

0 commit comments

Comments
 (0)