Skip to content

Commit 602e057

Browse files
committed
Changed C and C++ project source templates to use #pragma once directive.
Enables header files to use '#pragma once' instead of header include guards. Latter can still be used by overwriting project properties. Introduced the 'c.headers.include.guards.enable' and 'cpp.headers.include.guards.enable' project properties to restore the old behaviour. Changed the init code for C and C++ projects to be able to handle the new behaviour. Signed-off-by: kilo52 <[email protected]>
1 parent a0fb80a commit 602e057

File tree

19 files changed

+89
-40
lines changed

19 files changed

+89
-40
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.7-dev
1+
1.8.0-dev

c/01_executable/source/src/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE ${{VAR_ARTIFACT_BINARY_N
88
add_library(
99
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
1010
STATIC
11-
c/application.c
11+
c/example.c
1212
)
1313

1414
target_include_directories(

c/01_executable/source/src/main/c/application.c renamed to c/01_executable/source/src/main/c/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <stdio.h>
44

5-
#include "application.h"
5+
#include "example.h"
66

77

88
int getFortyTwo(){

c/01_executable/source/src/main/c/application.h renamed to c/01_executable/source/src/main/c/example.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
${{VAR_COPYRIGHT_HEADER}}
22

3-
#ifndef ${{VAR_PREFIX_INCLUDE_GUARD}}_APPLICATION_H
4-
#define ${{VAR_PREFIX_INCLUDE_GUARD}}_APPLICATION_H
3+
${{VAR_C_HEADER_BEGIN}}
54

65
/**
76
* Gets the number 42.
@@ -15,4 +14,4 @@ int getFortyTwo();
1514
*/
1615
void printText();
1716

18-
#endif // ${{VAR_PREFIX_INCLUDE_GUARD}}_APPLICATION_H
17+
${{VAR_C_HEADER_END}}

c/01_executable/source/src/main/c/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
${{VAR_COPYRIGHT_HEADER}}
22

3-
#include "application.h"
3+
#include "example.h"
44

55

66
int main(int argc, char** argv){
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright (C) ${{VAR_COPYRIGHT_YEAR}} ${{VAR_COPYRIGHT_HOLDER}}
22

33
add_test_suite(
4-
TEST_SUITE_NAME ApplicationTest
5-
TEST_SUITE_TARGET test_application
6-
TEST_SUITE_SOURCE c/test_application.c
4+
TEST_SUITE_NAME ExampleTest
5+
TEST_SUITE_TARGET test_example
6+
TEST_SUITE_SOURCE c/test_example.c
77
TEST_SUITE_LINK ${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
88
)

c/01_executable/source/src/main/tests/c/test_application.c renamed to c/01_executable/source/src/main/tests/c/test_example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "unity.h"
44

5-
#include "application.h"
5+
#include "example.h"
66

77

88
void setUp(){ }

c/02_library/source/src/main/include/example.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
* @see ${{VAR_PROJECT_ORGANISATION_URL}}
1111
*/
1212

13-
#ifndef ${{VAR_PREFIX_INCLUDE_GUARD}}_EXAMPLE_H
14-
#define ${{VAR_PREFIX_INCLUDE_GUARD}}_EXAMPLE_H
13+
${{VAR_C_HEADER_BEGIN}}
1514

1615
#include "${{VAR_ARTIFACT_BINARY_NAME}}_export.h"
1716

@@ -32,4 +31,4 @@
3231
*/
3332
${{VAR_ARTIFACT_BINARY_NAME_UPPER}}_EXPORT const char* getText();
3433

35-
#endif // ${{VAR_PREFIX_INCLUDE_GUARD}}_EXAMPLE_H
34+
${{VAR_C_HEADER_END}}

c/init.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,31 @@
3030
# VAR_ARTIFACT_BINARY_NAME_UPPER: The name of the binary file to be produced
3131
# by the project, in all upper-case.
3232
# VAR_PREFIX_INCLUDE_GUARD: The prefix to be used in all header include guards
33+
# VAR_C_HEADER_BEGIN: The code at the beginning of a C header file
34+
# VAR_C_HEADER_END: The code at the end of a C header file
3335

3436
function process_files_lvl_1() {
3537
replace_var "C_VERSION" "$var_c_version";
3638
replace_var "C_VERSION_LABEL" "$var_c_version_label";
3739
replace_var "ARTIFACT_BINARY_NAME" "$var_artifact_binary_name";
3840
replace_var "ARTIFACT_BINARY_NAME_UPPER" "$var_artifact_binary_name_upper";
41+
42+
local var_c_header_begin="#pragma once";
43+
local var_c_header_end="";
44+
get_boolean_property "c.headers.include.guards.enable" "false";
45+
if [[ "$PROPERTY_VALUE" == "true" ]]; then
46+
# shellcheck disable=SC2154
47+
var_c_header_begin="#ifndef ${var_project_name_upper}_EXAMPLE_H";
48+
var_c_header_begin+="${_NL}";
49+
var_c_header_begin+="#define ${var_project_name_upper}_EXAMPLE_H";
50+
var_c_header_end="#endif // ${var_project_name_upper}_EXAMPLE_H";
51+
fi
52+
replace_var "C_HEADER_BEGIN" "$var_c_header_begin" "h";
53+
replace_var "C_HEADER_END" "$var_c_header_end" "h";
54+
55+
# Kept for backwards compatibility
3956
# shellcheck disable=SC2154
40-
replace_var "PREFIX_INCLUDE_GUARD" "$var_project_name_upper";
57+
replace_var "PREFIX_INCLUDE_GUARD" "$var_project_name_upper" "h";
4158
}
4259

4360
# [API function]

cpp/01_executable/source/src/main/cpp/namespace/Application.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
${{VAR_COPYRIGHT_HEADER}}
22

3-
#ifndef ${{VAR_NAMESPACE_INCLUDE_GUARD}}_APPLICATION_H
4-
#define ${{VAR_NAMESPACE_INCLUDE_GUARD}}_APPLICATION_H
3+
${{VAR_CPP_HEADER_BEGIN}}
54

65
#include <string>
76

@@ -24,4 +23,4 @@ class Application {
2423
}; // END CLASS Application
2524

2625
${{VAR_NAMESPACE_DECL_END}}
27-
#endif // ${{VAR_NAMESPACE_INCLUDE_GUARD}}_APPLICATION_H
26+
${{VAR_CPP_HEADER_END}}

0 commit comments

Comments
 (0)