@Gitter :gitter.im/cnruby
Code ID: basic_117
Code Name: Hello, Package!
- Demonstrate Finding an Executable Package
- The Structures of Project
CMake
Files of The Project- C++ Files of The Project
- Final Summary
- References
- The Project's Commands
#<!-- markdown-exec(cmd:cat docs/output/tree.txt) -->#
.
├── cmake
│ ├── CMakeLists.txt
│ └── config.h.in
├── CMakeLists.txt
├── config
│ └── config.hxx
└── src
├── CMakeLists.txt
└── main.cxx
#<!-- /markdown-exec -->
#<!-- markdown-exec(cmd:cat cmake/CMakeLists.txt) -->#
find_package(Git REQUIRED)
message(STATUS "GIT_FOUND\t\t= ${GIT_FOUND}")
if(GIT_FOUND)
message(STATUS "GIT_EXECUTABLE\t= ${GIT_EXECUTABLE}")
message(STATUS "GIT_VERSION_STRING\t= ${GIT_VERSION_STRING}")
execute_process(
#COMMAND git rev-list --max-count=1 HEAD
COMMAND ${GIT_EXECUTABLE} rev-list --max-count=1 HEAD
# User-defined Variable "GIT_REVISION"
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "GIT_REVISION\t\t= ${GIT_REVISION}")
else()
message(STATUS "Git NOT FOUND")
endif(GIT_FOUND)
configure_file(
${PROJECT_SOURCE_DIR}/cmake/config.h.in
${PROJECT_SOURCE_DIR}/config/config.hxx
)
#<!-- /markdown-exec -->
//<!-- markdown-exec(cmd:cat cmake/config.h.in) -->//
#ifndef CMAKE_CONFIG_H
#define CMAKE_CONFIG_H
const char *GIT_VERSION = "@GIT_VERSION_STRING@";
const char *GIT_REVISION = "@GIT_REVISION@";
#endif
//<!-- /markdown-exec -->
//<!-- markdown-exec(cmd:cat config/config.hxx) -->//
#ifndef CMAKE_CONFIG_H
#define CMAKE_CONFIG_H
const char *GIT_VERSION = "2.21.0";
const char *GIT_REVISION = "e5b2c4b722bad446d2b9673bc0daaa507aeaabd6";
#endif
//<!-- /markdown-exec -->
//<!-- markdown-exec(cmd:cat src/main.cxx) -->//
#include <iostream>
#include "config.hxx"
int main(int, char **)
{
std::cout << "Hello, C++ Package!" << std::endl;
std::cout << "git version:\t\t" << GIT_VERSION << std::endl;
std::cout << "git revision hash:\t" << GIT_REVISION << std::endl;
}
//<!-- /markdown-exec -->
@Gitter: gitter.im/cnruby
@Github: github.com/cnruby
@Twitter: twitter.com/cnruby
@Blogspot: cnruby.blogspot.com
- https://cmake.org/cmake/help/latest/command/find_package.html
- https://cmake.org/cmake/help/latest/command/execute_process.html
ruby format-codes.rb
git clone https://github.com/cnruby/w3h1_cmake.git basic_117
cd basic_117
git checkout basic_117
code .
cmake -GNinja -Bbuild/
cmake --build build/ --clean-first -v
cmake --build build/ --target clean
cmake --build build/ --clean-first -v &> v11.txt
# generate the configure file
rm -rf config
cmake --build build/ --clean-first
cmake -Bbuild/
cmake --build build/ --target rebuild_cache
cmake --build build/ --clean-first
./bin/main_117
# update the configure file
cmake --build build/ --clean-first
# others
markdown-exec README.md
code build/build.ninja
ruby format-codes.rb
cmake --check-system-vars --build build/
cmake --help-command find_package | less