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

Commit 34348fd

Browse files
committed
Added support for interface/header-only libraries through CMake's INTERFACE scope.
The feature isn't complete yet.
1 parent 3ee6753 commit 34348fd

File tree

11 files changed

+179
-118
lines changed

11 files changed

+179
-118
lines changed

cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@
66
#=============================================================================#
77
function(_set_library_flags _library_target _board_id)
88

9+
set(scope_options "PRIVATE" "PUBLIC" "INTERFACE")
10+
cmake_parse_arguments(parsed_args "${scope_options}" "" "" ${ARGN})
11+
12+
if (parsed_args_PRIVATE)
13+
set(scope PRIVATE)
14+
elseif (parsed_args_INTERFACE)
15+
set(scope INTERFACE)
16+
else ()
17+
set(scope PUBLIC)
18+
endif ()
19+
920
# Set C++ compiler flags
1021
get_cmake_compliant_language_name(cpp flags_language)
11-
set_compiler_target_flags(${_library_target} "${_board_id}" PUBLIC LANGUAGE ${flags_language})
22+
set_compiler_target_flags(${_library_target} "${_board_id}" ${scope} LANGUAGE ${flags_language})
1223

1324
# Set linker flags
1425
set_linker_flags(${_library_target} "${_board_id}")
@@ -22,13 +33,14 @@ endfunction()
2233
# _target_name - Name of the library target to be created. Usually library's real name.
2334
# _board_id - Board ID associated with the linked Core Lib.
2435
# _sources - Source and header files to create library target from.
25-
# [ARCH] - Optional library architecture (Such as 'avr', 'nrf52', etc.)
36+
# [ARCH] - Optional library architecture (Such as 'avr', 'nrf52', etc.).
37+
# [INTERFACE] - Whether the library should be created as an interface library (header-only).
2638
#=============================================================================#
2739
function(_add_arduino_cmake_library _target_name _board_id _sources)
2840

29-
cmake_parse_arguments(library "" "ARCH" "" ${ARGN})
41+
cmake_parse_arguments(parsed_args "INTERFACE" "ARCH" "" ${ARGN})
3042

31-
if (library_ARCH) # Treat architecture-specific libraries differently
43+
if (parsed_args_ARCH) # Treat architecture-specific libraries differently
3244
# Filter any sources that aren't supported by the platform's architecture
3345
list(LENGTH library_ARCH num_of_libs_archs)
3446
if (${num_of_libs_archs} GREATER 1)
@@ -42,17 +54,24 @@ function(_add_arduino_cmake_library _target_name _board_id _sources)
4254
list(FILTER _sources ${filter_type} REGEX ${arch_filter})
4355
endif ()
4456

45-
add_library(${_target_name} STATIC "${_sources}")
57+
if (parsed_args_INTERFACE)
58+
add_library(${_target_name} INTERFACE)
59+
set(scope INTERFACE)
60+
else ()
61+
add_library(${_target_name} STATIC "${_sources}")
62+
set(scope PUBLIC)
63+
endif ()
64+
4665
# Treat headers' parent directories as include directories of the target
4766
get_headers_parent_directories("${_sources}" include_dirs)
48-
target_include_directories(${_target_name} PUBLIC ${include_dirs})
67+
target_include_directories(${_target_name} ${scope} ${include_dirs})
4968

50-
_set_library_flags(${_target_name} ${_board_id})
69+
_set_library_flags(${_target_name} ${_board_id} ${scope})
5170

52-
if (library_ARCH)
53-
string(TOUPPER ${library_ARCH} upper_arch)
71+
if (parsed_args_ARCH)
72+
string(TOUPPER ${parsed_args_ARCH} upper_arch)
5473
set(arch_definition "ARDUINO_ARCH_${upper_arch}")
55-
target_compile_definitions(${_target_name} PUBLIC ${arch_definition})
74+
target_compile_definitions(${_target_name} ${scope} ${arch_definition})
5675
endif ()
5776

5877
endfunction()

cmake/Platform/Targets/ArduinoLibraryTarget.cmake

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ function(_get_unsupported_architectures _arch_list _return_var)
6969

7070
endfunction()
7171

