@Gitter :gitter.im/cnruby
Code ID: basic_122
Code Name: Hello, Library's Components!
# For MacOS 10.11+
brew install boost
# For Ubuntu 20.04+
sudo apt install libboost-all-dev
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 -->
#<!-- 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 -->
#<!-- 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 -->
//<!-- 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 -->
@Gitter: gitter.im/cnruby
@Github: github.com/cnruby
@Twitter: twitter.com/cnruby
@Blogspot: cnruby.blogspot.com
- https://cmake.org/cmake/help/latest/command/configure_file.html
- https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file
- https://riptutorial.com/cmake/example/26652/generate-a-cplusplus-configure-file-with-cmake
- https://stackoverflow.com/questions/48580399/how-to-ensure-a-generated-config-h-file-is-in-the-include-path
- https://github.com/bast/cmake-example/tree/master/cmake
- https://cmake.org/pipermail/cmake/2006-May/009049.html
- https://cmake.org/cmake/help/latest/module/FindBoost.html
- https://stackoverflow.com/questions/58081084/target-boostlibrary-already-has-an-imported-location-link-errors
- https://stackoverflow.com/questions/12578499/how-to-install-boost-on-ubuntu
- https://www.boost.org/doc/libs/
- https://www.boost.org/doc/libs/1_73_0/libs/filesystem/doc/index.htm