First you should read about the difference between and #include "filepath" here.#include <filepath>
Personally, I'm working with Boost from Visual Studio as follows:
boost library root (in my case C:\Program Files (x86)\Boost_1_53).#include <boost/lexical_cast/lexical_cast_old.hpp>If you're using non headers-only libraries you should also add path to Boost libraries in Project properties → Linker → General → Additional Libraries Directories.
if it's not a typo, the "," is not needed in the set directive :
set(BOOST_ROOT "C:/dev/tools/boost_1_60_0")
this should work as expected.
The first variant,
Boost_INCLUDE_DIRS - Boost include directories
is among variables titled with
results are reported in variables:
These variable are for using (via read) in the after CMakeLists.txt.find_package(Boost)
The second variant,
Boost_INCLUDE_DIR - Directory containing Boost headers
is among variables titled with
saves search results persistently in CMake cache entries:
That is, you may set this CACHE variable (e.g. with option when call -D) for hint CMake about the Boost location.cmake
But preferable way for hint CMake about Boost location is to set variables in the list above, titled with
This module reads hints about search locations from variables:
When read these variables, CMake ( script) checks their value for correctness. E.g. it could be checked that directory stored in variable FindBoost.cmake actually contains some Boost headers.BOOST_INCLUDEDIR
Following recipe should work
Download Boost binaries from official boost binaries location and install to say C:\Boost
Most times you do not need to build Boost on your own.
Your CMakeLists.txt should look like follows
cmake_minimum_required (VERSION 3.8)
project(boostAndCMake)
set(BOOST_ROOT "C:\Boost") # either set it here or from the command line
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS system) # header only libraries must not be added here
add_executable(CMakeProject2 CMakeProject2.cpp CMakeProject2.h)
target_include_directories(CMakeProject2 PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(CMakeProject2 ${Boost_LIBRARIES})
Because we used on the REQUIRED call, CMake will fail execution and skip the rest of the script if it cannot be found. So no need to check find_package. You need to check it, when you omit Boost_FOUND.REQUIRED
Now from the command line call from the directory where your script resides:
cmake -H. -Bbuildit -G "Visual Studio 15 2017" -DBOOST_ROOT=C:\Boost
This creates a build directory named buildit in the current directory, further creates a solution for Visual Studio 2017 inside the build directory and provides the setting for the variable that is used in the BOOST_ROOT call to identify the Boost directory on your computer. To see what options are available on the find_package call see FindBoost documentation in CMake.find_package(Boost ...)
Header Only Libraries
If your libraries are header only you need to omit them from the call. To see which libraries are not header only see this post.find_package(Boost ...)
Using newer Boost versions
If your CMake installation cannot find the requested version, e.g. 1.69.0, but supports the naming scheme of the more recent Boost version you can use it with . Last change of the Boost naming scheme was from 1.65.1 to 1.66.set(Boost_ADDITIONAL_VERSIONS "1.69.0" "1.69")
removes the versioned subdirectory from the include path (as @IgorR. pointed out).--layout=system
"Removing that second boost in the path" is a bad idea. In a respectable OS (cough...), the include files for various libraries are supposed to co-exist in one common include directory, hence the subdirectory to avoid clashes. Boost headers are therefore habitually referred to as e.g. boost, i.e. including that #include <boost/any.hpp> subdirectory.boost/
This is done both by third-party software using Boost, and by Boost itself. If you remove the second from the path, you would end up with boost, and any Boost-using software won't compile as not even Boost could find its own includes.C:\Boost\include\any.hpp
After digging around in CMake and experimenting, I determined that CMake was unhappy with the fact that all of my Boost libraries were contained in and not /usr/local/lib/boost. Once I soft-linked them back out, the build worked./usr/local/lib
It should be easy to accomplish what you want without using anything platform specific...
std::string dstFolder = "New Folder";
std::string path(dstFolder);
/*
* i starts at 2 as that's what you've hinted at in your question
* and ends before 10 because, well, that seems reasonable.
*/
for (int i = 2; boost::filesystem::exists(path) && i < 10; ++i) {
std::stringstream ss;
ss << dstFolder << "(" << i << ")";
path = ss.str();
}
/*
* If all attempted paths exist then bail.
*/
if (boost::filesystem::exists(path))
throw something_appropriate;
/*
* Otherwise create the directory.
*/
boost::filesystem::create_directory(path);
CMake's command has two modes: Module and Config mode. Many related questions on this site feature answers that are using Module mode. However, Boost 1.70 and greater provides a find_package or BoostConfig.cmake package configuration file to easily use with boost-config.cmake Config mode. The package configuration file should be generated when you build Boost. For example, if you build Boost 1.72 into the find_package() directory, the stage file is located here:BoostConfig.cmake
boost_1_72_0/stage/lib/cmake/Boost-1.72.0/BoostConfig.cmake
Your error indicates that you are using Config mode, so you have two options:
Do the steps recommended in the error message to help the Config mode package search complete successfully. Append the path to your Boost installation to the prefix path by adding this line to your CMake file before :find_package()
list(APPEND CMAKE_PREFIX_PATH /home/ubuntu/boost_1_70_0)
Force Module mode by setting the variable before the call to Boost_NO_BOOST_CMAKE:find_package()
set(Boost_NO_BOOST_CMAKE ON)