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

Commit 6af1ef6

Browse files
authored
Merge pull request #60 from arduino-cmake/feature/lib-without-sources
Added ability to create libraries without sources
2 parents 693011c + bd40206 commit 6af1ef6

34 files changed

+3996
-46
lines changed

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.vscode/cmake-kits.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"name": "Arduino-CMake-Toolchain",
4+
"toolchainFile": "${workspaceRoot}/cmake/Arduino-Toolchain.cmake"
5+
}
6+
]

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"travis.repository": "Arduino-CMake-NG",
3+
"travis.username": "arduino-cmake",
4+
"travis.statusPollingInterval": 120,
5+
6+
"cmake.sourceDirectory": "${workspaceRoot}/examples",
7+
"cmake.buildDirectory": "${workspaceRoot}/build/cmake-build-debug",
8+
"cmake.preferredGenerators": [
9+
"Ninja",
10+
"Unix Makefiles",
11+
],
12+
"cmake.configureOnOpen": true,
13+
"C_Cpp.intelliSenseEngineFallback": "Enabled",
14+
"C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools"
15+
}

cmake/Platform/Libraries/LibrarySourcesArchitectureResolver.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ endfunction()
3131
#=============================================================================#
3232
function(resolve_library_architecture _library_sources _return_var)
3333

34+
if(NOT _library_sources)
35+
return()
36+
endif()
37+
3438
cmake_parse_arguments(parsed_args "" "LIB_PROPS_FILE" "" ${ARGN})
3539

3640
if (parsed_args_LIB_PROPS_FILE) # Library properties file is given

cmake/Platform/Sources/SourcesManager.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,29 @@ function(target_source_directories _target_name)
2727
list(REMOVE_DUPLICATES source_dirs)
2828

2929
if (parsed_args_RECURSE) # Search recursively
30+
3031
foreach (source_dir ${source_dirs})
32+
3133
find_header_files(${source_dir} headers RECURSE)
3234
find_source_files(${source_dir} sources RECURSE)
3335

3436
list(APPEND collective_headers ${headers})
3537
list(APPEND collective_sources ${sources})
38+
3639
endforeach ()
40+
3741
else ()
42+
3843
foreach (source_dir ${source_dirs})
44+
3945
find_header_files(${source_dir} headers)
4046
find_source_files(${source_dir} sources)
4147

4248
list(APPEND collective_headers ${headers})
4349
list(APPEND collective_sources ${sources})
50+
4451
endforeach ()
52+
4553
endif ()
4654

4755
if (collective_headers)
@@ -54,6 +62,7 @@ function(target_source_directories _target_name)
5462

5563
# Treat headers' parent directories as include directories of the target
5664
get_headers_parent_directories("${collective_headers}" include_dirs)
65+
5766
target_include_directories(${_target_name} PUBLIC ${include_dirs})
5867

5968
target_sources(${_target_name} PUBLIC ${collective_sources})
@@ -73,6 +82,7 @@ function(get_source_file_includes _source_file _return_var)
7382
endif ()
7483

7584
file(STRINGS "${_source_file}" source_lines)
85+
7686
list(FILTER source_lines INCLUDE REGEX "${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN}")
7787

7888
set(${_return_var} ${source_lines} PARENT_SCOPE)
@@ -91,17 +101,22 @@ function(get_source_file_included_headers _source_file _return_var)
91101
cmake_parse_arguments(headers "WE" "" "" ${ARGN})
92102

93103
file(STRINGS "${_source_file}" source_lines) # Loc = Lines of code
104+
94105
list(FILTER source_lines INCLUDE REGEX ${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN})
95106

96107
# Extract header names from inclusion
97108
foreach (loc ${source_lines})
109+
98110
string(REGEX MATCH ${ARDUINO_CMAKE_HEADER_NAME_REGEX_PATTERN} match ${loc})
111+
99112
if (headers_WE)
100113
get_name_without_file_extension("${CMAKE_MATCH_1}" header_name)
101114
else ()
102115
set(header_name ${CMAKE_MATCH_1})
103116
endif ()
117+
104118
list(APPEND headers ${header_name})
119+
105120
endforeach ()
106121

107122
set(${_return_var} ${headers} PARENT_SCOPE)
@@ -119,10 +134,15 @@ function(get_headers_parent_directories _sources _return_var)
119134

