Skip to content

Commit 8d4e872

Browse files
linguini1xiaoxiang781216
authored andcommitted
!testing/cmocka: Compile cmocka as a libary only by default
BREAKING CHANGE This commit introduces a Kconfig switch to include the cmocka binary built from cmocka_main.c. The default behaviour is now changed so that cmocka is built as a library only, which would be the desired behaviour for users creating their own cmocka projects. To restore the old behaviour (where the cmocka program is compiled), add CONFIG_TESTING_CMOCKA_PROG=y to your legacy configuration. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
1 parent 7daac30 commit 8d4e872

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

testing/cmocka/CMakeLists.txt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,22 @@ if(CONFIG_TESTING_CMOCKA)
7474
target_include_directories(cmocka PRIVATE ${INCDIR})
7575
target_compile_options(cmocka PRIVATE ${CFLAGS})
7676

77-
nuttx_add_application(
78-
NAME
79-
${CONFIG_TESTING_CMOCKA_PROGNAME}
80-
PRIORITY
81-
${CONFIG_TESTING_CMOCKA_PRIORITY}
82-
STACKSIZE
83-
${CONFIG_TESTING_CMOCKA_STACKSIZE}
84-
MODULE
85-
${CONFIG_TESTING_CMOCKA}
86-
INCLUDE_DIRECTORIES
87-
${INCDIR}
88-
SRCS
89-
cmocka_main.c
90-
DEPENDS
91-
cmocka)
77+
if(CONFIG_TESTING_CMOCKA_PROG)
78+
nuttx_add_application(
79+
NAME
80+
${CONFIG_TESTING_CMOCKA_PROGNAME}
81+
PRIORITY
82+
${CONFIG_TESTING_CMOCKA_PRIORITY}
83+
STACKSIZE
84+
${CONFIG_TESTING_CMOCKA_STACKSIZE}
85+
MODULE
86+
${CONFIG_TESTING_CMOCKA}
87+
INCLUDE_DIRECTORIES
88+
${INCDIR}
89+
SRCS
90+
cmocka_main.c
91+
DEPENDS
92+
cmocka)
93+
endif()
9294

9395
endif()

testing/cmocka/Kconfig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44
#
55

66
config TESTING_CMOCKA
7-
tristate "Enable libcmocka"
7+
bool "Enable libcmocka"
88
depends on LIBC_REGEX
99
default n
1010
---help---
1111
Enable libcmocka and run all testcases
1212

1313
if TESTING_CMOCKA
1414

15+
config TESTING_CMOCKA_PROG
16+
tristate "Compile cmocka binary"
17+
default n
18+
---help---
19+
Instead of just compiling cmocka as a library, the 'cmocka' binary is
20+
also included.
21+
22+
if TESTING_CMOCKA_PROG
23+
1524
config TESTING_CMOCKA_PROGNAME
1625
string "Program name"
1726
default "cmocka"
@@ -27,8 +36,13 @@ config TESTING_CMOCKA_STACKSIZE
2736
int "cmocka test stack size"
2837
default DEFAULT_TASK_STACKSIZE
2938

39+
endif # TESTING_CMOCKA_PROG
40+
3041
config TESTING_CMOCKA_LEAKDETECT
31-
bool "Memory leaks can be checked using cmocka, please use in local environment"
42+
bool "Detect leaks"
3243
default n
44+
---help---
45+
Memory leaks can be checked using cmocka, please use in a local
46+
environment.
3347

3448
endif

testing/cmocka/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ CFLAGS += -DHAVE_CLOCK_REALTIME=1
2929
CFLAGS += -DHAVE_STRUCT_TIMESPEC=1
3030
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/testing/cmocka
3131

32+
MODULE = $(CONFIG_TESTING_CMOCKA_PROG)
33+
34+
ifneq ($(CONFIG_TESTING_CMOCKA_PROG),)
3235
PROGNAME = $(CONFIG_TESTING_CMOCKA_PROGNAME)
3336
PRIORITY = $(CONFIG_TESTING_CMOCKA_PRIORITY)
3437
STACKSIZE = $(CONFIG_TESTING_CMOCKA_STACKSIZE)
35-
MODULE = $(CONFIG_TESTING_CMOCKA)
36-
37-
MAINSRC = $(CURDIR)/cmocka_main.c
38+
MAINSRC = $(CURDIR)/cmocka_main.c
39+
endif
3840

3941
# Download and unpack tarball if no git repo found
4042
ifeq ($(wildcard cmocka/.git),)

0 commit comments

Comments
 (0)