72+
function(add_arduino_header_only_library _target_name _board_id)
73+
74+
_add_arduino_cmake_library(${_target_name} ${_board_id} "${_sources}" INTERFACE "${ARGN}")
75+
76+
endfunction()
77+
7278
#=============================================================================#
7379
# Creates a library target for the given name and sources.
7480
# As it's an Arduino library, it also finds and links all dependent platform libraries (if any).
@@ -95,12 +101,14 @@ endfunction()
95101
# _library_name - Name of the Arduino library to find.
96102
# _board_id - Board ID associated with the linked Core Lib.
97103
# [3RD_PARTY] - Whether library should be treated as a 3rd Party library.
104+
# [HEADER_ONLY] - Whether library is a header-only library, i.e has no source files
98105
#=============================================================================#
99106
function(find_arduino_library _target_name _library_name _board_id)
100107

101-
cmake_parse_arguments(find_lib "3RD_PARTY" "" "" ${ARGN})
108+
set(argument_options "3RD_PARTY" "HEADER_ONLY")
109+
cmake_parse_arguments(parsed_args "${argument_options}" "" "" ${ARGN})
102110

103-
if (NOT find_lib_3RD_PARTY)
111+
if (NOT parsed_args_3RD_PARTY)
104112
convert_string_to_pascal_case(${_library_name} _library_name)
105113
endif ()
106114

@@ -130,13 +138,21 @@ function(find_arduino_library _target_name _library_name _board_id)
130138
set(error_message "Couldn't find any header files for the ${_library_name} library")
131139
message(SEND_ERROR "${error_message}")
132140
else ()
133-
find_library_source_files("${library_path}" library_sources)
134-
if (NOT library_sources)
135-
set(error_message "Couldn't find any source files for the ${_library_name} library")
136-
message(SEND_ERROR "${error_message}")
141+
if (parsed_args_HEADER_ONLY)
142+
add_arduino_header_only_library(${_target_name} ${_board_id} "${library_headers}"
143+
INTERFACE ARCH ${lib_arch})
137144
else ()
138-
set(sources ${library_headers} ${library_sources})
139-
add_arduino_library(${_target_name} ${_board_id} "${sources}" ARCH ${lib_arch})
145+
find_library_source_files("${library_path}" library_sources)
146+
if (NOT library_sources)
147+
string(CONCAT error_message
148+
"Couldn't find any source files for the ${_library_name} library - "
149+
"Is it a header-only library?\n"
150+
"If so, please pass the HEADER_ONLY option as an argument to the function")
151+
message(SEND_ERROR "${error_message}")
152+
else ()
153+
set(sources ${library_headers} ${library_sources})
154+
add_arduino_library(${_target_name} ${_board_id} "${sources}" ARCH ${lib_arch})
155+
endif ()
140156
endif ()
141157
endif ()
142158
endif ()

examples/3rd-party-library/3rd_party.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void setup()
77
{
88
testNeoPixel();
99
testGFX();
10+
testEnableInterrupt();
1011
}
1112

1213
void loop()

examples/3rd-party-library/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ find_arduino_library(Adafruit_GFX Adafruit-GFX-Library ${board_id} 3RD_PARTY)
2121
target_source_directories(Adafruit_GFX DIRS libraries/Adafruit-GFX-Library/Fonts)
2222

2323
# Find the "EnableInterrupt" a header-only library
24-
#find_arduino_library(enableInterrupt EnableInterrupt ${board_id} 3RD_PARTY)
24+
find_arduino_library(EnableInterrupt EnableInterrupt ${board_id} 3RD_PARTY HEADER_ONLY)
2525