120135
# Extract header files
121136
list(FILTER _sources INCLUDE REGEX "${ARDUINO_CMAKE_HEADER_FILE_EXTENSION_REGEX_PATTERN}")
137+
122138
foreach (header_source ${_sources})
139+
123140
get_filename_component(header_parent_dir ${header_source} DIRECTORY)
141+
124142
list(APPEND parent_dirs ${header_parent_dir})
143+
125144
endforeach ()
145+
126146
if (parent_dirs) # Check parent dirs, could be none if there aren't any headers amongst sources
127147
list(REMOVE_DUPLICATES parent_dirs)
128148
endif ()

cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ function(_add_arduino_cmake_library _target_name _board_id _sources)
1313
cmake_parse_arguments(parsed_args "INTERFACE" "" "" ${ARGN})
1414

1515
if (parsed_args_INTERFACE)
16+
1617
add_library(${_target_name} INTERFACE)
1718
set(scope INTERFACE)
19+
1820
else ()
19-
add_library(${_target_name} STATIC "${_sources}")
21+
22+
add_library(${_target_name} STATIC "${_sources}")
2023
set(scope PUBLIC)
24+
2125
endif ()
2226

2327
# Treat headers' parent directories as include directories of the target
@@ -26,8 +30,7 @@ function(_add_arduino_cmake_library _target_name _board_id _sources)
2630

2731
set_library_flags(${_target_name} ${_board_id} ${scope})
2832

29-
set_target_architecture_definition(${_target_name} ${scope}
30-
${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE})
33+
set_target_architecture_definition(${_target_name} ${scope} ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE})
3134

3235
endfunction()
3336

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,26 @@ function(add_arduino_library _target_name _board_id)
1010

1111
parse_sources_arguments(parsed_sources "" "" "" "${ARGN}")
1212

13-
get_sources_root_directory("${parsed_sources}" library_root_dir)
13+
if (parsed_sources)
1414

15-
get_library_properties_file(${library_root_dir} library_properties_file)
15+
get_sources_root_directory("${parsed_sources}" library_root_dir)
1616

17-
if (library_properties_file) # Properties file has been found
18-
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
19-
LIB_PROPS_FILE ${library_properties_file})
20-
else ()
21-
resolve_library_architecture("${parsed_sources}" arch_resolved_sources)
22-
endif ()
17+
get_library_properties_file(${library_root_dir} library_properties_file)
18+
19+
if (library_properties_file) # Properties file has been found
20+
resolve_library_architecture("${parsed_sources}" arch_resolved_sources
21+
LIB_PROPS_FILE ${library_properties_file})
22+
else ()
23+
resolve_library_architecture("${parsed_sources}" arch_resolved_sources)
24+
endif ()
25+
26+
_add_arduino_cmake_library(${_target_name} ${_board_id} "${arch_resolved_sources}")
27+
28+
else() # No sources have been provided at this stage, simply create a library target
2329

24-
_add_arduino_cmake_library(${_target_name} ${_board_id} "${arch_resolved_sources}")
30+
_add_arduino_cmake_library(${_target_name} ${_board_id} "")
31+
32+
endif()
2533

2634
find_dependent_platform_libraries("${arch_resolved_sources}" lib_platform_libs)
2735

cmake/Platform/Utilities/CMakeArgumentsUtils.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
#=============================================================================#
1212
function(_consume_reserved_arguments _args _reserved_options _reserved_single_values _return_var)
1313

14+
if("${_args}" STREQUAL "") # Check if there are any arguments at all
15+
return()
16+
endif()
17+
1418
set(temp_arg_list ${_args})
1519

1620
list(LENGTH _args args_length)
21+
1722
decrement_integer(args_length 1) # We'll peform index iteration - It's always length-1
1823

1924
foreach (index RANGE ${args_length})

examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.8.2)
22

33
project(Examples LANGUAGES C CXX ASM)
44

@@ -9,3 +9,4 @@ add_subdirectory(header-only-library)
99
add_subdirectory(blink-example)
1010
add_subdirectory(servo-knob-example)
1111
add_subdirectory(sketch)
12+
add_subdirectory(misc)

examples/hello-world/helloWorld.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ void setup()
77

88
void loop()
99
{
10-
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
11-
delay(1000); // wait for a second
12-
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
13-
delay(1000); // wait for a second
10+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
11+
delay(1000); // wait for a second
12+
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
13+
delay(1000); // wait for a second
1414
}

0 commit comments

Comments
 (0)