Skip to content

cnruby/w3h1_cmake

 
 

Repository files navigation

Hello, Library's Components!

Using Library's Components For C++ Sources



@Gitter :gitter.im/cnruby
Code ID: basic_122
Code Name: Hello, Library's Components!

Youtube Video

TABLE of CONTENTS

About The Project

About The Project

Requirements

Install The Library boost

# For MacOS 10.11+
brew install boost
# For Ubuntu 20.04+
sudo apt install libboost-all-dev

Get The Code with Shell Commands

git clone https://github.com/cnruby/w3h1_cmake.git basic_122
cd basic_122
git checkout basic_122
code .
#<!-- markdown-exec(cmd:cat docs/output/tree.txt) -->#
.
├── cmake
│  ├── CMakeLists.txt
│  ├── config.h.in
│  ├── GetBoostOne.cmake
│  └── Initialize.cmake
├── CMakeLists.txt
├── config
│  └── config.hxx
└── src
   ├── CMakeLists.txt
   └── main.cxx
#<!-- /markdown-exec -->

The Folder's Structure

Codes of The Project

Codes of The Project

The Structure of Process

The Structure of Process

#<!-- markdown-exec(cmd:cat cmake/GetBoostOne.cmake) -->#
# find a library 'boost' with the component 'filesystem'
set(Boost_USE_MULTITHREADED TRUE)
find_package(Boost 1.72.0 REQUIRED COMPONENTS filesystem)

# check if Boost was found
if(Boost_FOUND)
    message(STATUS "Boost found")
    message(STATUS "Boost_VERSION_STRING\t\t= ${Boost_VERSION_STRING}")
    message(STATUS "Boost_INCLUDE_DIRS\t\t= ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARY_DIRS\t\t= ${Boost_LIBRARY_DIRS}")
    message(STATUS "Boost_LIBRARIES\t\t= ${Boost_LIBRARIES}")
    message(STATUS "Boost_FILESYSTEM_FOUND\t= ${Boost_FILESYSTEM_FOUND}")
    message(STATUS "Boost_FILESYSTEM_LIBRARY\t= ${Boost_FILESYSTEM_LIBRARY}")
else()
    message(FATAL_ERROR "Cannot find Boost")
endif()
#<!-- /markdown-exec -->

The CMake File of Folder 'cmake'

#<!-- markdown-exec(cmd:cat src/CMakeLists.txt) -->#
add_executable(
  main_122
  main.cxx
)
target_include_directories(
  main_122
  PRIVATE ${PROJECT_CONIFG_DIR}
)
# link against the boost libraries
target_link_libraries(
  main_122
  PRIVATE Boost::filesystem
)
#<!-- /markdown-exec -->

The Listfile of Folder 'src'

//<!-- markdown-exec(cmd:cat src/main.cxx) -->//
#include <iostream>
#include <boost/filesystem.hpp>

#include "config.hxx"

int main(int, char**) {
  std::cout << PROJECT_DESCRIPTION << std::endl;

  // use of boost filesystem
  boost::filesystem::path path = Boost_INCLUDE_DIRS;
  std::cout << "boost include path = " << path << std::endl;
  std::cout << "boost include parent path = " << path.parent_path() << std::endl;

  return 0;
}
//#include <boost/filesystem/path.hpp>
//<!-- /markdown-exec -->

The C++ Main File of Folder 'src'

Demonstrate Using Library 'boost'

Final Summary

Final Summary

感谢大家观看!

@Gitter: gitter.im/cnruby

@Github: github.com/cnruby

@Twitter: twitter.com/cnruby

@Blogspot: cnruby.blogspot.com

References