2626
# Link all libraries to our previously created target
2727
link_arduino_library(3rd_Party_Arduino_Library Adafruit_NeoPixel ${board_id})
2828
link_arduino_library(3rd_Party_Arduino_Library Adafruit_GFX ${board_id})
29-
#link_arduino_library(3rd_Party_Arduino_Library enableInterrupt ${board_id})
29+
link_arduino_library(3rd_Party_Arduino_Library EnableInterrupt ${board_id})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
#include "include/InterruptTest.hpp"
2+
3+
void handler_function()
4+
{
5+
uint32_t interrupt_time = millis();
6+
}
7+
8+
void testEnableInterrupt()
9+
{
10+
enableInterrupt(BUTTON_PIN, handler_function, RISING);
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#ifndef EXAMPLES_INTERRUPTTEST_HPP
22
#define EXAMPLES_INTERRUPTTEST_HPP
33

4+
#include <EnableInterrupt.h>
5+
6+
#define BUTTON_PIN 5
7+
8+
void testEnableInterrupt();
9+
410
#endif //EXAMPLES_INTERRUPTTEST_HPP

examples/3rd-party-library/libraries/EnableInterrupt/EnableInterrupt.h

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -654,79 +654,6 @@ static volatile uint8_t portSnapshotB;
654654
#endif
655655

656656
#ifndef NEEDFORSPEED
657-
#if defined BOBUINO_PINOUT
658-
#define ARDUINO_PIN_A0 21
659-
#define ARDUINO_PIN_A1 20
660-
#define ARDUINO_PIN_A2 19
661-
#define ARDUINO_PIN_A3 18
662-
#define ARDUINO_PIN_A4 17
663-
#define ARDUINO_PIN_A5 16
664-
#define ARDUINO_PIN_A6 15
665-
#define ARDUINO_PIN_A7 14
666-
#define ARDUINO_PIN_B0 4
667-
#define ARDUINO_PIN_B1 5
668-
#define ARDUINO_PIN_B2 6 // INT2
669-
#define ARDUINO_PIN_B3 7
670-
#define ARDUINO_PIN_B4 10
671-
#define ARDUINO_PIN_B5 11
672-
#define ARDUINO_PIN_B6 12
673-
#define ARDUINO_PIN_B7 13
674-
#define ARDUINO_PIN_C0 22
675-
#define ARDUINO_PIN_C1 23
676-
#define ARDUINO_PIN_C2 24
677-
#define ARDUINO_PIN_C3 25
678-
#define ARDUINO_PIN_C4 26
679-
#define ARDUINO_PIN_C5 27
680-
#define ARDUINO_PIN_C6 28
681-
#define ARDUINO_PIN_C7 29
682-
#define ARDUINO_PIN_D0 0
683-
#define ARDUINO_PIN_D1 1
684-
#define ARDUINO_PIN_D2 2 // INT0
685-
#define ARDUINO_PIN_D3 3 // INT1
686-
#define ARDUINO_PIN_D4 30
687-
#define ARDUINO_PIN_D5 8
688-
#define ARDUINO_PIN_D6 9
689-
#define ARDUINO_PIN_D7 31
690-
691-
const uint8_t PROGMEM digital_pin_to_port_bit_number_PGM[] = {
692-
0, // PD0
693-
1, // PD1
694-
2, // PD2
695-
3, // PD3
696-
0, // PB0
697-
1, // PB1
698-
2, // PB2
699-
3, // PB3
700-
5, // PD5
701-
6, // PD6
702-
703-
4, // PB4
704-
5, // PB5
705-
6, // PB6
706-
7, // PB7
707-
7, // PA7
708-
6, // PA6
709-
5, // PA5
710-
4, // PA4
711-
3, // PA3
712-
2, // PA2
713-
714-
1, // PA1
715-
0, // PA0
716-
0, // PC0
717-
1, // PC1
718-
2, // PC2
719-
3, // PC3
720-
4, // PC4
721-
5, // PC5
722-
6, // PC6
723-
7, // PC7
724-
725-
4, // PD4
726-
7, // PD7
727-
};
728-
729-
#else
730657
#define ARDUINO_PIN_A0 24
731658
#define ARDUINO_PIN_A1 25
732659
#define ARDUINO_PIN_A2 26
@@ -816,7 +743,6 @@ const uint8_t PROGMEM digital_pin_to_port_bit_number_PGM[] = {
816743
6,
817744
7
818745
};
819-
#endif
820746

821747

822748
#if ! defined(EI_NOTEXTERNAL) && ! defined(EI_NOTINT0) && ! defined(EI_NOTINT1) && ! defined(EI_NOTINT2)

examples/3rd-party-library/libraries/EnableInterrupt/README.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ Functions:
66
enableInterrupt- Enables interrupt on a selected Arduino pin.
77
disableInterrupt - Disables interrupt on the selected Arduino pin.
88

9-
10-
*_What's New?_ Fri Jun 22 06:49:57 CDT 2018 Version 1.0.0 of the library has been released. Alex Reinert contributed Bobuino support. Thanks, Alex! And at this point, I think it's long past due that we stick a non-beta sticker on this thing. Congratulations, EnableInterrupt- you are all grown up. Version 1.0.0 it is.
9+
*_What's New?_ Tue Sep 19 18:02:21 CDT 2017 Version 0.9.8 of the library has been released.
10+
There were a number of outstanding pull requests that were merged into the library. Thanks
11+
to Loranzo Cafaro for his switch debounce example, to Jevon Wild for his changes to make the
12+
library more functional with PlatformIO (http://docs.platformio.org/en/latest/what-is-platformio.html),
13+
Ricardo JL Rufino for some PlatformIO fixes to the library.json file, and Sara Damiano for
14+
adding support for the Sodaq Mbili and EnviroDIY Mayfly.
1115

1216
The EnableInterrupt library is an Arduino interrupt library, designed for
1317
all versions of the Arduino- at this writing, the Uno (and other ATmega328p-based
@@ -293,7 +297,7 @@ the library's code and thus is not supported by this library. It is the same
293297
pin the Arduino uses to upload sketches, and it is connected to the FT232RL
294298
USB-to-Serial chip (ATmega16U2 on the R3).
295299

296-
### Mighty 1284, Bobuino, EnviroDIY Mayfly, Sodaq Mbili Support
300+
### Mighty 1284, EnviroDIY Mayfly, Sodaq Mbili Support
297301
The ATmega 1284p shares pinout with the 644; the only difference is in memory
298302
size. We use the "Mighty 1284" platform as our model, because the needed files are
299303
mature and complete.
@@ -320,26 +324,6 @@ Pin Interrupt Pin* PORT PCINT ATmega644/1284 pin Pin* POR
320324
25/A1 PA1 1 39
321325
24/A0 PA0 0 40
322326

323-
Bobuino External Bobuino Bobuino
324-
Pin Interrupt Pin* PORT PCINT ATmega644/1284 pin Pin* PORT PCINT ATmega644/1284 pin
325-
Port 4 PB0 8 1 31 PD7 31 21
326-
2 INT2 PB2 5 PB1 9 2 22 PC0 16 22
327-
10 INT1 PD2 6 PB2 2 3 23 PC1 17 23
328-
11 INT0 PD3 7 PB3 11 4 24 PC2 18 24
329-
10 PB4 12 5 25 PC3 19 25
330-
11 PB5 13 6 26 PC4 20 26
331-
12 PB6 14 7 27 PC5 21 27
332-
13 PB7 15 8 28 PC6 22 28
333-
0 PD0 24 14 29 PC7 23 29
334-
1 PD1 25 15 14/A0 PA7 7 33
335-
2 PD2 26 16 15/A1 PA6 6 34
336-
3 PD3 27 17 16/A2 PA5 5 35
337-
30 PD4 28 18 17/A3 PA4 4 36
338-
8 PD5 29 19 18/A4 PA3 3 37
339-
9 PD6 30 20 19/A5 PA2 2 38
340-
20/A6 PA1 1 39
341-
21/A7 PA0 0 40
342-
343327
Mayfly Mayfly Mayfly
344328
Mbili External Mbili Mbili
345329
Pin Interrupt Pin* PORT PCINT ATmega644/1284 pin Pin* PORT PCINT ATmega644/1284 pin
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- examples/test.sh compiles
2+
- #pragma message in .h file up-to-date?
3+
- Use Arduino IDE, compile "SimpleDueZero"
4+
- Tests:
5+
- Simple
6+
- HiSpeed
7+
- HiSpeedAllPins328
8+
- AllPins328
9+
- HiSpeedAllPins2560
10+
- AllPins2560
11+
- ATtinyBlink
12+
- README.md up-to-date?
13+
- extras/RELEASE_NOTES consistent with README.md?
14+
- library.properties current?
15+
- library.json current?
16+
- Git Tagged? git tag -a 2.31 -m 'my version 1.4'; git push origin 2.31 OR git push origin --tags
17+
- Zip file created? ~/bin/zipei 0.9.0
18+
- BinTray:
19+
- Upload Zip file
20+
- Update the downloads area
21+
- Git commit
22+
- Push files to GitHub
23+
- Post to Arduino forums

0 commit comments

Comments
 (0)