Merge pull request #12844 from aabadie/pr/make/base_ext
Makefile.base: add variables for customizing C++ builds
This commit is contained in:
commit
c58232aebf
@ -48,11 +48,14 @@ ifeq (1, $(SUBMODULES))
|
||||
endif
|
||||
endif
|
||||
|
||||
# By default consider C++ files has a .cpp extension
|
||||
SRCXXEXT ?= cpp
|
||||
|
||||
ifeq ($(strip $(SRC))$(NO_AUTO_SRC),)
|
||||
SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c))
|
||||
endif
|
||||
ifeq ($(strip $(SRCXX))$(NO_AUTO_SRC),)
|
||||
SRCXX := $(wildcard *.cpp)
|
||||
SRCXX := $(filter-out $(SRCXXEXCLUDE),$(wildcard *.$(SRCXXEXT)))
|
||||
endif
|
||||
ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),)
|
||||
ASMSRC := $(wildcard *.s)
|
||||
@ -68,7 +71,7 @@ GENOBJC := $(GENSRC:%.c=%.o)
|
||||
OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o)
|
||||
OBJC_NOLTO := $(SRC_NOLTO:%.c=$(BINDIR)/$(MODULE)/%.o)
|
||||
OBJC := $(OBJC_NOLTO) $(OBJC_LTO)
|
||||
OBJCXX := $(SRCXX:%.cpp=$(BINDIR)/$(MODULE)/%.o)
|
||||
OBJCXX := $(SRCXX:%.$(SRCXXEXT)=$(BINDIR)/$(MODULE)/%.o)
|
||||
ASMOBJ := $(ASMSRC:%.s=$(BINDIR)/$(MODULE)/%.o)
|
||||
ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o)
|
||||
|
||||
@ -108,7 +111,7 @@ $(GENOBJC): %.o: %.c $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_H
|
||||
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
||||
$(CFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $<
|
||||
|
||||
$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C)
|
||||
$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.$(SRCXXEXT) $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C)
|
||||
$(Q)$(CCACHE) $(CXX) \
|
||||
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
|
||||
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
||||
|
||||
8
tests/cpp_exclude/Makefile
Normal file
8
tests/cpp_exclude/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
FEATURES_REQUIRED += cpp
|
||||
|
||||
USEMODULE += module_exclude
|
||||
EXTERNAL_MODULE_DIRS += $(CURDIR)/module_exclude
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
6
tests/cpp_exclude/Makefile.ci
Normal file
6
tests/cpp_exclude/Makefile.ci
Normal file
@ -0,0 +1,6 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
nucleo-f031k6 \
|
||||
nucleo-f042k6 \
|
||||
stm32f030f4-demo \
|
||||
stm32f0discovery \
|
||||
#
|
||||
31
tests/cpp_exclude/main.cpp
Normal file
31
tests/cpp_exclude/main.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample C++ application
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "module.hpp"
|
||||
|
||||
int main() {
|
||||
puts("Hello from C++");
|
||||
|
||||
module_class obj;
|
||||
obj.print_hello();
|
||||
|
||||
return 0;
|
||||
}
|
||||
5
tests/cpp_exclude/module_exclude/Makefile
Normal file
5
tests/cpp_exclude/module_exclude/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
MODULE = module_exclude
|
||||
|
||||
SRCXXEXCLUDE := module_excluded.cpp
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
1
tests/cpp_exclude/module_exclude/Makefile.dep
Normal file
1
tests/cpp_exclude/module_exclude/Makefile.dep
Normal file
@ -0,0 +1 @@
|
||||
FEATURES_REQUIRED += cpp
|
||||
3
tests/cpp_exclude/module_exclude/Makefile.include
Normal file
3
tests/cpp_exclude/module_exclude/Makefile.include
Normal file
@ -0,0 +1,3 @@
|
||||
# Use an immediate variable to evaluate `MAKEFILE_LIST` now
|
||||
USEMODULE_INCLUDES_module_exclude := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_module_exclude)
|
||||
32
tests/cpp_exclude/module_exclude/module.cpp
Normal file
32
tests/cpp_exclude/module_exclude/module.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample module C++ class
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "module.hpp"
|
||||
|
||||
module_class::module_class() {}
|
||||
|
||||
module_class::~module_class() {}
|
||||
|
||||
void module_class::print_hello(void)
|
||||
{
|
||||
puts("Hello from C++ module");
|
||||
}
|
||||
46
tests/cpp_exclude/module_exclude/module.hpp
Normal file
46
tests/cpp_exclude/module_exclude/module.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample module C++ class
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
class module_class
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief constructor
|
||||
*/
|
||||
module_class();
|
||||
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~module_class();
|
||||
|
||||
/**
|
||||
* @brief public function
|
||||
*/
|
||||
void print_hello(void);
|
||||
};
|
||||
|
||||
/** @} */
|
||||
#endif /* MODULE_H */
|
||||
34
tests/cpp_exclude/module_exclude/module_excluded.cpp
Normal file
34
tests/cpp_exclude/module_exclude/module_excluded.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample module C++ class
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "module.hpp"
|
||||
|
||||
#error "This should not be built"
|
||||
|
||||
module_class::module_class() {}
|
||||
|
||||
module_class::~module_class() {}
|
||||
|
||||
void module_class::print(void)
|
||||
{
|
||||
puts("Hello from C++ module");
|
||||
}
|
||||
19
tests/cpp_exclude/tests/01-run.py
Executable file
19
tests/cpp_exclude/tests/01-run.py
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2019 Inria
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect_exact('Hello from C++')
|
||||
child.expect_exact('Hello from C++ module')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
||||
8
tests/cpp_ext/Makefile
Normal file
8
tests/cpp_ext/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
FEATURES_REQUIRED += cpp
|
||||
|
||||
USEMODULE += module
|
||||
EXTERNAL_MODULE_DIRS += $(CURDIR)/module
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
6
tests/cpp_ext/Makefile.ci
Normal file
6
tests/cpp_ext/Makefile.ci
Normal file
@ -0,0 +1,6 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
nucleo-f031k6 \
|
||||
nucleo-f042k6 \
|
||||
stm32f030f4-demo \
|
||||
stm32f0discovery \
|
||||
#
|
||||
32
tests/cpp_ext/main.cpp
Normal file
32
tests/cpp_ext/main.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample C++ application
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "module.hh"
|
||||
|
||||
int main() {
|
||||
puts("Hello from C++");
|
||||
|
||||
module_class obj;
|
||||
obj.print_hello();
|
||||
|
||||
return 0;
|
||||
}
|
||||
5
tests/cpp_ext/module/Makefile
Normal file
5
tests/cpp_ext/module/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
MODULE = module
|
||||
|
||||
SRCXXEXT = cc
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
1
tests/cpp_ext/module/Makefile.dep
Normal file
1
tests/cpp_ext/module/Makefile.dep
Normal file
@ -0,0 +1 @@
|
||||
FEATURES_REQUIRED += cpp
|
||||
3
tests/cpp_ext/module/Makefile.include
Normal file
3
tests/cpp_ext/module/Makefile.include
Normal file
@ -0,0 +1,3 @@
|
||||
# Use an immediate variable to evaluate `MAKEFILE_LIST` now
|
||||
USEMODULE_INCLUDES_module := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_module)
|
||||
32
tests/cpp_ext/module/module.cc
Normal file
32
tests/cpp_ext/module/module.cc
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample module C++ class
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "module.hh"
|
||||
|
||||
module_class::module_class() {}
|
||||
|
||||
module_class::~module_class() {}
|
||||
|
||||
void module_class::print_hello(void)
|
||||
{
|
||||
puts("Hello from C++ module");
|
||||
}
|
||||
34
tests/cpp_ext/module/module.cpp
Normal file
34
tests/cpp_ext/module/module.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample module C++ class
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "module.hh"
|
||||
|
||||
#error "This should not be built"
|
||||
|
||||
module_class::module_class() {}
|
||||
|
||||
module_class::~module_class() {}
|
||||
|
||||
void module_class::print(void)
|
||||
{
|
||||
puts("Hello from C++ module");
|
||||
}
|
||||
44
tests/cpp_ext/module/module.hh
Normal file
44
tests/cpp_ext/module/module.hh
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Sample module C++ class
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
class module_class
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief constructor
|
||||
*/
|
||||
module_class();
|
||||
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~module_class();
|
||||
|
||||
/**
|
||||
* @brief public function
|
||||
*/
|
||||
void print_hello(void);
|
||||
};
|
||||
|
||||
/** @} */
|
||||
#endif /* MODULE_H */
|
||||
19
tests/cpp_ext/tests/01-run.py
Executable file
19
tests/cpp_ext/tests/01-run.py
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2019 Inria
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect_exact('Hello from C++')
|
||||
child.expect_exact('Hello from C++ module')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
||||
Loading…
x
Reference in New Issue
Block a user