Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SofijaErkin/0c3e104b76fc874eb40579bb2527ed4f to your computer and use it in GitHub Desktop.
Save SofijaErkin/0c3e104b76fc874eb40579bb2527ed4f to your computer and use it in GitHub Desktop.
A best way to Setup C++11 debugger with Visual Studio Code on mac

A best setup C++11 debugger with VSCode (mac)

(ONLY FOR ONE SINGLE C/C++ FILE)

This is a set of files about setting up C++11 debugger with Visual Studio Code

on mac.

Notice:

This is my workspace environment!

Clang: 9.0.0;

Llvm-gcc: 4.2.1;

Visual Studio Code v1.63.2;

Code Runner v0.11.6 (Author: Jun Han);

CodeLLDB v1.4.5 or v1.5.0 (Author: Vadim Chugunov).

Now:

This workspace named HelloWorld, including a directories .vscode and 5 files.

The Architecture of workspace HelloWorld are:

HelloWorld

|

|_.vscode

|     |__c_cpp_properties.json

|     |__launch.json

|     |__settings.json

|     |__tasks.json

|__helloworld.cpp

helloworld.cpp: This workspace main function.

.vscode: VSCode configuration folder.

tasks.json: This task will invoke the Clang C++ compiler to create an

executable file from the source code.

settings.json: Workspace Settings.

launch.json: configure VS Code to launch the LLDB debugger when you press

F5 to debug the program.

c_cpp_properties.json: allows you to change settings such as the path to

the compiler, include paths.

Notices:

You only need to modify the Include path setting if your program includes

header files that are not in your workspace or the standard library path.

Especially: "includePath": [ "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include"].

If your seprated Command-line tools's Clang version is 9.0.0, copy this program

directly.

If not, just use this command to checkout the Clang version of your seprated

Command-line tools:

cd /Library/Developer/CommandLineTools/usr/lib/clang/ && ls

That may show like this: 9.0.0 or 9.1.0 or 10.0.0 or X.X.X. As this may show,

The Clang version of your seprated Command-line tools is 9.0.0, or 9.0.1 or

10.0.0 or X.X.X. And just replace my 9.0.0.

If you do not have a seprated Command-line tools, just install a seprated command

line tools for your Mac depencing your macOS System.

I will add the 5 file via adding file.

END.

