Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

27 changes: 15 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
cmake_minimum_required(VERSION 3.4)

project(command_line_parser)

# global compiler flags
#set complier varibles/specifications
include(cmake/standardprojectsettings.cmake)

set(CMAKE_CXX_EXTENSIONS OFF) # OFF -> -std=c++14, ON -> -std=gnu++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED true)
#This lib has no location and has to be linked for the enforcing complier warnings
add_library(project_warnings INTERFACE)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
#complier warnings management.
include(cmake/compilerwarnings.cmake)
set_project_warnings(project_warnings)

if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-literal-suffix -s")
endif(WIN32)
#static analysis of code
include(cmake/staticanalyzer.cmake)

# setting relative paths for the install the directory
set(_include include)
Expand All @@ -25,3 +23,8 @@ set(_bin bin/${CMAKE_BUILD_TYPE})
#adding the directory of sample application and library
add_subdirectory(commandlineparser)
add_subdirectory(sample)

# to generate doxygen documents
include(cmake/doxygen.cmake)
enable_doxygen()

53 changes: 53 additions & 0 deletions cmake/compilerwarnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#This functions sets the complier warnings.
#Additional Feature : if WARNINGS_AS_ERRORS is set to true then warnings will be treated as errors.

function(set_project_warnings project_name)

option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" False)

set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
/w14242 # 'identfier': conversion from 'type1' to 'type1', possible loss
# of data
/w14254 # 'operator': conversion from 'type1:field_bits' to
# 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class
# virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not
# virtual instances of this class may not be destructed correctly
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable
# declared in the for-loop is used outside the for-loop scope
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing
# an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected
# operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend
# 'operator'?
/w14555 # expression has no effect; expected expression with side- effect
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # Enable warning on thread un-safe static member initialization
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may
# cause unexpected runtime behavior.
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
/w14928 # illegal copy-initialization; more than one user-defined
# conversion has been implicitly applied

)

#To make complier warnings as error.
if (${WARNINGS_AS_ERRORS})
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
endif()

if(MSVC)
set(PROJECT_WARNINGS ${MSVC_WARNINGS} )
endif()

target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS})

endfunction()
41 changes: 41 additions & 0 deletions cmake/doxygen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This is .chm document file generation script built using cmake support for doxygen.

function(enable_doxygen)

option(ENABLE_DOXYGEN "Enable doxygen doc builds of source" ON)

if(ENABLE_DOXYGEN)

find_package(Doxygen)

if(DOXYGEN_FOUND)

#setting required varibles for the doxygen file generation before the doxygen_add_docs command
file(MAKE_DIRECTORY docs/doxygendocuments)

set(DOXYGEN_EXTRACT_ALL NO)
set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
set(DOXYGEN_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/doxygendocuments)
set(DOXYGEN_PROJECT_BRIEF "Command Line Parser is a C++ based project for parsing the command line arguments and retrieve the values corresponding to a particular command.")
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_GENERATE_HTMLHELP YES)
set(DOXYGEN_CHM_FILE cmd_lib.chm)
set(DOXYGEN_SEARCHENGINE NO)
set(DOXYGEN_HHC_LOCATION "C:/Program Files (x86)/HTML Help Workshop/hhc.exe")
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${PROJECT_SOURCE_DIR}/README.md)

#doxygen_add_docs creates a custom target doxygen-docs
doxygen_add_docs(run_doxygen ${PROJECT_SOURCE_DIR}/commandlineparser/include ${PROJECT_SOURCE_DIR}/README.md)

#install doxygen files
INSTALL(FILES ${PROJECT_SOURCE_DIR}/docs/doxygendocuments/html/cmd_lib.chm DESTINATION docs/doxygendocuments)

else()

message ("Doxygen not found !!")

endif()

endif()

endfunction()
16 changes: 16 additions & 0 deletions cmake/standardprojectsettings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#This file is for setting the complier flags.

# setting few parameters
set(CMAKE_CXX_EXTENSIONS ON)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# setting of cmake_build_type doesnot works for MSVC from script file
# can set config type during generate step of cmake using command [cmake --build . --config <BUILD_TYPE>]
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)

set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type Release" FORCE)

endif()
27 changes: 27 additions & 0 deletions cmake/staticanalyzer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#This is script for static analysis of the code using cppcheck.

option(ENABLE_CPPCHECK "Enable static analysis with cppcheck" ON)

if(ENABLE_CPPCHECK)

find_program(CPPCHECK cppcheck)

if(CPPCHECK)

file(MAKE_DIRECTORY docs/staticanalyzer)
set(REPORT_DIR docs/staticanalyzer)
set(CMAKE_CXX_CPPCHECK_ARGS --language=c++ --std=c++14 --xml --enable=all --suppress=missingInclude ${CMAKE_SOURCE_DIR}/commandlineparser/include/*.h ${CMAKE_SOURCE_DIR}/commandlineparser/src/*.cpp)
set(CMAKE_CXX_CPPCHECK ${CPPCHECK} ${CMAKE_CXX_CPPCHECK_ARGS} 2> ${PROJECT_SOURCE_DIR}/${REPORT_DIR}/static_analysis_report.xml )

add_custom_target(
run_cppcheck
COMMAND ${CMAKE_CXX_CPPCHECK}
COMMENT "running cppcheck"
)

else()
message(SEND_ERROR "cppcheck requested but executable not found !")
endif()

endif()

3 changes: 0 additions & 3 deletions commandlineparser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ install(EXPORT cmd_lib FILE cmd_lib.cmake DESTINATION "lib/cmake/cmd_lib")
#install the config.cmake file
install(FILES cmd_lib-config.cmake DESTINATION "lib/cmake/cmd_lib")

#install doxygen files
install(FILES ../docs/html/index.html ../docs/html/cmd_lib.chm DESTINATION docs)

install(FILES ../docs/html/index.html ../docs/html/cmd_lib.chm DESTINATION ../docs/doxygendocuments)


Binary file removed docs/doxygendocuments/cmd_lib.chm
Binary file not shown.
Binary file added docs/doxygendocuments/html/cmd_lib.chm
Binary file not shown.
Loading