Skip to content

Commit 3a690e8

Browse files
committed
libdefs: a way for user to configure libraries
1 parent 126bb02 commit 3a690e8

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

legacy/builder/phases/libraries_builder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type LibrariesBuilder struct{}
3737
func (s *LibrariesBuilder) Run(ctx *types.Context) error {
3838
librariesBuildPath := ctx.LibrariesBuildPath
3939
buildProperties := ctx.BuildProperties
40-
includes := utils.Map(ctx.IncludeFolders.AsStrings(), utils.WrapWithHyphenI)
40+
libFolders := append(ctx.IncludeFolders.AsStrings(), ctx.BuildPath.Join("sketch").Join("libdefs").String()) // user definitions for library include files
41+
includes := utils.Map(libFolders, utils.WrapWithHyphenI)
4142
libs := ctx.ImportedLibraries
4243

4344
if err := librariesBuildPath.MkdirAll(); err != nil {

legacy/builder/phases/sketch_builder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ type SketchBuilder struct{}
2727
func (s *SketchBuilder) Run(ctx *types.Context) error {
2828
sketchBuildPath := ctx.SketchBuildPath
2929
buildProperties := ctx.BuildProperties
30-
includes := utils.Map(ctx.IncludeFolders.AsStrings(), utils.WrapWithHyphenI)
30+
libFolders := append(ctx.IncludeFolders.AsStrings(), ctx.BuildPath.Join("sketch").Join("libdefs").String()) // user definitions for library include files
31+
includes := utils.Map(libFolders, utils.WrapWithHyphenI)
3132

3233
if err := sketchBuildPath.MkdirAll(); err != nil {
3334
return errors.WithStack(err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
// This user file is in 'sketchDir/libdefs/' so it can be included by libraries.
3+
//
4+
// Its name and what to include is specified by the library documentation.
5+
6+
#pragma once
7+
8+
#define LIB2_SOME_CONFIG 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#if defined __has_include
3+
# if __has_include (<lib2_user_config.h>)
4+
# pragma message "Including local project config file <lib2_user_config.h>"
5+
# include <lib2_user_config.h>
6+
# define DEFAULT_VALUES_ARE_GIVEN 1
7+
# endif
8+
#endif
9+
10+
#ifndef LIB2_SOME_CONFIG
11+
#define LIB2_SOME_CONFIG 0
12+
#endif
13+
14+
#define LIB2_SOME_SIZE ((LIB2_SOME_CONFIG) * 42)

test/testdata/sketch_with_multiple_custom_libraries/sketch_with_multiple_custom_libraries.ino

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "lib1.h"
22
#include "lib2.h"
33

4+
#if LIB2_SOME_SIZE != 42
5+
#error issue with lib2 user config
6+
#endif
7+
48
void setup() {
59
}
610

0 commit comments

Comments
 (0)