Skip to content

Commit b4ce9c3

Browse files
authored
Merge pull request #33 from swift-nav/rodrigor/language_standard
added cmake file to standardize company C/C++ standard
2 parents b390fa4 + 992595f commit b4ce9c3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

LanguageStandards.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Offers a simple function to set a number of targets to follow the company
3+
# wide C/C++ standard version. One can bypass some of these standards through
4+
# the following options:
5+
#
6+
# Single Value Options:
7+
#
8+
# C: C language standard to follow, current support values are 90, 99, and 11 (see: https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html)
9+
# CXX: C++ language standard to follow, current supported values are 98, 11, 14, 17, and 20 (see: https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html)
10+
#
11+
# Usage: set a target to conform to company standard
12+
#
13+
# add_executable(target_name main.cpp)
14+
# starling_set_language_standards(target_name)
15+
#
16+
# Usage: specify your own standards (C++17 and C98) on multiple targets
17+
#
18+
# add_library(library_target file1.c file2.cc)
19+
# add_executable(executable_target main.cpp)
20+
# target_link_libraries(executable_target PRIVATE library_target)
21+
#
22+
# starling_set_language_standards(executable_target library_target
23+
# C 99
24+
# CXX 17
25+
# )
26+
#
27+
28+
function(starling_set_language_standards)
29+
set(argOption "")
30+
set(argSingle "C" "CXX")
31+
set(argMulti "")
32+
33+
cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})
34+
35+
if(NOT x_C)
36+
set(x_C 99)
37+
endif()
38+
39+
if(NOT x_CXX)
40+
set(x_CXX 14)
41+
endif()
42+
43+
set_target_properties(${x_UNPARSED_ARGUMENTS}
44+
PROPERTIES
45+
C_STANDARD ${x_C}
46+
C_STANDARD_REQUIRED ON
47+
C_EXTENSIONS ON
48+
CXX_STANDARD ${x_CXX}
49+
CXX_STANDARD_REQUIRED ON
50+
CXX_EXTENSIONS OFF
51+
)
52+
endfunction()

0 commit comments

Comments
 (0)