Skip to content

cnruby/w3h1_cmake

 
 

Repository files navigation

Hello, C++ Library!

Build a Single Header File with CMake


@Gitter :gitter.im/cnruby
Code ID: basic_111
Code Name: Hello, C++ Library!

TABLE of CONTENTS

The Structure of Project "basic_111"

Get The Code with Shell Commands

git clone https://github.com/cnruby/w3h1_cmake.git basic_111
cd basic_111
git checkout basic_111
code .

What is The Folder's Structure of Project

#<!-- markdown-exec(cmd:cat tree.txt) -->#
.
├── CMakeLists.txt
├── include
│  └── local
│     ├── CMakeLists.txt
│     └── header.hxx
└── src
   ├── CMakeLists.txt
   └── main.cxx
#<!-- /markdown-exec -->

What is The Process's Structure of Project

_image

What is The Command's Structure of Project

_image

Build and Run The Project

How to Build The Bridge Between C++ File and Library

#<!-- markdown-exec(cmd:cat src/CMakeLists.txt) -->#
add_executable(
  main_111
  main.cxx
)
target_link_libraries(main_111 lib_111)
#<!-- /markdown-exec -->

How to Build The Library of A Single Header File

#<!-- markdown-exec(cmd:cat include/local/CMakeLists.txt) -->#
add_library(lib_111 INTERFACE)
target_include_directories(
  lib_111
  INTERFACE
  ${PROJECT_SOURCE_DIR}/include/local/
)
#<!-- /markdown-exec -->

Demonstrate The Project

Analyze The Build of Project

How to Understand the Build's Process of Project

_image

Command of Analyzing Build on Ninja

cmake --build build/ --clean-first -v

Demonstrate Build's Process on Ninja

Commands of Analyzing Build on C++ Complier

./bin/main_111
# compile
c++ -I./include/local -std=gnu++1z -MD -MT bin/main.cxx.o -MF  bin/main.cxx.o.d \
    -o bin/main.cxx.o -c ./src/main.cxx -v
# link
c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names \
     bin/main.cxx.o  -o ./bin/main_111 -v

Demonstrate Build's Process on C++ Complier

Final Summary

_image

感谢大家观看!

@Gitter: gitter.im/cnruby

@Github: github.com/cnruby

@Twitter: twitter.com/cnruby

@Blogspot: cnruby.blogspot.com

References

The Project's Commands

Formtting The Codes

ruby format-codes.rb

Build and Run The Project

cmake -GNinja -Bbuild/
cmake --build build/ --clean-first -v
./bin/main_111
rm ./bin/main.* ./bin/main_*
c++ -I./include/local -std=gnu++1z -MD -MT bin/main.cxx.o -MF  bin/main.cxx.o.d \
    -o bin/main.cxx.o -c ./src/main.cxx
c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names \
    bin/main.cxx.o -o ./bin/main_111
c++ -I./include/local -std=gnu++1z -MD -MT bin/main.cxx.o -MF  bin/main.cxx.o.d \
    -o bin/main.cxx.o -c ./src/main.cxx -v
c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names \
    bin/main.cxx.o -o ./bin/main_111 -v