From 72b356b97d723a8bb9e331ef65af26c472bf7417 Mon Sep 17 00:00:00 2001 From: Jean Rubillon Date: Tue, 8 Sep 2020 20:50:48 +0100 Subject: [PATCH] Added option to remove setjmp.h from generated mock files as not supported on all embedded systems --- docs/CMock_Summary.md | 7 +++++++ lib/cmock_config.rb | 1 + lib/cmock_generator.rb | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index efd50a3..4e700e0 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -477,6 +477,13 @@ from the defaults. We've tried to specify what the defaults are below. * default: `['(?:__attribute__\s*\(+.*?\)+)']` +* `:has_setjmp_h`: + Some embedded systems don't have available. Setting this to false + removes references to this header file and the ability to use cexception. + + * default: true + + * `:subdir`: This is a relative subdirectory for your mocks. Set this to e.g. "sys" in order to create a mock for `sys/types.h` in `(:mock_path)/sys/`. diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 9515481..2a3e5f8 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -41,6 +41,7 @@ class CMockConfig :array_size_type => [], :array_size_name => 'size|len', :skeleton => false, + :has_setjmp_h => true, # Format to look for inline functions. # This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static") diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index f08cadd..f0372a3 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -19,6 +19,7 @@ class CMockGenerator @ordered = @config.enforce_strict_ordering @framework = @config.framework.to_s @fail_on_unexpected_calls = @config.fail_on_unexpected_calls + @has_setjmp_h = @config.has_setjmp_h @subdir = @config.subdir @@ -169,7 +170,9 @@ class CMockGenerator file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty? file << "#include \n" file << "#include \n" - file << "#include \n" + if @has_setjmp_h + file << "#include \n" + end file << "#include \"cmock.h\"\n" @includes_c_pre_header.each { |inc| file << "#include #{inc}\n" } file << "#include \"#{header_file}\"\n" @@ -205,7 +208,9 @@ class CMockGenerator end def create_extern_declarations(file) - file << "extern jmp_buf AbortFrame;\n" + if @has_setjmp_h + file << "extern jmp_buf AbortFrame;\n" + end if @ordered file << "extern int GlobalExpectCount;\n" file << "extern int GlobalVerifyOrder;\n"