{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Library/Developer/CommandLineTools/usr/include",
"/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include",
"/usr/local/include",
"/Library/Developer/CommandLineTools/usr/include/c++/v1",
"/usr/include"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
# Popular open source projects using CMake
# It is always a good practice to read open source projects, which are widely
# used to learn about the best practices.
# OpenCV: https://github.com/opencv/opencv
# Caffe2: https://github.com/caffe2/caffe2
# MySql Server: https://github.com/mysql/mysql-server
# Reference:
# https://medium.com/@onur.dundar1/cmake-tutorial-585dd180109b
# Notices: "may see" means "reference".
# 1.CMake Version
# Version Update RoadMap may see:
# GitHub Gist:
# https://gist.github.com/SofijaErkin/0c3e104b76fc874eb40579bb2527ed4f
# Upper, lower, and mixed case commands are supported by CMake.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/A%20Basic%20Starting%20Point.html#step-1-a-basic-starting-point
# cmake_minimum_required(VERSION 2.8)
# Specifies the minimum required version of CMake.
#
# may see:
# https://hsf-training.github.io/hsf-training-cmake-webpage/03-cmakelists/index.html
# The cmake_minimum_required command sets the policies so that the build is
# exactly like it would be on the listed version of CMake, in other words, CMake
# “dumbs itself down” to the version you request for any features that could
# produce a different build. This makes CMake almost perfectly backwards
# compatible.
#
# OR,
# Adding Generator Expressions a-g-e-n-2--CMakeLists.txt.------------------------
# cmake_minimum_required(VERSION 3.15)
# Update the call to require that more recent version.
# Adding Generator Expressions a-g-e-n-2--CMakeLists.txt.------------------------
cmake_minimum_required(VERSION 2.8.9...3.22)
message("CMake Minimum Required Version: ${VERSION}")
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# major version 2, minor version 8, and patch version 9. Providing a version
# number allows for future support for your build environment.
# may see:
# https://github.com/hsf-training/hsf-training-cmake-webpage/blob/gh-pages/_includes/code/00-intro/CMakeLists.txt
# This is required in all CMakeLists Selecting a nice minimum version and range
# may see:
# https://hsf-training.github.io/hsf-training-cmake-webpage/03-cmakelists/index.html
# Specify a range of versions, this will cause the policies to be set to the
# highest supported value in that range. As a general rule, set the highest
# version you’ve tested with here.
# Note: "the highest version" means your the version of cmake on your laptop,
# as I see.
# 2.Project Name And Version
# project(theFitBody)
# project(theFitBody VERSION 1.0)
# Defines the project name and the version according to what we provied during
# project creation.
# Project version step p-v-5-1-CMakeLists.txt.
#
# may see:
# https://hsf-training.github.io/hsf-training-cmake-webpage/03-cmakelists/index.html
# You need to be working on a project, and it needs at least a name. CMake
# assumes a CXX (that’s C++) and C mixed project if you don’t give any
# LANGUAGES.
#
project(theFitBody
VERSION
1.0
DESCRIPTION
"A project to test CMake build"
LANGUAGES
CXX
)
# message("theFitBody Project Version: ${VERSION}; Description: ${DESCRIPTION}; Language: ${LANGUAGES}")
# may see:
# https://github.com/hsf-training/hsf-training-cmake-webpage/blob/gh-pages/_includes/code/00-intro/CMakeLists.txt
# # We can call the project anything we want Listing the language(s) avoids the C
# + CXX default.
# may see:
# https://hsf-training.github.io/hsf-training-cmake-webpage/03-cmakelists/index.html
# Projects can have versions, descriptions, and languages.
# Whitespace doesn’t matter. Be clear/pretty, or use cmake-format.
# Selecting static or shared Librarires s-s-o-s-l-n-1-CMakeLists.txt.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#step-9-selecting-static-or-shared-libraries
# Shows the BUILD_SHARED_LIBS variable be used to control the default behavior
# of add_library(), and allow control over how libraries without an explicit
# type (STATIC, SHARED, MODULE or OBJECT) are built.
#
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# Notice: this three command need to be changed for mac!
# Control where the static and shared libraries are built so that on windows,
# we don't need to tinker with the path to run the executable.
#
# option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
# Uses the option() command as it allows users to optionally select if the
# value should be ON or OFF.
# Selecting static or shared Librarires s-s-o-s-l-n-1-CMakeLists.txt.
# option(USE_TEST "Use theFitBody provided dynamic library implementation" ON)
# Makes the Dynamic/Static Library optional. Large projects this s a common
# occurrence.
# Optional Library step o-7-1-CMakeLists.txt.
configure_file(thefitbodyConfig.h.in thefitbodyConfig.h)
# Configure a header file to pass the version number to the source code.
# Project version step p-v-5-2-CMakeLists.txt.
# 3.CMake CXX Standard
set(CMAKE_CXX_STANDARD 11)
# message("CMake C++ Standard: C++ ${CMAKE_CXX_STANDARD}")
# Sets the CMAKE_CXX_STANDARD variable to the value of 11, as we selected
# when creating the project.
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Specify he C++ standard
# Adds CMAKE_CXX_STANDARD declarations above the call to add_executable.
# OR,
# Adding Generator Expressions a-g-e-n-1-CMakeLists.txt------------------------
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Generator%20Expressions.html#step-10-adding-generator-expressions
# Insteading of using CMAKE_CXX_STANDARD,
# Just constructe an INTERFACE target and specifying the required C++ standard
# level of 11:
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Generator%20Expressions.html#cmakelists-txt-cxx-std-feature
# add_library(theFitBody_compiler_flags INTERFACE)
# target_compile_features(theFitBody_compiler_flags INTERFACE cxx_std_11)
# This upcoming section constructing an INTERFACE target and specifying the required C++ standard
# level of 11 will require a change to the cmake_minimum_required() usage in the code.
# The Generator Expression that is about to be used was introduced in 3.15.
# Adding Generator Expressions a-g-e-n-1-CMakeLists.txt------------------------
message(${CMAKE_BINARY_DIR})
# 4.Bring Includes
# include_directories(inc)
# include_directories(${CMAKE_CURRENT_LIST_DIR}/inc)
# Adds the headers either to all the targets or to some specificones.
#
# The include_directories() function is used to bring the header files into the
# build environment.
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# 5.Manually Sources
set(SOURCE_FILES thefitbody.cpp)
# message("Source files: ${SOURCE_FILES}")
# As an alternate, you can create a variable named ${SOURCES} as a list to
# include target sources. It can be done in a lot of different ways, depending
# on your methodology.
# Add thefitbody.cpp file of project root directory as source file.
# Can manually add the source file using the set command as follows:
# (Add source files of project root directory as source file)
#
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# The set(SOURCES … ) function can be used to set a variable (e.g: SOURCES or
# SOURCE_FILES) that contains the name values of all of the source files (.cpp
# or .cc or .c) in the project. However, because each source file must be added
# manually the next line is used in its place(file(GLOB)), and this line is
# commented out.
#
# aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/src sources_path)
#
# aux_source_directory(src SOURCES)
# Add all the file in directory.
#
# file(GLOB SOURCES "src/*.cc")
# However, the file(GLOB...) allows for wildcard additions.
#
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# The file() command is used to add the source files to the project. GLOB (or
# GLOB_RECURSE) is used to create a list of all of the files that meet the
# globbing expression (i.e., “src/*.cpp“ or "src/.cc" or "src/.c" or "common/
# .cc") and add them to a variable SOURCES or SOURCE_FILES.
# Optional Library step o-7-2-CMakeLists.txt.
# if(USE_TEST)
# add_subdirectory(test)
# list(APPEND EXTRA_LIBS test)
# list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/test") # OR the below
# # Delete the line "list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/test")"
# # if use INTERFACE in ~/test/CMakeLists.txt.
# # INTERFACE usage i-u-3-1-CMakeLists.txt/./test/CMakeLists.txt.
# endif(~USE_TEST)
# add_subdirectory(~test)
# ...
# Optional Library step o-7-2-CMakeLists.txt.
# include_directories(inc/github)
# Add additional headers located n separate directories.
target_include_directories(theFitBody PUBLIC "${PROJECT_BINARY_DIR}")
# Adds that directory to the list of paths to search for include files.
# Project version step p-v-5-3-thefitbody.cpp.
#
# include_directories will include library headers,
#
# 6.Add Executable
add_executable(theFitBody ${SOURCE_FILES})
#
# add_exectable(Bank ${SOURCES})
#
# # add_executable(${PROJECT_NAME} ${source_path})
#
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# The add_executable() function uses the SOURCES or SOURCE_FILES variable,
# rather than an explicit reference to each source file, in order to build the
# theFitBody executable program.
# The first argument to the add_executable() function is the name of the
# executable to be built, and the second argument is the source file from which
# to build the executable.
# We need an executable target.
# may see:
# https://github.com/hsf-training/hsf-training-cmake-webpage/blob/gh-pages/_includes/code/00-intro/CMakeLists.txt
# Adds theFitBody excutable target which will be build from "${SOURCE_FILES}".
# Packaging Debug and Release p-d-a-r-n-2-~/theFitBody/test/CMakeLists.txt.
# set_target_properties(theFitBody PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
# Packaging Debug and Release p-d-a-r-n-2-~/theFitBody/test/CMakeLists.txt.
#
# may see:
# https://hsf-training.github.io/hsf-training-cmake-webpage/03-cmakelists/index.html
# You need at least one library or executable to do anything interesting.
# The “thing” you make here is called a “target”, and the executable/library has
# the same name, by default, and it has to be unique in the project. You use
# add_executable for programs, and add_library for libraries.
# 7.Compiler
set(CMAKE_CXX_COMPILER "g++")
# the default editor
# message("C++ Compiler: ${CMAKE_CXX_COMPILER}")
# 8.Debugr
set(CMAKE_BUILD_TYPE "Debug")
# message("Build Type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
# message("Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}")
set(CAMKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
# Open the message of debug
# OR,
# Packaging Debug and Release p-d-a-r-n-1-CMakeLists.txt.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Packaging%20Debug%20and%20Release.html#step-12-packaging-debug-and-release
# set(CMAKE_DEBUG_POSTFIX d)
# add_library(theFitBody_compiler_flags INTERFACE)
# Uses d as the postfix for the debug executable and libraries.
# Packaging Debug and Release p-d-a-r-n-1-CMakeLists.txt.
# Check Build System Environment
# UNIX, WIN32, WINRT, CYGWIN, APPLE are environment variables as flags set by default system
if(UNIX)
message("This is a ${CMAKE_SYSTEM_NAME} system")
elseif(WIN32)
message("This is a Windows System")
endif()# or use MATCHES to see if actual system name
# Darwin is Apple's system name
# if(${CMAKE_SYSTEM_NAME} MATCHES Darwin)
# message("This is a ${CMAKE_SYSTEM_NAME} system")
# elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows)
# message("This is a Windows System")
#endif()
# or use MATCHES to see if actual system name
# Darwin is Apple's system name
# if(${CMAKE_SYSTEM_NAME} MATCHES Darwin)
# add_definitions(-DCMAKEMACROSAMPLE="Apple MacOS")
#elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows)
# add_definitions(-DCMAKEMACROSAMPLE="Windows PC")
#endif()
#
# Build Project's C/C++ compiler and tools (linker etc.)
# Cross Compiling for Linux
# may see:
# https://cmake.org/cmake/help/v3.22/manual/cmake-toolchains.7.html#cross-compiling-for-linux
# eg:
#set(CMAKE_SYSTEM_NAME Linux)
#set(CMAKE_SYSTEM_PROCESSOR arm)
#set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
#set(CMAKE_STAGING_PREFIX /home/devel/stage)set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)
#set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
#set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
#
# 9.C++11 Support
# Compiler/Linker Flags with CMake
# may see user manuals:
# https://gcc.gnu.org/onlinedocs/gcc-2.95.2/gcc_2.html
# https://clang.llvm.org/docs/ClangCommandLineReference.html
# Setting Compiler Flags
set(CMAKE_CXX_FLAGS "-std=c++0x -stdlib=libc++ -g3 -Wall -O0")
# message("C++ Flags: ${CMAKE_CXX_FLAGS}")
#
# That make clang++ support C++11
# Append flag, best practice, suggested, don't lose previously defined flags
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# eg:
# Suggested way is to keep previous flags in mind and append new ones
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
# Alternatively, you can use generator expressions, which are conditional
# expressions. Below says that, if compiper is c++ then set it to c++11
# add_compile_options("$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:-std=c++11>")
# Please see manual:
# https://clang.llvm.org/docs/ClangCommandLineReference.html#optimization-level
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
#
# -O0, -O1, -O2, -O3, -Os, -Oz, -Ofast
# Warning flags, See manual and tree:
# https://gist.github.com/d0k/3608547
# https://clang.llvm.org/docs/DiagnosticsReference.html
#
# Set Source File Properties
# Change one target’s certain behavior, build main.cpp with C++11 and if you
# building only library, you may want to build it with C++14.
# set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/*.cpp PROPERTIES COMPILE_FLAGS "-std=c++11")
# A large set of properties manual:
# https://cmake.org/cmake/help/v3.22/manual/cmake-properties.7.html#source-file-properties
#
# Linker Flags
# GNU GCC Linker may see:
# https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
# Search the directories defined in environment variables /usr/lib;
# /usr/local/lib , then links standard libraries by default.
# Most common flag is -l to link desired library like, -lzlib, -lboost etc.
# The variables which you can add linker flags:
# CMAKE_EXE_LINKER_FLAGS: Flags used to by linker during creation of executable
# CMAKE_EXE_LINKER_FLAGS_RELEASE: Flags used to by linker during creation of release executable
# CMAKE_EXE_LINKER_FLAGS_DEBUG: Flags used to by linker during creation of debug executable
# CMAKE_STATIC_LINKER_FLAGS: Flags used by linker during the creation of static libraries (.a, .lib)
# CMAKE_SHARED_LINKER_FLAGS: Flags used by linker during the creation of shared libraries (.so, .dylib, .dll)
# CMAKE_MODULE_LINKER_FLAGS: Flags used by linker during the creation of module libraries
# e.g:
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl")
#
# OR, 7. 8. 9.
# Adding Generator Expressions a-g-e-n-3--CMakeLists.txt.------------------------
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Generator%20Expressions.html#cmakelists-txt-target-compile-options-genex
# set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
# set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
# Uses the COMPILE_LANG_AND_ID generator expression to control which flags to
# apply given a language and a set of compiler ids as seen upstairs.
# target_compile_options(theFitBody_compiler_flags INTERFACE
# "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>"
# "$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>"
# )
# Adds the desired compiler warning flags that we want for our project.
# The warning flags are encapsulated inside a BUILD_INTERFACE condition.
# This is done so that consumers of our installed project will not inherit our
# warning flags.
# Adding Generator Expressions a-g-e-n-3--CMakeLists.txt.------------------------
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
# To generate binary file inside bin folder with setting
# CMAKE_RUNTIME_OUTPUT_DIRECTORY or EXECUTABLE_OUTPUT_PATH.
# Same procedure can be done for library paths as well for shared libraries
# (.dll or .so) with following variables.
# LIBRARY_OUTPUT_PATH Or CMAKE_LIBRARY_OUTPUT_DIRECTORY
# Use archive output paths for static libraries (.a or .lib)
# CMAKE_ARCHIVE_OUTPUT_DIRECTORY Or ARCHIVE_OUTPUT_PATH
# Disable in-source building
# Disable in-source builds to prevent source tree corruption.
# if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
# message(FATAL_ERROR "
#FATAL: In-source builds are not allowed.
# You should create a separate directory for build files.
#")
#endif()
# 10.Target Linked Library
# main source function file, No inlcude, as it is not relevant to a library
# build.
#
# Build s shared library (Linux: .so / Mac OS X: .dylib / Windows: .dll)-------
# BIG Notice:
# HelloWorld
# |
# |_.vscode
# | |__c_cpp_properties.json
# | |__launch.json
# | |__settings.json
# | |__tasks.json
# |__CMakeLists.txt
# |__build
# |__inc
# | |__helloworld.h
# |__src
# |__helloworld.cpp
#
#
# set(CMAKE_BUILD_TYPE Release)
# The set(CMAKE_BUILD_TYPE Release) function is used to set the build type to
# be a release build.
# include_directories(inc)
#
# add_library(testStudent SHARED ${SOURCES})
# Generate the shared library from the sources.
# The library is built as a shared library using the SHARED flag (other options
# are: STATIC or MODULE) , and the testStudent name is used as the name of the
# shared library.
#
# install(TARGETS testStudent DESTINATION /usr/lib)
# Set the location for library installation -- i.e., /usr/lib in this case
# not really necessary in this example. Use "sudo make install" to apply.
# The install() function to define an installation location for the library
# (in this case it is /usr/lib). Deployment is invoked using a call to
# sudo make install in this case.
# The library is built in the build directory, which results in the output.
# Use the ldd command to display the shared library dependencies.
# The CMakeLists.txt file(for shared library) also includes a deployment step,
# which allows you to install the library in a suitable accessible location.
# Shared library locations can be added to the path, or if you wish to make
# them available system wide you can add them to the /usr/lib directory.
# For example, the libtestStudent.so library can be installed system wide
# using:
# sudo make install
# ls -l /usr/lib|grep libtest*
# This step has to be performed with root access in order to write to the
# /usr/lib directory.
# You will also find a file in the build directory, called install_manifest.txt
# that describes the locations at which the make install command applied
# changes.
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# Build s shared library (Linux: .so / Mac OS X: .dylib / Windows: .dll)-------
#
#
#
#
# Build a static library (Linux: .a / Mac OS X: .a / Windows: .lib)------------
# may see;
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# A statically-linked library is created at compile time to contain all of the
# code relating the library — essentially it makes copies of any dependency
# code,including that in other libraries.
# This results in a library that is typically larger in size than the
# equivalent shared library, but because all of the dependencies are determined
# at compile time, there are fewer run-time loading costs and the library may
# be more platform independent.
# Unless you are certain that you require a static library, you should use a
# shared library as there will be fewer code duplications and the shared library
# can be updated (e.g., for error correction) without recompilation.
#
# To build a static library using CMake, the steps are almost exactly the same
# as for building a shared library.
#
# set(CMAKE_BUILD_TYPE Release)
#
# include_directories(inc)
# Bring the headers, such as Student.h into the project.
#
# file(GLOB SOURCES "src/*.cpp")
# However, the file(GLOB...) allows for wildcard additions.
#
# add_library(testStudent STATIC ${SOURCES})
# OR,
# add_library(test_library STATIC cal.cpp)
# Generate the static library from the sources.
# Adds library target. e.g: create a static library "test_library: from cal.cpp
# source file.
# Library target "test_library" build from libtest_library.a file under the
# cmake-build-debug folder.
#
# install(TARGETS testStudent DESTINATION /usr/lib)
# Set the location for library installation -- i.e., /usr/lib in this case.
# not really necessary in this example. Use "sudo make install" to apply
# Use the same steps as before to build the static library, and you will see
# the output as follows:
# cd build/
# cmake ..
# make
# ls -l lib*
# You can determine the constituents of a static library using the GNU ar
# (archive) command — for example:
# ar -t libtestStudent.a
# You can also use the GNU nm command to list the symbols in object files and
# binaries. In this case, the command lists the symbols in the student library
# and their types (e.g., T is code, U is undefined, R is read-only data).
# This information can be very useful for debugging any problems that may occur
# with static libraries.
# ~/studentlib_static/build$ nm -C libtestStudent.a
# may see:
# https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#lib-targets
#
# Build a static library (Linux: .a / Mac OS X: .a / Windows: .lib)------------
# Link Shared or Static Library
# CMake can be used to generate the Makefiles in your project in order to
# simplify this process.
# This step provides the source code for a CMakeLists.txt file that can be
# used to build a program that links to a library (either shared or static).
#
# For the shared library:
# set ( PROJECT_LINK_LIBS libtestStudent.so )
# link_directories( ~/exploringBB/extras/cmake/studentlib_shared/build )
# For the static library:
# set ( PROJECT_LINK_LIBS libtestStudent.a )
# link_directories( ~/exploringBB/extras/cmake/studentlib_static/build )
#
# include_directories(~/exploringBB/extras/cmake/studentlib_shared/include)
#
# add_executable(libtest libtest.cpp)
# target_link_libraries(libtest ${PROJECT_LINK_LIBS} )
# target_link_libraries will link boost library.
# The project can be built and executed using the following steps:
# tree
# cd build
# cmake ..
# make
# ls -l libtest
# ./libtest
#
# OR,
#
# find_library(TEST_LIBRARY test_library lib)
# Provides the full path, or Create a lib directory under the project root
# and copy libtest_library.a from its default location (cmake-build-debug) to
# this folder.
# target_link_libraries(theFitBody LINK_PUBLIC ${TEST_LIBRARY})
# Pass directly via ${TEST_LIBRARY} variable.
# target_link_libraries(theFitBody PUBLIC ${EXTRA_LIBS})
# Optional Library step o-7-3-CMakeLists.txt.
# Make sure o place target_link_libraries after the add_execuable command.
#
#
# Link Dynamic Library
# To avoid the root CMakeLists.txt too difficult to maintian as our project
# gets more complicated, and to build a transparent project structure,
# extract the dynamic tests into a subproject
# Transparent project structure just like this:
# theFitBody
# |
# | __.vscode
# | |
# | |__c_cpp_properties.json
# | |__launch.json
# | |__settings.json
# | |__tasks.json
# |
# | __CMakeLists.txt
# |
# | __test
# | |
# | |__CMakeLists.txt
# | |__test.cpp
# | |__test.h
# |
# |__thefitbody.cpp
#
# Just use Boost.Test framework for example.
# Inserted this code to CMakeLists.txt under ./theFitBody/test:
# # CMakeLists.txt under ./theFitBody/test ------------------------------------
#
# # Packaging Debug and Release p-d-a-r-n-3-MultiCPackConfig.cmake.
# #
# # may see: https://medium.com/@onur.dundar1/cmake-tutorial-585dd180109b
# # If you intend to deliver binaries, you should make a Release, which doesn't
# # include debug flags in binary, which would be a way faster and ready to run.
# # However, debug version of executable files include many of other flags which
# # exposes the memory, method names etc for debuggers to help identify the
# # errors.
# # It is not a good practice and not safe to deliver debug version of an
# # application.
# #
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Packaging%20Debug%20and%20Release.html#mathfunctions-cmakelists-txt-version-properties
# set_property(TARGET test PROPERTY VERSION "1.0.0")
# set_property(TARGET test PROPERTY SOVERSION "1")
# # Sets the VERSION and SOVERSION properties, in test/CMakeLists.txt.
# # Adds version numbering to the test library.
#
# mkdir debug release
# Create debug and release subbdirectories.
# cd debug
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# Notice: CMake Error at CMakeLists.txt:18 (project):
# VERSION not allowed unless CMP0048 is set to NEW
# cmake --build .
# cd ../release
# cmake -DCMAKE_BUILD_TYPE=Release ..
# Notice: CMake Error at CMakeLists.txt:18 (project):
# VERSION not allowed unless CMP0048 is set to NEW
# cmake --build .
# Setup debug and release builds, use CMAKE_BUILD_TYPE to set the
# configuration type.
#
# OR,
# may see: https://medium.com/@onur.dundar1/cmake-tutorial-585dd180109b
# cmake -H. -Bbuild/Debug
# cmake -H. -Bbuild/Release
# Above configuration is not enough to create different binaries.
# Also set build type with CMAKE_BUILD_TYPE variable on the command line.
# (CLion handles this process by itself.)
# $ cmake -DCMAKE_BUILD_TYPE=Debug -H. -Bbuild/Debug
# $ cmake -DCMAKE_BUILD_TYPE=Release -H. -Bbuild/Release
# CMAKE_BUILD_TYPE is accessible inside CMakeLists.txt. You can easily check
# for build type in CMakeLists.txt:
# if(${CMAKE_BUILD_TYPE} MATCHES Debug)
# message("Debug Build")
# elseif(${CMAKE_BUILD_TYPE} MATCHES Release)
# message("Release Build")
# endif()
# Can also, set compiler and linker flags separately for build types using the
# config variables shown in the previous section.
# e.g:
# CMAKE_EXE_LINKER_FLAGS_RELEASE: Flags used to by linker during creation of release executable
# CMAKE_EXE_LINKER_FLAGS_DEBUG: Flags used to by linker during creation of debug executable
# CMAKE_CXX_FLAGS_RELEASE
# CMAKE_CXX_FLAGS_DEBUG
#
# # Packaging Debug and Release p-d-a-r-n-3-MultiCPackConfig.cmake.
#
# add_library(test test.cpp)
# # The test.cpp provides similar functionality to the compiler's dynamic func.
# # Dynamic Library Link step d-4-1-CMakeLists.txt.
# # Selecting static or shared Librarires s-s-o-s-l-n-4-~/test/CMakeLists.txt.
# # OR the below |>
# set(Boost_USE_STATIC_LIBS OFF)
# #enable dynamic linking
# find_package(Boost REQUIRED COMPONENTS unit_test_framework)
# # search for unit_test_framework
#
# include_directories(${Boost_INCLUDE_DIR})
#
# add_executable(cmake_testapp_boost tests.cpp)
# # create a cmake_testapp_boost target from test.cpp
#
# target_include_directories(test
# INTERFACE
# ${CMAKE_CURRENT_SOURCE_DIR}
# )
# # Use test Library as INTERFACE.
# # INTERFACE usage i-u-3-2-CMakeLists.txt/./test/CMakeLists.txt.
# # Selecting static or shared Librarires s-s-o-s-l-n-5-~/test/CMakeLists.txt.
#
# # OR,
# # Adding Export Configuration a-e-c-n-4-~/theFitBody/Config.cmake.in.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#mathfunctions-cmakelists-txt-target-include-directories
# target_include_directories(test
# INTERFACE
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
# $<INSTALL_INTERFACE:include>
# )
# # Updates the test target_include_directories() to understand that it needs
# # different INTERFACE locations when being used from within the build
# # directory and from an install / package.
# # Adding Export Configuration a-e-c-n-4-~/theFitBody/Config.cmake.in.
#
# # Selecting static or shared Librarires s-s-o-s-l-n-6-~/test/CMakeLists.txt.
# # may see:
# #https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-cmakelists-txt-add-library-static
# option(USE_TEST "Use theFitBody provided testLIB implementation" ON)
# # # Should we use our own testLIB functions.
# # Selecting static or shared Librarires s-s-o-s-l-n-6-~/test/CMakeLists.txt.
#
# # Adds system inrospecion s-i-n-1--CMakeLists.txt.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20System%20Introspection.html#step-5-adding-system-introspection
# #
# include(CheckSymbolExists)
# check_symbol_exists(log "test.h" HAVE_LOG)
# check_symbol_exists(exp "test.h" HAVE_EXP)
# if(NOT (HAVE_LOG AND HAVE_EXP))
# unset(HAVE_LOG CACHE)
# unset(HAVE_EXP CACHE)
# set(CMAKE_REQUIRED_LIBRARIES "t")
# check_symbol_exists(log "test.h" HAVE_LOG)
# check_symbol_exists(exp "test.h" HAVE_EXP)
# if(HAVE_LOG AND HAVE_EXP)
# target_link_libraries(test PRIVATE t)
# endif()
# endif()
# # Does this system provide the log and exp functions?
# # Or, has the target platform suppoet the log and exp functions.
#
# # OR
# include(CheckSymbolExists)
# check_symbol_exists(log "test.h" HAVE_LOG)
# check_symbol_exists(exp "test.h" HAVE_EXP)
# if(HAVE_LOG AND HAVE_EXP)
# target_compile_definitions(test
# PRIVATE "HAVE_LOG" "HAVE_EXP")
# endif()
#
# # Adds system inrospecion s-i-n-1--CMakeLists.txt.
#
# # Adds system inrospecion s-i-n-2--CMakeLists.txt.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20System%20Introspection.html#mathfunctions-mysqrt-cxx-ifdef
# # Adds #if-#endif on ~/test/test.cpp
# #if defined(HAVE_LOG) && defined(HAVE_EXP)
# type_expression_ variable_tar_ = expression(in-expression_variable_);
# std :: cout << "Computng sqrt of " << in-expression_variable_ << "to be"
# << variable_tar << "Using og and expc" << std :: endl;
# #else
# type_expression_ variable_tar_ = in-expression_variable_;
# #endif
# # Adds system inrospecion s-i-n-2--CMakeLists.txt.
#
# # Adds system inrospecion s-i-n-3-OVER.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20System%20Introspection.html#mathfunctions-mysqrt-cxx-include-cmath
# # Needs to add the test-Library to ~/test/test.cpp
# #include <test-Library>
# # Adds system inrospecion s-i-n-3-OVER.
#
#
# target_link_libraries(cmake_testapp_boost ${Boost_LIBRARIES})
# # link Boost libraries to the new target
#
# target_link_libraries(cmake_testapp_boost test_library)
#
# # link Boost with code library
# # the Upper <|
#
#
# # Installing and testing Library i-t-l-3-1-CMakeLists.txt.
#
# install(TARGETS test DESTINATION lib)
# # Installs the library and header of Dynamic test Library and for the
# # application we want to install the executable nd configured header.
# install(FILES test.h DESTINATION include)
# # This install command CMake add to the end of test/CMakeLists.txt.
#
# # Installing and testing Library i-t-l-3-1-CMakeLists.txt.
#
# # CMakeLists.txt under ./theFitBody/test ------------------------------------
# Not use paltform log and exp functions.
# Link Dynamic Library
# To avoid the root CMakeLists.txt too difficult to maintian as our project
# gets more complicated, and to build a transparent project structure,
# extract the dynamic tests into a subproject
# Transparent project structure just like this:
# theFitBody
# |
# | __.vscode
# | |
# | |__c_cpp_properties.json
# | |__launch.json
# | |__settings.json
# | |__tasks.json
# |
# | __CMakeLists.txt
# |
# | __test
# | |
# | |__CMakeLists.txt
# | |__MakeTable.cpp
# | |__test.cpp
# | |__test.h
# |
# |__thefitbody.cpp
#
# Just use Boost.Test framework for example.
# Inserted this code to CMakeLists.txt under ./theFitBody/test:
# # CMakeLists.txt under ./theFitBody/test ------------------------------------
#
# # Selecting static or shared Librarires s-s-o-s-l-n-7-~/test/CMakeLists.txt.
# if(USE_TEST)
# # Selecting static or shared Librarires s-s-o-s-l-n-7-~/test/CMakeLists.txt.
# # Adds a custom command and generate file a-c-c-g-f-n-1
# # Selecting static or shared Librarires s-s-o-s-l-n-8-~/test/CMakeLists.txt.
# add_executable(MakeTable MakeTable.cxx)
# # First we add the executable that generates the table.
# # At the top of ~/test/CMakeLists.txt, the executable for MakeTable is added
# # as any other executable would be added.
# # Selecting static or shared Librarires s-s-o-s-l-n-8-~/test/CMakeLists.txt.
# # Adds a custom command and generate file a-c-c-g-f-n-1
#
# # Adds a custom command and generate file a-c-c-g-f-n-2
# # Selecting static or shared Librarires s-s-o-s-l-n-9-~/test/CMakeLists.txt.
# add_custom_command(
# OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
# COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
# DEPENDS MakeTable
# )
# # Adds the command to generate the source code.
# # Adds a custom command that specifies how to produce Table.h by running
# # MakeTable.
# # Selecting static or shared Librarires s-s-o-s-l-n-9-~/test/CMakeLists.txt.
# # Adds a custom command and generate file a-c-c-g-f-n-2
#
# # Selecting static or shared Librarires s-s-o-s-l-n-10-~/test/CMakeLists.txt.
# add_library(testLibrary STATIC
# mytest.cxx
# ${CMAKE_CURRENT_BINARY_DIR}/Table.h
# )
# # Library that just does mytest.
# # Selecting static or shared Librarires s-s-o-s-l-n-10-~/test/CMakeLists.txt.
#
# # Adds a custom command and generate file a-c-c-g-f-n-3
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Custom%20Command%20and%20Generated%20File.html#mathfunctions-cmakelists-txt-add-library-table-h
# add_library(test
# mytest.cxx
# ${CMAKE_CURRENT_BINARY_DIR}/Table.h
# )
# # Lets CMake know that mytest.cxx depends on the generated file Table.h.
# # This is done by adding the generated Table.h to the list of sources for the
# # library MathFunctions.
# # Adds a custom command and generate file a-c-c-g-f-n-3
#
# # Selecting static or shared Librarires s-s-o-s-l-n-11-~/test/thefitbody.cpp.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-cmakelists-txt-add-library-static
# target_include_directories(testLibrary PRIVATE
# ${CMAKE_CURRENT_BINARY_DIR}
# )
# # States that we depend on our binary dir to find Table.h
# target_link_libraries(test PRIVATE testLibrary)
# endif()
#
# # Selecting static or shared Librarires s-s-o-s-l-n-14-OVER.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-cmakelists-txt-position-independent-code
# set_target_properties(testLibrary PROPERTIES
# POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
# )
# # States that testLibrary need PIC when the default is shared libraries
# # Selecting static or shared Librarires s-s-o-s-l-n-14-OVER.
#
# target_compile_definitions(test PRIVATE "EXPORTING_TEST")
# # Define the symbol stating we are using the declspec(dllexport) when
# # building on windows, macOS may change!
#
# set(installable_libs test)
# # OR,
# # Adding Export Configuration a-e-c-n-1-CMakeLists.txt
# set(installable_libs test theFitBody_compiler_flags)
# # Modify test/CMakeLists.txt so that all targets have a
# # target_link_libraries() call to theFitBody_compiler_flags.
# # Adding Export Configuration a-e-c-n-1-CMakeLists.txt
#
# if(TARGET testLibrary)
# list(APPEND installable_libs testLibrary)
# endif()
#
# install(TARGETS ${installable_libs} DESTINATION lib)
# # OR,
# # Adding Export Configuration a-e-c-n-2-CMakeLists.txt
# install(TARGETS ${installable_libs}
# EXPORT testTargets
# DESTINATION lib)
# # The EXPORT keyword generates a CMake file containing code to import all
# # targets listed in the install command from the installation tree.
# # Adding Export Configuration a-e-c-n-2-CMakeLists.txt
#
# install(FILES test.h DESTINATION include)
# # Install rules.
#
# # May change mytest.cpp.!
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-mysqrt-cxx-namespace
#
# # Selecting static or shared Librarires s-s-o-s-l-n-13-~/test/CMakeLists.txt.
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-mathfunctions-h
# test.h under ~/theFitBody/test/test.h ---------------------------------------
#if defined(_WIN32)
# if defined(EXPORTING_MYMATH)
# define DECLSPEC __declspec(dllexport)
# else
# define DECLSPEC __declspec(dllimport)
# endif
#else // non windows
# define DECLSPEC
#endif
# namespace test {
# double DECLSPEC mytest(double x);
# }
# #
# test.h under ~/theFitBody/test/test.h ---------------------------------------
# # Selecting static or shared Librarires s-s-o-s-l-n-13-~/test/CMakeLists.txt.
#
# add_library(test test.cpp)
# # The test.cpp provides similar functionality to the compiler's dynamic func.
# # Dynamic Library Link step d-4-1-CMakeLists.txt.
# # OR the below |>
# set(Boost_USE_STATIC_LIBS OFF)
# #enable dynamic linking
# find_package(Boost REQUIRED COMPONENTS unit_test_framework)
# # search for unit_test_framework
#
# include_directories(${Boost_INCLUDE_DIR})
#
# add_executable(cmake_testapp_boost tests.cpp)
# # create a cmake_testapp_boost target from test.cpp
#
# target_include_directories(test INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
# # Use test Library as INTERFACE.
# # INTERFACE usage i-u-3-2-CMakeLists.txt/./test/CMakeLists.txt.
#
#
# target_link_libraries(cmake_testapp_boost ${Boost_LIBRARIES})
# # link Boost libraries to the new target
#
# target_link_libraries(cmake_testapp_boost test_library)
#
# # link Boost with code library
# # the Upper <|
#
# # Adds a custom command and generate file a-c-c-g-f-n-4
# target_include_directories(test
# INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
# PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
# )
# # Adds the current binary directory to the list of include directories so
# # that Table.h can be found and included by test.cxx.
# # Adds a custom command and generate file a-c-c-g-f-n-4
#
# # Adds a custom command and generate file a-c-c-g-f-n-5
# # Adds header file ~/test/Table.h to ~/test/test.cpp
# #include "Table.h"
# # Adds a custom command and generate file a-c-c-g-f-n-5
#
# # Adds a custom command and generate file a-c-c-g-f-n-6
# # Rewrite ~/test/test.cpp
# # may see:
# # https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Custom%20Command%20and%20Generated%20File.html#mathfunctions-mysqrt-cxx
#
#
#
# # Installing and testing Library i-t-l-3-1-CMakeLists.txt.
#
# install(TARGETS test DESTINATION lib)
# # Installs the library and header of Dynamic test Library and for the
# # application we want to install the executable nd configured header.
# install(FILES test.h DESTINATION include)
# # This install command CMake add to the end of test/CMakeLists.txt.
#
# # Installing and testing Library i-t-l-3-1-CMakeLists.txt.
#
# # CMakeLists.txt under ./theFitBody/test ------------------------------------
# add_subdirectory(test)
# AddS the test library.
# Dynamic Library Link step d-4-2-CMakeLists.txt.
# Also,
# Selecting static or shared Librarires s-s-o-s-l-n-2-CMakeLists.txt.
# Make subproject test target cmake_testapp_boost available for the main build.
# Place he add_subdirectory(test) command in the rootCMakeLists.txt.
# target_link_libraries(theFitBody PUBLIC test)
# Link the dynamic library test
# Dynamic Library Link step d-4-3-CMakeLists.txt.
# Also,
# Selecting static or shared Librarires s-s-o-s-l-n-3-~/test/CMakeLists.txt.
# target_include_directories(theFitBody PUBLIC "${PROJECT_SOURCE_DIR}/test")
# Adds the binary tree to the search path or include files o that we will find
# test.h.
# Dynamic Library Link step d-4-4-OVER.
# target_include_directories(theFitBody PUBLIC "${EXTRA_INCLUDES}") # OR below
# if use test as INTERFACE.
# target_include_directories(theFitBody PUBLIC "${PROJECT_BINARY_DIR}")
# Optional Library step o-7-4-thefirbody.cpp.
# Installing and testing Library i-t-l-3-2-CMakeLists.txt.
#
# install(TARGETS theFitBody DESTINATION bin)
#
# install(FILES "${PROJECT_BINARY_DIR}/thefitbodyCOnfig.h" DESTINATION include)
#
# Installing and testing Library i-t-l-3-2-CMakeLists.txt.
# Adding Export Configuration a-e-c-n-3-~/theFitBody/test/CMakeLists.txt
# install(EXPORT testTargets
# FILE testTargets.cmake
# DESTINATION lib/cmake/test
# )
# Needs to explicitly install the generated testTargets.cmake file.
# Adding Export Configuration a-e-c-n-3-~/theFitBody/test/CMakeLists.txt
# Adding Export Configuration a-e-c-n-6-CMakeLists.txt.
# include(CMakePackageConfigHelpers)
# To properly configure and install that file, add the following to the bottom
# of the top-level CMakeLists.txt.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#cmakelists-txt-install-config-cmake
#
# configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
# "${CMAKE_CURRENT_BINARY_DIR}/testConfig.cmake"
# INSTALL_DESTINATION "lib/cmake/example"
# NO_SET_AND_CHECK_MACRO
# NO_CHECK_REQUIRED_COMPONENTS_MACRO
# )
# Generates the config file that is includes the exports
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#cmakelists-txt-configure-package-config-cmake
#
# write_basic_package_version_file(
# "${CMAKE_CURRENT_BINARY_DIR}/testConfigVersion.cmake"
# VERSION "${THEFITBODY_VERSION_MAJOR}.${THEFITBODY_VERSION_MINOR}"
# COMPATIBILITY AnyNewerVersion
# )
# Writes a file which is used by the "find_package" document the version and
# compatibility of the desired package. Use the THEFITBODY_VERSION_* variables
# and say that it is compatible with AnyNewerVersion, which denotes that this
# version or any higher one are compatible with the requested version.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#cmakelists-txt-basic-version-file-cmake
#
#
# install(FILES
# ${CMAKE_CURRENT_BINARY_DIR}/testConfig.cmake
# ${CMAKE_CURRENT_BINARY_DIR}/testConfigVersion.cmake
# DESTINATION lib/cmake/test
# )
# Sets both generated files to be installed.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#cmakelists-txt-install-configured-files-cmake
#
# Optional
#
# export(EXPORT test
# FILE "${CMAKE_CURRENT_BINARY_DIR}/testTargets.cmakDEBUGe"
# )
# If want project to also be used from a build directory we only have to add
# the following to the bottom of the top level CMakeLists.txt.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#cmakelists-txt-export
# With this export call now generate a Targets.cmake, allowing the configured
# testConfig.cmake in the build directory to be used by other projects, without
# needing it to be installed.
# Adding Export Configuration a-e-c-n-6-CMakeLists.txt.
# Testing theFitBody t-t-f-b-n-1-OVER.-----------------------------------------
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Installing%20and%20Testing.html#testing-support
# enable_testing()
#
# add_test(NAME Runs COMMAND theFitBody 25)
# Does simply verifes that the application theFitBody runs, does no segfault or
# otherwise ceash, and has a zero return value.
#
# add_test(NAME Usage COMMAND theFitBody)
# Does the usage message work?
# Does verify that the output of the test contains certain strings.
# set_tests_properties(Usage
# PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
# )
#
# function(do_test target arg result)
# add_test(NAME Comp${arg} COMMAND ${target} ${arg})
# set_tests_properties(Comp${arg}
# PROPERTIES PASS_REGULAR_EXPRESSION ${result}
# )
# endfunction()
# Define a function to simplify adding tests.
# do_test that runs the application and verifies that the computed square root
# is correct for given input.
#
# do_test(theFitBody 4 "4 is 2")
# do_test(theFitBody 9 "9 is 3")
# do_test(theFitBody 5 "5 is 2.236")
# do_test(theFitBody 7 "7 is 2.645")
# do_test(theFitBody 25 "25 is 5")
# do_test(theFitBody -25 "-25 is (-nan|nan|0)")
# do_test(theFitBody 0.0001 "0.0001 is 0.01")
# Do a bunch of result based tests
# Ddded to the project with a name, input, and expected results based on the
# passed arguments.
#
# Rebuild and cd the binary directory and run ctest executable:
# ctest -N
#
# and
#
# ctest -VV
#
# For multi-config generator, add the "-C <mode>" flag:
# e.g:
# Run tests in Debug mode use(from binary directory):
# ctest -C Debug -VV
# Run tests in Release mode:
# ctest -C Release -VV
#
# Others, IDE need to build RUN_TESTS target.
#
# Testing theFitBody t-t-f-b-n-1-OVER.-----------------------------------------
# Or Change "Testing theFitBody t-t-f-b-n-1-OVER." to Testing dashboard
#
# Testing dashboard theFitBody t-d-t-f-b-n-1-CTestConfig.cmake ----------------
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Support%20for%20a%20Testing%20Dashboard.html#step-8-adding-support-for-a-testing-dashboard
# include(CTest)
# Enable dashboard scripting.
# CTest module will automatically call enable_testing(), so we can remove it
# from our CMake files.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Support%20for%20a%20Testing%20Dashboard.html#cmakelists-txt-include-ctest
# Adds CTestConfig.cmake to the top directory of theFitBody Project.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Support%20for%20a%20Testing%20Dashboard.html#ctestconfig-cmake
# Testing dashboard theFitBody t-d-t-f-b-n-1-CTestConfig.cmake ----------------
# Testing dashboard theFitBody t-d-t-f-b-n-3-OVER ----------------
# To create a simple dashboard you can run the cmake executable or the
# cmake-gui to configure the project, but do not build it yet.
# Instead, change directory to the binary tree, and then run:
# ctest [-VV] -D Experimental
# Multi-config generators, the configuration type must be specified:
# ctest [-VV] -C Debug -D Experimental
# OR
# ctest [-VV] -C Release -D Experimental
# Notice: I need to create a project named "theFirBody"on CMakeTurorial, or
# That Testing dashboard does not work!
# If create a project "theFitBody" on CMakeTurorial, then The ctest executable
# will build and test the project and submit the results to Kitware's public
# dashboard:
# https://my.cdash.org/index.php?project=CMaketheFitBody
# Testing dashboard theFitBody t-d-t-f-b-n-3-OVER ----------------
# Packages an installer
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Packaging%20an%20Installer.html#step-7-packaging-an-installer
# include(InstallRequiredSystemLibraries)
# Includes InstallRequiredSystemLibraries,
# This module will include any runtime libraries that are needed by the project
# for the current platform.
# set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
# Sets some CPack variables to where we have stored the license and version
# information for this project.
# set(CPACK_PACKAGE_VERSION_MAJOR "${THEFITBODY_VERSION_MAJOR}")
# set(CPACK_PACKAGE_VERSION_MINOR "${THEFITBODY_VERSION_MINOR}")
# The version information was set earlier in this theFitBody and the
# license.txt has been included in the top-level source directory for this
# step.
# set(CPACK_SOURCE_GENERATOR "TGZ")
# The CPACK_SOURCE_GENERATOR variable selects a file format for the source
# package.
# include(CPack)
# CPack module which will use these variables and some other properties of
# the current system to setup an installer.
# Build the Packages an installer Project and run the cpack execuable, just
# use:
# cpack
# To specify the generator, use the -G option, e.g:
# cpack -G ZIP
# Multi-config builds, use "-C" to specify he configuration, just use:
# cpack -G ZIP -C Debug
#
# OR
#
# cpack -G ZIP -C Release
# To create an archive of the full source tree would just type:
# cpack --config CPackSourceConfig.cmake
# Others,
# Run the installer found in the binary directory.
# Then run the installed executable and verify that it works.
#
# OR, CMake Installation/Deployment Configurations
# may see: https://medium.com/@onur.dundar1/cmake-tutorial-585dd180109b
# Good coverage of the parameters of install command of CMake in:
# https://cmake.org/cmake/help/v3.0/command/install.html
# Main procedure in this process is to copy the files generated by build
# process to a destination folder on the host. Therefore:
# $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/test/with/cmake -H. -Bbuild/Release
# CMAKE_INSTALL_PREFIX is the variable to define host destination. it is set to
# /usr/local by default. During the build process, you should point the
# destination folder in command-line.
# Keeping in mind that, you are getting prefix destination from terminal you
# should think about library and executable destinations accordingly.
# CTest: a framework for compiling and running tests as part of the CMake build
# process.
# may see: https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#ctest
# Separated Multiple directories CMakeLists.txt
# As your project grows, it is likely that you will organize it into
# sub-directories. Makefiles become more verbose when there are sub-directories
# present —in fact, it is usual practice to place an individual Makefile in
# each sub-directory. These Makefiles are then individually invoked by the
# Makefile in the parent directory.
# But,
# CMake can be very useful in this situation.
# may see:
# https://cmake.org/examples/
# OR,
# may see:
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
# Update the optional variable USE_TEST
# cmake ../Step2 -DUSE_TEST=OFF
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Library.html#tutorialconfig-h-in-cmakedefine
# Installing and testing Library i-t-l-3-3-OVER.
# Install step, just use :
# make install
#
# OR
#
# cmake install
#
# multi-configuration add the "--config" argument to specific the configuration
#
# Separated install add the "--prefix" argument to follow the installed root,
# e.g:
# (This will navigate to the install directory nd verify that the installed
# theFitBody runs.)
# cmake install . --prefix "User/marryme/theFitBodyTest"
#
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Installing%20and%20Testing.html#install-rules
# CMake Best Practices
# may see:
# https://medium.com/@onur.dundar1/cmake-tutorial-585dd180109b
# Always remember the previous configurations, make sure you append new flag
# instead of overwriting it.
# It is better to implement, add_flag/remove method of yours, to achieve
# easier implementation.
# e.g:
# set(VARIABLE "${VARIABLE} Flag1 Flag2")
# Always check system information carefully, raise error if a certain
# configuration can’t be done to prevent faulty binaries.
# Always, check required libraries to continue build process, raise error if
# not found.
# References:
# CMakeLists.txt | CLion - JetBrains
# https://www.jetbrains.com/help/clion/cmakelists-txt-file.html
# Quick CMake tutorial | CLion - JetBrains
# https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html
# CMake Tutorial
# https://cmake.org/cmake/help/latest/guide/tutorial/index.html#cmake-tutorial
# More Modern CMake Your first CMakeLists.txt file
# https://hsf-training.github.io/hsf-training-cmake-webpage/03-cmakelists/index.html
# https://github.com/hsf-training/hsf-training-cmake-webpage/tree/gh-pages/_includes/code/00-intro
# Introduction to CMake by Example
# http://derekmolloy.ie/hello-world-introductions-to-cmake/
#
# The best, and most up-to-date documentation on CMake:
# https://cmake.org/
# The CMake Documentation Index provides a very useful list of available commands:
# The document is available at:CMake 3.22 Documentation Index
# https://cmake.org/cmake/help/v3.22/genindex.html
# CMake commands:
# https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html
# KDE has its own CMake style guideline
# https://community.kde.org/Policies/CMake_Coding_Style
# A detailed list of environment variables
# https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html
# CMake Generator Expressions
# https://cmake.org/cmake/help/v3.22/manual/cmake-generator-expressions.7.html
# CMake Variables
# https://cmake.org/cmake/help/v3.22/manual/cmake-language.7.html#variables
# https://cmake.org/cmake/help/v3.22/manual/cmake-variables.7.html#manual:cmake-variables(7)
# Following variables can be used to check for system related information
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks
# Following script can be used to block in-source building.
# Source of script OpenCV Project:
# https://github.com/opencv/opencv/blob/master/CMakeLists.txt
#
# Cross Compiling for Linux
# https://cmake.org/cmake/help/v3.22/manual/cmake-toolchains.7.html#cross-compiling-for-linux
# User manuals:
# https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Invoking-GCC.html#Invoking-GCC
# https://clang.llvm.org/docs/ClangCommandLineReference.html#clang-command-line-argument-reference
# Optimisation flags-Setting Compiler Flags
# https://clang.llvm.org/docs/ClangCommandLineReference.html#optimization-level
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# Warning flags
# https://gist.github.com/d0k/3608547
# https://clang.llvm.org/docs/DiagnosticsReference.html
# Set Source File Properties
# https://cmake.org/cmake/help/v3.22/manual/cmake-properties.7.html#source-file-properties
# Linker Flags
# https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
# Install command of CMake
# https://cmake.org/cmake/help/v3.22/command/install.html
#
# Other Resources
# GNU and LLVM Compiler Flags:
# https://www.bu.edu/tech/support/research/software-and-programming/programming/compilers/gcc-compiler-flags/
# FindBoost-cmake-modules
# https://cmake.org/cmake/help/v3.22/module/FindBoost.html
# CMake Wiki Examples
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/Examples
# Learning CMake A Beginner's Guide
# https://tuannguyen68.gitbooks.io/learning-cmake-a-beginner-s-guide/content/index.html
# How To Write Platform Checks
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks
// # # Adding Export Configuration a-e-c-n-5-~/theFitBody/CMakeLists.txt.
@PACKAGE_INIT@
include ( "${CMAKE_CURRENT_LIST_DIR}/testTargets.cmake" )
// may see:
// https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html#config-cmake-in
// # # Adding Export Configuration a-e-c-n-5-~/theFitBody/CMakeLists.txt.
# Testing dashboard theFitBody t-d-t-f-b-n-2-CMakeLists.txt -------------------
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Support%20for%20a%20Testing%20Dashboard.html#ctestconfig-cmake
set(CTEST_PROJECT_NAME "CMaketheFitBody")
# The project name
set(CTEST_NIGHTLY_START_TIME "00:00:00 UTC")
# The project "Nightly" start time
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=CMaketheFitBody")
# The URL of the CDash instance where the submission's generated documents will
# be sent.
set(CTEST_DROP_SITE_CDASH TRUE)
# Testing dashboard theFitBody t-d-t-f-b-n-2-CMakeLists.txt -------------------
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug With LLDB",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "Compile With clang++"
}
]
}
# Notices--------------------------------------------------
# This Seprated Multiple CXX Manully VScode(mac) Do Not USE Makefile.
# This Seprated Multiple CXX Manully VScode(mac) Do Not USE Makefile.
# This Seprated Multiple CXX Manully VScode(mac) Do Not USE Makefile.
# ---------------------------------------------------------
# Thanks, Job Vranish.
# (https://spin.atomicobject.com/2016/08/26/makefile-c-projects/)
# Reference: Makefile Tutorial
# (https://makefiletutorial.com/)
# Reference: @yagiyuki from Qiita
# (https://qiita.com/yagiyuki/items/ff343d381d9477e89f3b)
# Reference: simonsso from Github
# (https://github.com/simonsso/empty-cpp-project/blob/master/Makefile)
# (1)Compiler
CXX = clang++
# (2)Compile options
CXX_FLAGS = -Wall -Wextra -std=c++11 -g
# (3)Build task directory path
BUILD_DIR := .
# (4)Source files directory path
SRC_DIRS := .
# (5)Library files directory path
LIBDIR :=
# (6)Add library files
LIBS :=
# (7)Target file, excutable file.
#TARGET := main fitbodyapp
#This main function helloworld
#TARGET :=fitbodyapp
TARGET :=helloworld
# (8)Source files(code), to be compiled
# Find source files we want to compile
# *expression must around by single quotos
# SRCS = $(wildcard ./src/*.cpp)
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
# (9)Object files
# String substituion for every C/C++ file
# e.g: ./src/bank.cpp urns into ./build/bank.cpp.o
# OBJS = $(patsubst %cpp,%.o,$(SRCS))
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
# (10)Dependency files
DEPS := $(OBJS:.o=.d)
# (11)Include files directory path
# Every folder in ./src find include files to be passed via clang
# INCDIR = -I./inc
# INC_DIR = ./inc
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
# (12)Include files add together a prefix, clang make sense that -I flag
# INCS = -I$(INC_DIR)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# (13)Make Makefiles output Dependency files
# That -MMD and -MP flags together to generate Makefiles
# That generated Makefiles will take .o as .d to the output
CPP_FLAGS := $(INC_FLAGS) -MMD -MP
# Link: Generate executable file from object file
$(BUILD_DIR)/$(TARGET):$(OBJS)
$(CXX) -o $(TARGET) $(OBJS)
# Compile: Generate object files from source files
$(BUILD_DIR)/%.cpp.o: $(SRC_DIRS)/%.cpp
mkdir -p $(dir $@)
$(CXX) $(CPP_FLAGS) $(CXX_FLAGS) -c $< -o $@
.PHONY: clean
clean:
# rm -r $(BUILD_DIR)
rm -r $(OBJS) $(TARGET) *.d
-include $(DEPS)
# Packaging Debug and Release p-d-a-r-n-4-OVER.
# may see:
# https://cmake.org/cmake/help/latest/guide/tutorial/Packaging%20Debug%20and%20Release.html#multicpackconfig-cmake
include("release/CPackConfig.cmake")
set(CPACK_INSTALL_CMAKE_PROJECTS
"debug;theFitBody;ALL;/"
"release;theFitBody;ALL;/"
)
#
# Run cpack specifying our custom configuration file with the config option.
# cpack --config MultiCPackConfig.cmake
# Packaging Debug and Release p-d-a-r-n-4-OVER.
{
"files.defaultLanguage": "c++",
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.acceptSuggestionOnEnter": "off",
"code-runner.runInTerminal": true,
"code-runner.executorMap": {
// Not Use Makefile
//"c": "cd $dir && gcc -std=c11 -stdlib=libc++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
//"cpp": "cd $dir && g++ -std=c++11 -stdlib=libc++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
// Use Makefile
"c": "cd $dir && make && ./$fileNameWithoutExt && make clean",
"cpp": "cd $dir && make && ./$fileNameWithoutExt && make clean"
//
// 1.single source file compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__helloworld.cpp
// In-source build
// "c/cpp": "cd $dir && cmake . && make && ./$fileNameWithoutExt && make clean"
//
// Using CMake — execute the cmake command and pass it the directory
// that contains the source code and the CMakeLists.txt file — in this
// case “.” refers to the current directory:
// cmake .
// CMake identified the environment settings for the Linux/macOS/
// windows device and created the Makefile for this project, which can
// be viewed. Do not make edits to this Makefile, as any edits will be
// overwritten the next time that the cmake utility is executed.
// Once the Makefile has been created, the make command can be used to
// build the project:
// make
// ./$fileNameWithoutExt
// It works!
// may see:
// Introduction to CMake by Example:
// http://derekmolloy.ie/hello-world-introductions-to-cmake/
//
// 2.single source file build directory compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__helloworld.cpp
//
// Directory build for target, CMakeCache.txt, CMakeFiles, Makefile,
// cmake_install.cmake.
//
// Out-source build
// For this Architecture from 2 ~ 12, I wish to place all of the build
// files in the build directory, which is achieved very simply by
// calling the cmake program from within the build directory, as
// follows.
// The build directory then contains the Makefile for the project,
// which correctly refers to the files in the src and include
// directories. The project can then be built from the build directory
// using the make command.
// One nice feature of this approach is that all of the files related
// to the build process are within the build directory as illustrated
// by the tree utility output.
// To clean this project you can simply recursively delete all files/
// directories within the build directory. which is the same file
// system structure as was present before the cmake program was
// executed.
// Important: If you add new source files to your project it is very
// important that you call the cmake program again, otherwise the
// Makefiles will not be updated to account for any additions.
// may see:
// http://derekmolloy.ie/hello-world-introductions-to-cmake/
//
// "c/cpp": "cd $dir/./build && cmake .. && make && ./$fileNameWithoutExt && make clean"
// OR,
// "c/cpp": "cd $dir/./build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*"
//
// 3.single source file build directory include compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// |__helloworld.h
// |__helloworld.cpp
//
// Directory inc for include files.
// Out-source build
// cd $dir/./build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 4.source file build directory include compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// | |__helloworld.h
// |__src
// |__helloworld.cpp
//
// Directory src for source files.
// Out-source build
// cd $dir/../build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 5. main source file build directory include compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// | |__helloworld.h
// |__main.cpp
// |__src
// |__helloworld.cpp
//
// main.cpp for main function in top directory of the Project.
// Out-source build
// cd $dir/./build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 6. main source file build directory include compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// | |__helloworld.h
// |__src
// |__helloworld.cpp
// |__main.cpp
//
// main.cpp for main function under the src directory.
// Out-source build
// cd $dir/../build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 7. separated main source file build directory include compile
// command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// | |__helloworld.h
// |__common
// |__main.cpp
// |__src
// |__helloworld.cpp
//
// main.cpp for main function under the common directory.
// Out-source build
// cd $dir/../build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 8. separated main source file build directory include link library
// compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// | |__helloworld.h
// |__library_link
// |__library_link_.css
// |__common
// |__main.cpp
// |__src
// |__helloworld.cpp
//
// Directory library_link: for the project to link library (e.g:
// library_link_.css).
// Out-source build
// cd $dir/../build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 9. separated main source file build directory include link library
// test input compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__inc
// | |__helloworld.h
// |__library_link
// |__library_link_.css
// |__common
// |__main.cpp
// |__src
// |__helloworld.cpp
// |__test_input
// |__test_input_.txt
//
// Directory test_input: for the project to input file (e.g:
// test_input_.txt or test_input_.md or others.
// Out-source build
// cd $dir/../build && cmake .. && make && ./$fileNameWithoutExt && cd .. && rm -r build/*
//
// 10. multiple separated main source file build directory include link library
// test input compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__patch_taylor
// | |__CMakeLists.txt
// | |__helloworld_taylor.h
// | |__helloworld_taylor.cpp
// |__patch_david
// | |__CMakeLists.txt
// | |__helloworld_david.h
// | |__helloworld_david.cpp
// |__library_link
// | |__library_link_.css
// |__main.cpp
// |__test_input
// |__test_input_.txt
//
// Directory patch_taylor: for the taylor to patch;
// Directory patch_david: for the taylor to patch.
// Out-source build
//
//
//
// 11. multiple directroy separated main source file build directory include link library
// test input compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__patch_taylor
// | |__CMakeLists.txt
// | |__inc_taylor
// | | |__helloworld_taylor.h
// | |__src_taylor
// | |__helloworld_taylor.cpp
// |__patch_david
// | |__CMakeLists.txt
// | |__inc_david
// | | |__helloworld_david.h
// | |__src_david
// | |__helloworld_david.cpp
// |__library_link
// | |__library_link_.css
// |__main.cpp
// |__test_input
// |__test_input_.txt
//
// Directory patch_taylor: for the taylor to patch dircetoy;
// Directory patch_david: for the taylor to patch dircetoy.
// Out-source build
//
//
//
// 12. multiple directroy separated main source file build directory include link library
// test input compile command below.
// The Architecture of workspace HelloWorld are:
// HelloWorld
// |
// |_.vscode
// | |__c_cpp_properties.json
// | |__launch.json
// | |__settings.json
// | |__tasks.json
// |__CMakeLists.txt
// |__build
// |__patch_taylor
// | |__CMakeLists.txt
// | |__inc_taylor
// | | |__helloworld_taylor.h
// | |__library_link
// | | |__library_link_taylor_.css
// | |__src_taylor
// | |__helloworld_taylor.cpp
// |__patch_david
// | |__CMakeLists.txt
// | |__inc_david
// | | |__helloworld_david.h
// | |__library_link
// | | |__library_link_david_.css
// | |__src_david
// | |__helloworld_david.cpp
// |__main.cpp
// |__test_input
// |__test_input_.txt
//
// Directory patch_taylor: for the taylor to patch all dircetoy;
// Directory patch_david: for the taylor to patch all dircetoy.
// Out-source build
//
//
//
},
"code-runner.saveFileBeforeRun": true,
"code-runner.preserveFocus": false,
"code-runner.clearPreviousOutput": false,
"code-runner.ignoreSelection": true,
// "C_Cpp.clang_format_sortIncludes": true,
"editor.formatOnType": true,
"clang.cxxflags": [
"-std=c++11"
],
"clang.cflags": [
"-std=c11"
],
"clang.completion.enable": true
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Compile With clang++",
"command": "clang++",
"args": [
"-std=c++11",
"-stdlib=libc++",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-g"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include "thefitbodyConfig.h"
#include "thefitbodyConfig.h.in"
// Selecting static or shared Librarires s-s-o-s-l-n-12-~/test/test.h.
// #include "./test/test.h"
// Selecting static or shared Librarires s-s-o-s-l-n-12-~/test/test.h.
// Optional Library step o-7-5-thefitbody.cpp.
/*
#ifdef USE_TEST
# include "test.h"
// Or # include "./test/test.h"
#endif
*/
// Optional Library step o-7-5-thefitbody.cpp.
// Optional Library step o-7-6-thefitbody.h.in.
/*
#ifdef USE_TEST
const double variable = accept_variable(input_value)
#else
const double variable = accept_other_variable(input_value)
#endif
*/
// Optional Library step o-7-6-thefitbody.h.in.
using namespace std;
int main(int argc, char **argv) {
// Just test Project theFitBody via input-output-----------------------------
// may see:
// https://www.thecrazyprogrammer.com/2011/03/c-program-to-calculate-square-root-of.html
float sqrt_test_project_input_, test_result_;
cout << "Enter any number to test input-output for Project theFitBody:";
cin >> sqrt_test_project_input_;
test_result_ = sqrt(sqrt_test_project_input_);
cout << "Square root of " << sqrt_test_project_input_ << "is" << test_result_;
// Just test Project theFitBody via input-output-----------------------------
const double inputValue = std::stod(argv[1]);
//
// Project version step p-v-5-4-thefitbodyConfig.h.in.
/*
if (argc < 2) {
// report version
std::cout << argv[0] << " Version " << THEFITBODY_VERSION_MAJOR << "."
<< THEFITBODY_VERSION_MINOR << std::endl;
std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
*/
// Project version step p-v-5-4-thefitbodyConfig.h.in.
//
//
SofijaMarcas sofija_marcas_temporary_;
sofija_marcas_temporary_.printHello();
cout << endl;
return 0;
// aab4aa47eb3a0723f63427daed1a7bcfca5b6e5b
// Test to local Repository.
}
#ifndef thefitbodyConfig_h
#define thefitbodyConfig_h
#include <iostream>
#include <string>
#include <vector>
class SofijaMarcas {
public:
void printHello();
};
void SofijaMarcas::printHello() {
vector<string> msg{"Hello", "C++", "World",
"from", "VS Code", "and the C++ extension!"};
for (const string &word : msg) {
cout << word << " ";
}
cout << endl;
std::cout << "25歳の元妻、資金が尽き「パパ活」をしていた" << std::endl;
int i = 0;
while ((i++) < 3)
cout << "若い身体を使って世渡りするのは構わないが殺人はまずいよ\n";
cout << endl;
}
#endif /* thefitbodyConfig_h */
#include "thefitbodyConfig.h"
// the configured options and settings for theFitBody
#define THEFITBODY_VERSION_MAJOR @THEFITBODY_VERSION_MAJOR@
#define THEFITBODY_VERSION_MINOR @THEFITBODY_VERSION_MINOR@
// Project version p-v-5-5-OVER.
// #cmakedefine USE_TEST
// Optional Library step o-7-7-OVER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment