CMake FindBoost module and Boost C++ libraries built with BOOST_LIB_BUILDID - c++

Is it possible to specify the BOOST_LIB_BUILDID for an already built Boost C++ library with the CMake FindBoost module?
I am supposed to use a Boost library that is built for x86 and x64 in the same directory, whereas the x64 version has been built with the following b2 arguments:
-layout=versioned --buildid=x64
I couldn't find anything related to this in the official CMake documentation.

Related

Non-CMake library distributed via vcpkg to CMake consumers - CMake config or Find module?

I write a library that is built with Visual Studio (msbuild).
I distribute binaries only of the library via vcpkg (I use a private vcpkg registry. The portfile.cmake for the port simply downloads a zip file of the binaries and headers and places them in the vcpkg install tree).
I have a client that is using CMake.
I can integrate vcpkg (manifest mode) into CMake and find_package() finds vcpkg ports except for mine.
I've arrived at the point that I think I need to distribute either a CMake config (<my-package>-config.cmake) or a CMake find module (Find<my-package>.cmake).
All of the books I've read for CMake seem to assume that you can easily export your CMake targets to create a CMake config. Since I don't build my library with CMake I'm not sure how to get a Targets.cmake.
The documentation I'm reading on CMake find modules begins discussing resolving dependencies using CMakeFindDependencyMacro and find_dependency() but vcpkg also manages dependencies (this was the whole reason I distributed my library via vcpkg).
What's the solution here; CMake config or find module?
How does one write either if the project is not built with CMake?

cmake FindBoost not finding Boost libraries when building with MinGW on Windows

qtcreator supports both qmake and cmake for cross platform development and
qmake works fine for both msvc and MinGW builds on Windows. However, I'd prefer to support just one tool: cmake.
The CMakeLists.txt at via-httplib works fine on linux and when using cmake to build msvc on Windows.
However, when using cmake to build MinGW on Windows, I get the following error:
CMake Error at C:/Program
Files/CMake/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
Unable to find the requested Boost libraries.
Boost version: 1.69.0
Boost include path: D:/DevLibraries/boost/boost_1_69_0
Could not find the following Boost libraries:
boost_system
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR
to the directory containing Boost libraries or BOOST_ROOT to the
location of Boost.
Both the BOOST_LIBRARYDIR and BOOST_ROOT environment variables are set and are found when using the Visual Studio 15 2017 Win64 generator and default native compilers
The error message indicates that when using the MinGW Makefiles and default native compilers, cmake finds the BOOST_ROOT environment variable but not BOOST_LIBRARYDIR. So it does not seem to be the same problem described here: Cmake doesn't find Boost
Is this a bug in FindBoost.cmake? Is there a "work around"?
It is an issue with the _boost_ARCHITECTURE_TAG in FindBoost.cmake, described on line 1518.
The tag was added to handle Boost 1.66.0 and later versions.
It is not setting the _boost_ARCHITECTURE_TAG for MinGW to -x64, so it is searching for boost library names like:
libboost_system-mgw73-mt-d-1_69.a
instead of:
libboost_system-mgw73-mt-d-x64-1_69.a
There is a workaround: set the cmake variable: Boost_ARCHITECTURE to -x64.
Note: setting Boost_ARCHITECTURE as an environment variable does not work, as FindBoost.cmake does not read Boost_ARCHITECTURE as an environment variable.

Cannot find boost libraries with cmake

I've install boost 1.63.0 on Windows and I am trying to build with CMake (using Visual Studio 2017 as a generator). I'm having trouble getting find_package() to find my boost libraries and I can't figure out why.
CMakeLists.txt:
find_package(Boost REQUIRED COMPONENTS system filesystem thread)
Output:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.8/Modules/FindBoost.cm
ake:1813 (message):
Unable to find the requested Boost libraries.
Boost version: 1.63.0
Boost include path: C:/Program Files (x86)/boost/boost_1_63_0
Could not find the following Boost libraries:
boost_system
boost_filesystem
boost_thread
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Boost finds the includes, but not the libraries. Headers are located at:
%BOOST_ROOT%. Libraries are located at %BOOST_ROOT%/stage/lib. When I look at _boost_LIBRARY_SEARCH_DIRS_RELEASE, the first place it looks is the correct location. I've also tried hard-coding BOOST_LIBRARYDIR to that path just to be sure.
To install boost I extracted the downloaded archive to %BOOST_ROOT%, then ran bootstrap and .\b2 link=static,shared threading=single,multi. This should give me all versions of the libraries. In the case of boost:system, I have the following binaries in %BOOST_ROOT%/stage/lib%:
boost_system-vc100-mt-1_63.dll
boost_system-vc100-mt-1_63.lib
boost_system-vc100-mt-gd-1_63.dll
boost_system-vc100-mt-gd-1_63.lib
libboost_system-vc100-mt-1_63.lib
libboost_system-vc100-mt-gd-1_63.lib
I've tried enabling and disabling the following, but to no avail:
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED OFF )
set( Boost_DEBUG ON )
Here is an interesting part. The Boost_DEBUG parameter spits out this line:
Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_63;boost_system-vc141-mt;boost_system-mt-1_63;boost_system-mt;boost_system
Note the vc141 versus vc100. I think .\b2 built something for vc100. That's strange because I was running it from the Dev Command Prompt for VS 2017. I've taken a wild guess and tried to build boost with ./b2 toolset=msvc-14.1 but I get an error: *** argument error * rule maybe-rewrite-setup ( toolset : setup-script : setup-options : version : rewrite-setup ? )".
How can I ensure that I compile boost with VS2017 or MSVC141?
This thread seems related:
Version numbers for Visual Studio 2017, Boost and CMake
Check the FindBoost.cmake script that is being used. Depending on the version of CMake you use, this version of Boost may not be handled. The dependencies between libraries is set depending on the version of Boost found.
For example the latest version of the script in CMake sources on GitHub handles version 1.63. I had the problem with CMake v3.6.2 which does not handle it.
Regarding the version mismatch for MSVC I don't know, sorry.
I compiled boost, and am compiling the linking application with the same toolset. Therefore I decided that it was safe to simply rename all compiled libs from *-vc100-* to *-vc141-*. While normally I would discourage that (you could get subtle differences in the ABI), in this case I was certain that it was the same compiler and so it's clear that either cmake or b2 had a bug which created(or searched) a file with the wrong name.
After doing that, cmake not only found boost, but linked successfully.

cmake: How to link subdirectory library by ignoring sysroot library?

I am trying to cross compile an application for a different platform (quark processor) using cmake. The platform has provided an SDK to me. My application requires a newer version of one of the libraries in the SDK. I have added the new source code for the library using add_subdirectory(). But my problem is when I use target_link_libraries(), cmake is linking the older version of the library in my SDK. How to enable cmake ignore the library version in the SDK sysroot, and only use the new library version present in the subdirectory?
Edit: My apologies for the initial lack of details.Adding more details to the question as suggested.
My CMakeLists.txt include the following statements
add_subdirectory(libs/mosquitto-1.4.10)
target_link_libraries(myapp mosquittopp)
As mentioned, my problem is that the SDK I am using contains a 1.4 version of mosquitto library. The target_link_libraries() only links the 1.4 version and not the newer 1.4.10 version, even though cmake successfully builds the 1.4.10 version.

My program can not find the boost library

I tried to write code that was a sample of the Boost test library:
#include <boost/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test)
{
BOOST_CHECK(true);
}
I built the source code, and I got the execution file test.exe. I tried to execute that file, but I got an error message.
The program can't start because boost_unit_test_framework-vc80-mt-1_44.dll is missing from your computer. Try reinstalling the program to fix this problem.
But, I have ready that file on my boost library directory.
What's the problem in this case?
Background:
For my build environment, I use Windows 7 Ultimate x64, and Visual Studio 2005.
So I built boost library by my self, and I got all the libraries for the 64-bit computing system.
Using bjam, and I use the command: bjam --toolset=mvsc-8.0 address-model=64 threading=multi --build-system=complete install on 64-bit command prompt window.
After the build, I set the boost library and header directory in Visual Studio directory path option.
Thank you all!
Make sure that the path to your DLL is included in the "PATH" environment variable. (Or include the DLL in your exe directory if you like). That way the DLL will be found.
You can also choose to use the static versions of the Boost libraries.
Build or download the static libraries and point Visual Studio at those instead. The Boost code will be built into your application (increasing its size some) and you will not need a DLL.
If using CMake to configure your application, you can tell CMake to use the static versions of the Boost libraries using Boost_USE_STATIC_LIBS:
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost ... )
This way, the DLLs will not be required, as the requisite Boost definitions will be built into your application via the static libraries.