diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f2dd0de --- /dev/null +++ b/.clang-format @@ -0,0 +1,168 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + 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 +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + - Regex: '.*' + Priority: 3 + SortPriority: 0 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: true +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +... + diff --git a/.cmake-format.yml b/.cmake-format.yml new file mode 100644 index 0000000..bb6ff44 --- /dev/null +++ b/.cmake-format.yml @@ -0,0 +1,218 @@ +# ---------------------------------- +# Options affecting listfile parsing +# ---------------------------------- +with section("parse"): + + # Specify structure for custom cmake functions + additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'], + 'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}} + + # Specify variable tags. + vartags = [] + + # Specify property tags. + proptags = [] + +# ----------------------------- +# Options affecting formatting. +# ----------------------------- +with section("format"): + + # How wide to allow formatted cmake files + line_width = 80 + + # How many spaces to tab for indent + tab_size = 2 + + # If an argument group contains more than this many sub-groups (parg or kwarg + # groups) then force it to a vertical layout. + max_subgroups_hwrap = 1 + + # If a positional argument group contains more than this many arguments, then + # force it to a vertical layout. + max_pargs_hwrap = 6 + + # If a cmdline positional group consumes more than this many lines without + # nesting, then invalidate the layout (and nest) + max_rows_cmdline = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = True + + # If the trailing parenthesis must be 'dangled' on its on line, then align it + # to this reference: `prefix`: the start of the statement, `prefix-indent`: + # the start of the statement, plus one indentation level, `child`: align to + # the column of the arguments + dangle_align = 'prefix' + + # If the statement spelling length (including space and parenthesis) is + # smaller than this amount, then force reject nested layouts. + min_prefix_chars = 1 + + # If the statement spelling length (including space and parenthesis) is larger + # than the tab width by more than this amount, then force reject un-nested + # layouts. + max_prefix_chars = 10 + + # If a candidate layout is wrapped horizontally but it exceeds this many + # lines, then reject the layout. + max_lines_hwrap = 2 + + # What style line endings to use in the output. + line_ending = 'unix' + + # Format command names consistently as 'lower' or 'upper' case + command_case = 'canonical' + + # Format keywords consistently as 'lower' or 'upper' case + keyword_case = 'unchanged' + + # A list of command names which should always be wrapped + always_wrap = [] + + # If true, the argument lists which are known to be sortable will be sorted + # lexicographicall + enable_sort = True + + # If true, the parsers may infer whether or not an argument list is sortable + # (without annotation). + autosort = False + + # By default, if cmake-format cannot successfully fit everything into the + # desired linewidth it will apply the last, most agressive attempt that it + # made. If this flag is True, however, cmake-format will print error, exit + # with non-zero status code, and write-out nothing + require_valid_layout = False + + # A dictionary mapping layout nodes to a list of wrap decisions. See the + # documentation for more information. + layout_passes = {} + +# ------------------------------------------------ +# Options affecting comment reflow and formatting. +# ------------------------------------------------ +with section("markup"): + + # What character to use for bulleted lists + bullet_char = '*' + + # What character to use as punctuation after numerals in an enumerated list + enum_char = '.' + + # If comment markup is enabled, don't reflow the first comment block in each + # listfile. Use this to preserve formatting of your copyright/license + # statements. + first_comment_is_literal = False + + # If comment markup is enabled, don't reflow any comment block which matches + # this (regex) pattern. Default is `None` (disabled). + literal_comment_pattern = None + + # Regular expression to match preformat fences in comments default= + # ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$' + + # Regular expression to match rulers in comments default= + # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'`` + ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$' + + # If a comment line matches starts with this pattern then it is explicitly a + # trailing comment for the preceeding argument. Default is '#<' + explicit_trailing_pattern = '#<' + + # If a comment line starts with at least this many consecutive hash + # characters, then don't lstrip() them off. This allows for lazy hash rulers + # where the first hash char is not separated by space + hashruler_min_length = 10 + + # If true, then insert a space between the first hash char and remaining hash + # chars in a hash ruler, and normalize its length to fill the column + canonicalize_hashrulers = True + + # enable comment markup parsing and reflow + enable_markup = False + +# ---------------------------- +# Options affecting the linter +# ---------------------------- +with section("lint"): + + # a list of lint codes to disable + disabled_codes = [] + + # regular expression pattern describing valid function names + function_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid macro names + macro_pattern = '[0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope + global_var_pattern = '[0-9A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope (but internal semantic) + internal_var_pattern = '_[0-9A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with local + # scope + local_var_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid names for privatedirectory + # variables + private_var_pattern = '_[0-9a-z_]+' + + # regular expression pattern describing valid names for publicdirectory + # variables + public_var_pattern = '[0-9A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for keywords used in + # functions or macros + keyword_pattern = '[0-9A-Z_]+' + + # In the heuristic for C0201, how many conditionals to match within a loop in + # before considering the loop a parser. + max_conditionals_custom_parser = 2 + + # Require at least this many newlines between statements + min_statement_spacing = 1 + + # Require no more than this many newlines between statements + max_statement_spacing = 1 + max_returns = 6 + max_branches = 12 + max_arguments = 5 + max_localvars = 15 + max_statements = 50 + +# ------------------------------- +# Options affecting file encoding +# ------------------------------- +with section("encode"): + + # If true, emit the unicode byte-order mark (BOM) at the start of the file + emit_byteorder_mark = False + + # Specify the encoding of the input file. Defaults to utf-8 + input_encoding = 'utf-8' + + # Specify the encoding of the output file. Defaults to utf-8. Note that cmake + # only claims to support utf-8 so be careful when using anything else + output_encoding = 'utf-8' + +# ------------------------------------- +# Miscellaneous configurations options. +# ------------------------------------- +with section("misc"): + + # A dictionary containing any per-command configuration overrides. Currently + # only `command_case` is supported. + per_command = {} + diff --git a/.gitignore b/.gitignore index 259148f..c35bfc8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,13 @@ *.exe *.out *.app +_*/* +bin/* +build/* +.DS_Store +.DS_Store/* + +*.mov +*.mp4 +*.m4a +docs/*/*.md \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b9255f4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required( + VERSION 3.1...3.16 + FATAL_ERROR +) +set( + CMAKE_CXX_STANDARD + 17 +) +project( + basic_113 + VERSION 0.1.0 + LANGUAGES CXX + DESCRIPTION "basic_113 Hello, Static Library!" +) +set( + CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${PROJECT_SOURCE_DIR}/bin +) + +set( + LIB_DIR + ${PROJECT_SOURCE_DIR}/lib/ +) + +add_subdirectory(src) +add_subdirectory(lib) diff --git a/README.md b/README.md index c92219b..cf10206 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,238 @@ -# C++ Application with 'CMake' - -## Prerequisite - -### OS Environment -- MacOS 10.11.6+ -- Ubuntu 20.04+ - -### Language Environment -- [Clang 8.0.0+](https://clang.llvm.org/) -- [Python 3.7+](https://www.python.org/) -- [Ruby 2.7.1+](https://www.ruby-lang.org/en/) -- [Rust 1.42.0+](https://www.rust-lang.org/) - -### VS Code -- [VS Code](https://code.visualstudio.com/) OR [Eclipse Theia](https://theia-ide.org/) - -### VS Code Extension -- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) -- [CMake Tool](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) -- [CMake](https://marketplace.visualstudio.com/items?itemName=twxs.cmake) -- [reStructuredText](https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext) -- [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) -- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) -- [PlantUML](https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml) -- [cmake-format](https://marketplace.visualstudio.com/items?itemName=cheshirekow.cmake-format) - -### Tool and Library -- [CMake](https://cmake.org/) -- [Ninja](https://ninja-build.org/) -- [clang-format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) -- [cmake_format](https://github.com/cheshirekow/cmake_format) -- [Doxygen](http://www.doxygen.nl/) -- [Graphviz](http://graphviz.org/) -- [Sphinx](https://www.sphinx-doc.org/) -- [Sphinx bootstrap theme](https://github.com/ryan-roemer/sphinx-bootstrap-theme) -- [Library libpng 1.6.37+](http://www.libpng.org/pub/png/libpng.html) -- [Library boost 1.72.0+](https://www.boost.org/) -- [Library gettext 0.20.1](https://www.gnu.org/software/gettext/) -- [Library SQLite 3.31.1+](https://www.sqlite.org/index.html) -- [Library SQLite 3.8.10.2+](https://www.sqlite.org/index.html) For "basic_126" - -### Library on Ubuntu -- Library language-pack-de -- Library language-pack-zh-hans -- Library language-pack-zh-hant, optional - -## Liste -- **Hello, CMake!** Hello Application with 'CMake' "basic_101" [Youtube Video](https://youtu.be/I2-fIgkGfy8) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_101) -- **Hello, Ninja!** Hello Application with 'CMake' and 'Ninja' "basic_102" [Youtube Video](https://youtu.be/wPpknWBG3v4) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_102) -- **Hello, 'ccmake'!** 'CMake' Tool 'ccmake' "basic_103" [Youtube Video](https://youtu.be/yV7kopPr2Dk) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_103) -- **Hello, 'cmake'!** Where are The 'CMake' Commands from? "basic_104" [Youtube Video](https://youtu.be/Dkfdqyeh4OM) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_104) -- **Hello, VS Code!** Develop The 'CMake' Project with VS Code "basic_105" [Youtube Video](https://youtu.be/GgImAx-TTfY) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_105) -- **Hello, CMake Script!** CMake's Scripting Language for Building Systems "basic_106" [Youtube Video](https://youtu.be/frS4Zc4zhMU) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_106) -- **Hello, 'cmake_format'!** How to Format the 'CMake's File "basic_107" [Youtube Video](https://youtu.be/mhM12sqDKpE) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_107) -- **Hello, C++ Style!** Formatting the 'C/C++'s Codes "basic_108" [Youtube Video](https://youtu.be/uN6OollV1xo) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_108) -- **Hello, C++ Header!** Using a Include File from Other Folder "basic_109" [Youtube Video](https://youtu.be/dHt_i7-sBNM) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_109) -- **Hello, Common Header!** Linking a Comman Include file in C++ "basic_110" [Youtube Video](https://youtu.be/XHcIdPFaTw0) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_110) -- **Hello, C++ Library!** Build a Single Header File with CMake "basic_111" [Youtube Video](https://youtu.be/a0FdU06UGtQ) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_111) -- **Hello, Default Include Paths!** Query the Default Include Directories "basic_112" [Youtube Video](https://youtu.be/-1hA3QqJKEw) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_112) -- **Hello, Static Library!** Creating, Building and Using Static Library "basic_113" [Youtube Video](https://youtu.be/ztmYpK7lFCI) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_113) -- **Hello, Different Folders!** Storing Header and Implementation File in Different Folders "basic_114" [Youtube Video](https://youtu.be/nTc_m7ELkzE) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_114) -- **Hello, PRIVATE/PUBLIC!** Difference between PRIVATE/PUBLIC with target_include_directories "basic_115" [Youtube Video](https://youtu.be/pmRWYYEXLoc) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_115) -- **Hello, Configure File!** Generating a C++ Configure File with CMake "basic_116" [Youtube Video](https://youtu.be/thJFmINbG0U) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_116) -- **Hello, Package!** Finding an Executable Package For C++ Code "basic_117" [Youtube Video](https://youtu.be/D5sny0H8jUM) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_117) -- **Hello, Doxygen!** Generating Documentation From annotated 'C/C++'s Sources "basic_118" "basic_118" [Youtube Video](https://youtu.be/T1CBiV09v8w) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_118) -- **Hello, Module!** Using Your Custom CMake-Find Module "basic_119" [Youtube Video](https://youtu.be/7SkNPLFLrEc) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_119) -- **Hello, Breathe!** Generating functional Documentation For 'C/C++'s Sources "basic_120" [Youtube Video](https://youtu.be/RE6rbuy11Z0) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_120) -- **Hello, Third Party Library!** Using Third Party Library For C++ Sources "basic_121" [Youtube Video](https://youtu.be/fPAShAPvlio) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_121) -- **Hello, Library's Components!** Using Library's Components For C++ Sources "basic_122" [Youtube Video](https://youtu.be/AMn65HQ5WAE) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_122) -- **Hello, Module's Variables!** Using Find-Module's Variables with CMake Sources "basic_123" [Youtube Video](https://youtu.be/UuMJGiRZmlA) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_123) -- **Hello, Targets!** Building multiple Targets using CMake on Ubuntu 20.04 "basic_124" [Youtube Video](https://youtu.be/-T4BMEI2agc) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_124) -- **Hello, MULTOS!** Building C++ Project on Multiple Operating System using CMake "basic_125" [Youtube Video](https://youtu.be/fBkFHSka2NA) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_125) -- **Hello, Multiple Versions!** Building Multiple Versions of a Shared Library Using CMake "basic_126" [Youtube Video](https://youtu.be/GmXbz3yfhWc) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_126) -- **Hello, $PATH!** Creating a Symbolic Link for a Library "basic_127" [Youtube Video](https://youtu.be/DFdMZvpCoCg) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_127) -- **Hello, GitHub! Formatting Library from Repositories Using CMake "basic_128" [Youtube Video](https://youtu.be/27zsR2It2K8) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_128) -- **Hello, Hunter!** CMake-based Cross-Platform Package Manager for C++ Projects "basic_129" [Youtube Video](https://youtu.be/QWBu7vykWpc) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_129) -- **Hello, Multiple Projects!** Creating a Solution with C++ Multiple Projects "basic_130" [Youtube Video](https://youtu.be/Vt5TEcFm0Hg) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_130) -- **Hello, Output!** Changing the output default directory in a dedicated directory "basic_131" [Youtube Video](https://youtu.be/HnXP8jgryC4) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_131) -- **Hello, Custom Target!** Adding and Using A Custom Target in CMake "basic_132" [Youtube Video](https://youtu.be/xcJbhFgVI04) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_132) -- **Hello, Ninja Multi-Config!** Creating a Solution with C++ Multiple Configuration "basic_133" [Youtube Video](https://youtu.be/TLpscEDcI1U) | [Short Video](https://youtu.be/l3DCnXTSJuA) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_133) -- **Hello, COMPILE_DEFINITIONS!** How to specify preprocessor definitions through CMake "basic_134" [Youtube Video](https://youtu.be/4GPcMCwWgVM) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_134) -- **Hello, Generator Expression!** How to Learn Generator Expression in CMake "basic_135" [Youtube Video](https://youtu.be/xZkakSO3_II) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_135) -- **Hello, Targets 2.0!** How to Use Generator Expression in C++ Project "basic_136" [Youtube Video](https://youtu.be/hEWES7JgrfU) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_136) -- **Hello, Object Library!** How to Create and Use The Object File in CMake "basic_137"
[Youtube Video](https://youtu.be/xj1fx2Xsl-U) | [Short Video](https://youtu.be/edcA9puzDgU) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_137) -- **Hello, Object File!** How to Obtain and Apply The Object File of Library in CMake "basic_138"
[Youtube Video](https://youtu.be/1LMmQ_3kjFA) | [Short Video](https://youtu.be/9Y-alzDxJpg) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_138) -- **Hello, install:exe!** How to install executable from the project to local "basic_139"
[Youtube Video](https://youtu.be/nJj1efRi6oI) | [Short Video](https://youtu.be/edcA9puzDgU) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_139) -- **Hello, install:multi!** How to install executable on local with "Ninja Multi-Config" "basic_140"
[Youtube Video](https://youtu.be/tCN-eFZN8xE) | [Short Video](https://youtu.be/oB6Ujd0BVno) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_140) -- **Hello, install:DESTDIR!** How to use CMake Environment Variable `DESTDIR` "basic_141"
[Youtube Video](https://youtu.be/NtYyjwSjt9Q) | [Short Video](https://youtu.be/15Zrf_WZXPU) | [Code](https://github.com/cnruby/w3h1_cmake/tree/basic_141) +

Hello, Static Library!

+

Creating, Building and Using Static Library

+
+
+[@Gitter](https://gitter.im/cnruby) :gitter.im/cnruby
+Code ID: basic_113
+Code Name: Hello, Static Library!
+

+ + + +* [Youtube Video](https://youtu.be/ztmYpK7lFCI) + + + +

TABLE of CONTENTS

+ +- [What is This Structure of Project?](#what-is-this-structure-of-project) + - [The Folder's Structure](#the-folders-structure) + - [The Command's Structure](#the-commands-structure) + - [The Real Command's Structure](#the-real-commands-structure) + - [The Process's Structure](#the-processs-structure) +- [Analyze The Build of CMake](#analyze-the-build-of-cmake) + - [Code of The Listfile of 'lib'](#code-of-the-listfile-of-lib) + - [Code of The Listfile of 'src'](#code-of-the-listfile-of-src) + - [Demonstrate Build's Process on CMake](#demonstrate-builds-process-on-codecmakecode) +- [Analyze The Build of Compiler's Commands](#analyze-the-build-of-compilers-commands) + - [Build's Commands of C++ Compiler](#builds-commands-of-c-compiler) + - [Demonstrate Build's Commands of C++ Compiler](#demonstrate-builds-commands-of-c-compiler) + - [How to Graph the relationship of Build's Process](#how-to-graph-the-relationship-of-builds-process) +- [Final Summary](#final-summary) +- [References](#references) +- [The Real Process's Structure](#the-real-processs-structure) +- [The Project Command](#the-project-command) + - [Formatting The Codes](#formatting-the-codes) + - [Get The Code with Shell Commands](#get-the-code-with-shell-commands) + - [Build and Run The Project](#build-and-run-the-project) +

+ + + +## What is This Structure of Project? +### The Folder's Structure +```bash +## +. +├── CMakeLists.txt +├── lib +│ ├── CMakeLists.txt +│ ├── header.cxx +│ └── header.hxx +└── src + ├── CMakeLists.txt + └── main.cxx +# +``` +

+ + + +![_image](docs/113/image/what-command.png) +### The Command's Structure +

+ + + +![_image](docs/113/image/what-command-real.png) +### The Real Command's Structure +

+ + + +![_image](docs/113/image/what-process.png) +### The Process's Structure +

+ + + +## Analyze The Build of CMake +![_image](./docs/113/image/basic_113-07.png) +

+ + + +```bash +## +add_library(lib_113 STATIC ${LIB_DIR}/header.cxx) +#target_include_directories( +# lib_113 +# PRIVATE +# ${LIB_DIR} +#) +# +``` +### Code of The Listfile of 'lib' +

+ + + +```bash +## +add_executable( + main_113 + main.cxx +) +target_include_directories( + main_113 + PRIVATE + ${LIB_DIR}/ +) +target_link_libraries(main_113 lib_113) +# +``` +### Code of The Listfile of 'src' +

+ + + +### Demonstrate Build's Process on CMake + + + + +## Analyze The Build of Compiler's Commands +Analyze The Build of Compiler's Commands +

+ + + +```bash +##!/bin/bash +#[1/4]: Compile +c++ -I./lib -MD -MF ./bin/main.cxx.o.d -c ./src/main.cxx \ + -o ./bin/main.cxx.o +#[2/4]: Compile +c++ -I./lib -MD -MF ./bin/header.cxx.o.d -c ./lib/header.cxx \ + -o ./bin/header.cxx.o +#[3/4]: Package +cmake -E rm -f ./bin/liblib_113.a && \ + ar qc ./bin/liblib_113.a ./bin/header.cxx.o && \ + ranlib ./bin/liblib_113.a && cmake -E touch ./bin/liblib_113.a +#[4/4] : Link +c++ ./bin/main.cxx.o -o ./bin/main_113 ./bin/liblib_113.a +# +``` +### Build's Commands of C++ Compiler +

+ + + +### Demonstrate Build's Commands of C++ Compiler + + + + +![_image](docs/113/image/how.png) +### How to Graph the relationship of Build's Process +

+ + + +![_image](docs/113/image/what-process.png) +## Final Summary +

+ + + +

感谢大家观看!

+ +@Gitter: gitter.im/cnruby
+ +@Github: github.com/cnruby
+ +@Twitter: twitter.com/cnruby
+ +@Blogspot: cnruby.blogspot.com ## References -- [Learning CMake: A beginner's guide](https://tuannguyen68.gitbooks.io/learning-cmake-a-beginner-s-guide/content/index.html) -- [Modern CMake](https://cliutils.gitlab.io/modern-cmake/) -- [CMake Community Wiki](https://gitlab.kitware.com/cmake/community/-/wikis/home) -- [CMake BASIS](https://cmake-basis.github.io/quickstart.html) -- [CMake Cookbook Github](https://github.com/dev-cafe/cmake-cookbook) -- [CMake Cookbook 中文](https://chenxiaowei.gitbook.io/cmake-cookbook/) -- [CMake questions forum](https://discourse.cmake.org) -- [Getting started with cmake](https://riptutorial.com/cmake) - -## @cnruby -- [@Gitter](https://gitter.im/cnruby) -- [@Blog](https://www.blogger.com/blogger.g?tab=mj1&blogID=19758264#allposts/postNum=0) -- [@Twitter](https://twitter.com/cnruby) + +- https://cmake.org/cmake/help/latest/command/include_directories.html +- https://cmake.org/cmake/help/latest/command/target_include_directories.html +- https://stackoverflow.com/questions/31969547/what-is-the-difference-between-include-directories-and-target-include-directorie +- https://stackoverflow.com/questions/26243169/cmake-target-include-directories-meaning-of-scope +- https://gitlab.kitware.com/cmake/cmake/issues/19802 +- https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/ +- http://mariobadr.com/creating-a-header-only-library-with-cmake.html +- https://stackoverflow.com/questions/18869282/initialize-char +- https://stackoverflow.com/questions/2587349/initializing-char-and-char-pointers +- https://stackoverflow.com/questions/18963888/c-char-initialization-in-constructor +- https://stackoverflow.com/questions/13703647/how-to-properly-add-include-directories-with-cmake +- https://stackoverflow.com/questions/9834067/difference-between-char-and-const-char +- https://stackoverflow.com/questions/2186246/what-is-o-file +- https://www.online-convert.com/file-format/o + + + +## The Real Process's Structure +![_image](docs/113/image/what-process-real.png) + + + +## The Project Command + + + +### Formatting The Codes +```bash +ruby format-codes.rb +``` + + +### Get The Code with Shell Commands +```bash +git clone https://github.com/cnruby/w3h1_cmake.git basic_113 +cd basic_113 +git checkout basic_113 +code . +``` + + + +### Build and Run The Project +```bash +cmake -GNinja -Bbuild/ +cmake --build build/ --clean-first -v +cmake --build build/ --target clean +cmake --build build/ --clean-first -v &> v11.txt +./bin/main_113 +rm -rf ./build/ ./bin/* +./shell/start.sh +``` \ No newline at end of file diff --git a/docs/113/image/basic_113-07.png b/docs/113/image/basic_113-07.png new file mode 100644 index 0000000..d358b9c Binary files /dev/null and b/docs/113/image/basic_113-07.png differ diff --git a/docs/113/image/basic_113-11.png b/docs/113/image/basic_113-11.png new file mode 100644 index 0000000..64b4d16 Binary files /dev/null and b/docs/113/image/basic_113-11.png differ diff --git a/docs/113/image/how.png b/docs/113/image/how.png new file mode 100644 index 0000000..435318f Binary files /dev/null and b/docs/113/image/how.png differ diff --git a/docs/113/image/what-command-real.png b/docs/113/image/what-command-real.png new file mode 100644 index 0000000..a33de3d Binary files /dev/null and b/docs/113/image/what-command-real.png differ diff --git a/docs/113/image/what-command.png b/docs/113/image/what-command.png new file mode 100644 index 0000000..2411f51 Binary files /dev/null and b/docs/113/image/what-command.png differ diff --git a/docs/113/image/what-process-real.png b/docs/113/image/what-process-real.png new file mode 100644 index 0000000..7776898 Binary files /dev/null and b/docs/113/image/what-process-real.png differ diff --git a/docs/113/image/what-process.png b/docs/113/image/what-process.png new file mode 100644 index 0000000..f9f54aa Binary files /dev/null and b/docs/113/image/what-process.png differ diff --git a/docs/how.puml b/docs/how.puml new file mode 100644 index 0000000..a6fc09b --- /dev/null +++ b/docs/how.puml @@ -0,0 +1,82 @@ +@startuml +scale 600 width +skinparam backgroundColor #FFEBDC +scale 1 +skinparam backgroundColor LightYellow +skinparam state { + BackgroundColor<> Olive +} + +[*] --> MAIN_COMPILE : BEGIN +[*] -left-> LIBRARY_COMPILE : BEGIN + +state MAIN_COMPILE { + state "-I./lib/header.hxx" as header_hxx_main + header_hxx_main : main.cxx + state "main.cxx.o" as main_cxx_o <> + main_cxx_o : "OUTPUT File" + state "main.cxx.o.d" as main_cxx_o_d <> + main_cxx_o_d : "OUTPUT File" + + [*] -right-> header_hxx_main : 1/4 + header_hxx_main -> main_cxx_o : compile 'main.cxx' + header_hxx_main -> main_cxx_o_d : compile 'main.cxx' + main_cxx_o_d -> main_cxx_o : "INPUT FILE" +} + +state LIBRARY_COMPILE { + state "-I./lib/header.hxx" as header_hxx_lib + header_hxx_lib : header.cxx + state "header.cxx.o" as header_cxx_o <> + header_cxx_o : "OUTPUT File" + state "header.cxx.o.d" as header_cxx_o_d <> + header_cxx_o_d : "OUTPUT File" + + [*] -right-> header_hxx_lib : 2/4 + header_hxx_lib --> header_cxx_o : compile 'header.cxx' + header_hxx_lib --> header_cxx_o_d : compile 'header.cxx' + header_cxx_o_d -> header_cxx_o : "INPUT FILE" +} + +state LIBRARY_PACKAGE { + state "./bin/header.hxx.o" as header_hxx_pkg + header_hxx_pkg : header.hxx.o + state "**liblib_113.a**" as liblib_113_a <> + liblib_113_a : "OUTPUT File" + + [*] -right-> header_hxx_pkg : 3/4 + header_hxx_pkg -right-> liblib_113_a : package 'header.cxx.o' +} +header_cxx_o --> header_hxx_pkg + +state MAIN_LINK { + state "./src/main.cxx" as main_cxx_link + main_cxx_link : main.cxx + state "**main_113**" as main_113 <> + main_113 : "OUTPUT File" + + [*] -right-> main_cxx_link : 4/4 + main_cxx_o --> main_cxx_link : 4/4 + liblib_113_a --> main_cxx_link : 4/4 + main_cxx_link -> main_113 : link 'main.cxx' +} + +note bottom of liblib_113_a +This is a Library +end note + +note right of main_113 +This is a Executable +end note + +title + How to Build the State of Project "basic_113"? +end title + +header +Tips: version 1.0 +endheader + +center footer Develop C/C++ Application with the 'CMake' + +@enduml \ No newline at end of file diff --git a/docs/output/tree.txt b/docs/output/tree.txt new file mode 100644 index 0000000..a42e875 --- /dev/null +++ b/docs/output/tree.txt @@ -0,0 +1,11 @@ +# +. +├── CMakeLists.txt +├── lib +│ ├── CMakeLists.txt +│ ├── header.cxx +│ └── header.hxx +└── src + ├── CMakeLists.txt + └── main.cxx +# \ No newline at end of file diff --git a/docs/what-command-real.puml b/docs/what-command-real.puml new file mode 100644 index 0000000..42968c2 --- /dev/null +++ b/docs/what-command-real.puml @@ -0,0 +1,67 @@ +@startuml +scale 1000 width +skinparam backgroundColor #FFEBDC +scale 1.5 + +skinparam Folder { + backgroundColor Olive + borderColor orange +} + +package C++_Main <> as cxx_main { + package target_link_libraries <<...>> { + rectangle main_113 <> as main_113_link + rectangle lib_113 <> as library_link + } + package add_executable <<...>> { + rectangle main_113 <> as main_113 + rectangle main.cxx <> as main_cxx + } + Folder target_include_directories <<**PRIVATE**>> as include_exe { + Folder main_113 <> as exe_113 + Folder <<./lib/>> as lib_dir + } + + main_113 *--> main_cxx + main_113 *--> exe_113 + exe_113 *--> lib_dir + main_113 *--> main_113_link + main_113_link *--> library_link +} + + +package C++_Library <> as cxx_lib { + package add_library <> as add_library { + rectangle lib_113 <> + } + Folder target_include_directories <<**PRIVATE**>> as include_lib { + Folder <<./lib/>> as lib + rectangle lib_113 <> as library + } + package Library_Code <<**./lib/**>> as library_code { + rectangle header.hxx as header_hxx + rectangle header.cxx as header_cxx + } + + lib_113 *-right-> library + lib_113 *--> header_cxx + library *--> lib + lib *.(0).> header_hxx +} + +cxx_main -(0)-> cxx_lib +'library_link *.(0).> library +lib_dir *.(0).> header_hxx + + +title + What is This Real Command's Structure of Project "basic_113"? +end title + +header +Tips: version 1.0 +endheader + +center footer Develop C/C++ Application with the 'CMake' + +@enduml \ No newline at end of file diff --git a/docs/what-command.puml b/docs/what-command.puml new file mode 100644 index 0000000..5dfc602 --- /dev/null +++ b/docs/what-command.puml @@ -0,0 +1,67 @@ +@startuml +scale 1000 width +skinparam backgroundColor #FFEBDC +scale 0.6 + +skinparam Folder { + backgroundColor Olive + borderColor orange +} + +package C++_Main <> as cxx_main { + package target_link_libraries <<...>> { + rectangle main_113 <> as main_113_link + rectangle lib_113 <> as library_link + } + package add_executable <<...>> { + rectangle main_113 <> as main_113 + rectangle main.cxx <> as main_cxx + } + Folder target_include_directories <<**PRIVATE**>> as include_exe { + rectangle main_113 <> as exe_113 + Folder <<./lib/>> as main_lib_dir + } + + main_113 *--> main_cxx + main_113 *--> exe_113 + exe_113 *--> main_lib_dir + main_113 *--> main_113_link + main_113_link *--> library_link +} + + +package C++_Library <> as cxx_lib { + package add_library <> as add_library { + rectangle lib_113 <> as lib + } + 'Folder target_include_directories <<**PRIVATE**>> as include_lib { + ' Folder <<./lib/>> as lib_dir + ' rectangle lib_113 <> + '} + package Library_Code <<**./lib/**>> as library_code { + rectangle header.hxx as header_hxx + rectangle header.cxx as header_cxx + } + + lib *.right.> lib_113 + lib *--> header_cxx + lib_113 *..> lib_dir + lib_dir *.(0).> header_hxx +} + +cxx_main -(0)-> cxx_lib +'library_link *.(0).> lib_113 +main_lib_dir *.(0).> header_hxx + + +title + What is This Command's Structure of Project "basic_113"? +end title + +header +Tips: version 1.0 +endheader + +center footer Develop C/C++ Application with the 'CMake' + +@enduml \ No newline at end of file diff --git a/docs/what-process-real.puml b/docs/what-process-real.puml new file mode 100644 index 0000000..5829e93 --- /dev/null +++ b/docs/what-process-real.puml @@ -0,0 +1,64 @@ +@startuml +scale 1200 width +skinparam backgroundColor #FFEBDC +scale 1.5 + +package Project_C++ as project { + rectangle header.hxx <> as header_hxx + rectangle header.cxx <> as header_cxx + rectangle main.cxx <> as main + rectangle CMakeLists.txt <> as begin + rectangle CMakeLists.txt <> as src_list + rectangle CMakeLists.txt <> as lib_list + 'rectangle main_cxx.o <> as o_file + + note right of begin + add_subdirectory(lib) + add_subdirectory(src) + endnote + note top of lib_list + add_library( + lib_113 + STATIC ${LIB_DIR}/header.cxx + ) + target_include_directories( + lib_113 + PRIVATE + ${LIB_DIR} + ) + endnote + note right of src_list + add_executable( + main_113 + main.cxx + ) + target_include_directories( + main_113 + PRIVATE + ${LIB_DIR} + ) + target_link_libraries( + main_113 + lib_113 + ) + endnote +} + +begin *--> src_list +begin *--> lib_list +src_list -left-> main +'local_list .(0).> main +lib_list -left-> header_cxx +lib_list -left-> header_hxx + +title + What is This Real Process's Structure of Project "basic_113"? +end title + +header +Tips: version 1.0 +endheader + +center footer Develop C/C++ Application with the 'CMake' + +@enduml \ No newline at end of file diff --git a/docs/what-process.puml b/docs/what-process.puml new file mode 100644 index 0000000..7cb80b5 --- /dev/null +++ b/docs/what-process.puml @@ -0,0 +1,59 @@ +@startuml +scale 700 width +skinparam backgroundColor #FFEBDC +scale 1.2 + +package Project_C++ as project { + rectangle header.hxx <> as header_hxx + rectangle header.cxx <> as header_cxx + rectangle main.cxx <> as main + rectangle CMakeLists.txt <> as begin + rectangle CMakeLists.txt <> as src_list + rectangle CMakeLists.txt <> as lib_list + 'rectangle main_cxx.o <> as o_file + + note right of begin + add_subdirectory(lib) + add_subdirectory(src) + endnote + note top of lib_list + add_library( + lib_113 STATIC + ${LIB_DIR}/header.cxx + ) + endnote + note right of src_list + add_executable( + main_113 + main.cxx + ) + target_include_directories( + main_113 + PRIVATE + ${LIB_DIR} + ) + target_link_libraries( + main_113 + lib_113 + ) + endnote +} + +begin *--> src_list +begin *--> lib_list +src_list -left-> main +'local_list .(0).> main +lib_list -left-> header_cxx +lib_list -left-> header_hxx + +title + What is This Process's Structure of Project "basic_113"? +end title + +header +Tips: version 1.0 +endheader + +center footer Develop C/C++ Application with the 'CMake' + +@enduml \ No newline at end of file diff --git a/format-codes.rb b/format-codes.rb new file mode 100644 index 0000000..495d675 --- /dev/null +++ b/format-codes.rb @@ -0,0 +1,13 @@ +# +# The File format-codes.rb +# ruby format-codes.rb +#EXTENSIONS = %w[cxx cpp hpp cu c h] +EXTENSIONS = %w[cxx hxx] +EXTENSIONS.each do |ext| + puts "ext = #{ext}" + `clang-format -style=file -i $(find . -name "*.#{ext}")` +end + +`cmake-format -c .cmake-format.yml -i $(find . -name "CMakeLists.txt")` +`cmake-format -c .cmake-format.yml -i $(find . -name "*.cmake")` +# \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..64528f2 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,11 @@ +# +add_library( + lib_113 STATIC + ${LIB_DIR}/header.cxx +) +#target_include_directories( +# lib_113 +# PRIVATE +# ${LIB_DIR} +#) +# diff --git a/lib/header.cxx b/lib/header.cxx new file mode 100644 index 0000000..81e253d --- /dev/null +++ b/lib/header.cxx @@ -0,0 +1,7 @@ +#include "header.hxx" + +#include + +void Header::hello(const char* name) { + std::cout << "Hello, Static Library from " << name << "!" << std::endl; +} diff --git a/lib/header.hxx b/lib/header.hxx new file mode 100644 index 0000000..55db0b4 --- /dev/null +++ b/lib/header.hxx @@ -0,0 +1,15 @@ +#ifndef HEADER_H +#define HEADER_H +#include + +// 24*60*60 = 86400 +#define SECONDS_IN_DAY 86400 + +// 24*60*60*1000 = 86400000 +const unsigned int MILISECONDS_IN_DAY = 86400000; + +struct Header { + void hello(const char*); +}; + +#endif \ No newline at end of file diff --git a/shell/cl.sh b/shell/cl.sh new file mode 100755 index 0000000..d966925 --- /dev/null +++ b/shell/cl.sh @@ -0,0 +1,14 @@ +#!/bin/bash +#[1/4]: Compile +c++ -I./lib -MD -MF ./bin/main.cxx.o.d -c ./src/main.cxx \ + -o ./bin/main.cxx.o +#[2/4]: Compile +c++ -I./lib -MD -MF ./bin/header.cxx.o.d -c ./lib/header.cxx \ + -o ./bin/header.cxx.o +#[3/4]: Package +cmake -E rm -f ./bin/liblib_113.a && \ + ar qc ./bin/liblib_113.a ./bin/header.cxx.o && \ + ranlib ./bin/liblib_113.a && cmake -E touch ./bin/liblib_113.a +#[4/4] : Link +c++ ./bin/main.cxx.o -o ./bin/main_113 ./bin/liblib_113.a +# \ No newline at end of file diff --git a/shell/start.sh b/shell/start.sh new file mode 100755 index 0000000..12fecf9 --- /dev/null +++ b/shell/start.sh @@ -0,0 +1,7 @@ +#!/bin/bash +rm -rf ./build ./bin/* +read -p "Press [Enter] key to start build..." +echo +./shell/cl.sh +./bin/main_113 +# \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..26bb869 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +# +add_executable( + main_113 + main.cxx +) +target_include_directories( + main_113 + PRIVATE ${LIB_DIR}/ +) +target_link_libraries(main_113 lib_113) +# diff --git a/src/main.cxx b/src/main.cxx new file mode 100644 index 0000000..afe8635 --- /dev/null +++ b/src/main.cxx @@ -0,0 +1,13 @@ +#include + +#include "header.hxx" + +int main(int, char**) { + Header header; + header.hello("main"); + + std::cout << "SECONDS_IN_DAY:\t\t" << SECONDS_IN_DAY << std::endl; + std::cout << "MILISECONDS_IN_DAY:\t" << MILISECONDS_IN_DAY << std::endl; + + return 0; +}