Dependency management using Conan with a CMake project under VS2017 - c++

I'm trying to setup a development environment for C++ to compile under Linux x64 using CMake integration with VS2017. To better manage dependencies I choose to use Conan but I'm pretty new to this software and I'm wondering what's the best way to have VS2017 to recognize the dependencies of the project.
For example, I've used Conan to install the POCO library for C++ but when I open the Main.cpp file it doesn't recognise the header files location and I'm not really sure where to add those paths.
Can anyone give some hints to solve this?
If needed all the source files are in my Github repo CppLinuxVS.
UPDATE
As per comments on this post, below you can find the contents of the files:
CMakeLists.txt
project(CppLinuxVS)
cmake_minimum_required(VERSION 2.8.12)
add_definitions("-std=c++11")
# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.8/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
add_executable(CppLinuxVS Main.cpp)
target_link_libraries(CppLinuxVS ${CONAN_LIST})
conanfile.txt
[requires]
Poco/1.8.0#pocoproject/stable
[generators]
cmake
UPDATE 2
Output of CMake inside VS2017 after downloading the conan.cmake file into the project instead of having the download specified in CMakeLists.txt. Also updated the CMakeLists.txt to require CMake 3.1.2 as per suggestion in the comments.
1> 17:52:57: Copying files to remote machine...
1> 17:53:00: Finished copying files (elapsed time 00h:00m:02s:799ms).
1> /usr/local/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug" "\var\tmp\src\03967bd6-44be-4e31-b449-a34a45d7109d\Linux-Debug"
1> -- Conan ** WARNING** : This detection of settings from cmake is experimental and incomplete. Please check 'conan.cmake' and contribute
1> -- Conan executing: conan install /var/tmp/src/03967bd6-44be-4e31-b449-a34a45d7109d/Linux-Debug/conanfile.txt -g cmake -s build_type=Debug -s os=Linux -s compiler=gcc -s compiler.version=5 -s compiler.libcxx=libstdc++11 --build=missing
1> PROJECT: Installing /var/tmp/src/03967bd6-44be-4e31-b449-a34a45d7109d/Linux-Debug/conanfile.txt
1> Requirements
1> OpenSSL/1.0.2l#conan/stable from 'conan-center'
1> Poco/1.8.0#pocoproject/stable from 'conan-center'
1> zlib/1.2.11#conan/stable from 'conan-center'
1> Packages
1> OpenSSL/1.0.2l#conan/stable:f68b4e006611addfaec53a2f3d5c0e6b0406266d
1> Poco/1.8.0#pocoproject/stable:e3d8f1070a587658375103e87fd35c8b5c372b6e
1> zlib/1.2.11#conan/stable:15c6f8a55cbf8b39b86ca055629a91be1b2d3cf5
1>
1> zlib/1.2.11#conan/stable: Already installed!
1> OpenSSL/1.0.2l#conan/stable: Already installed!
1> Poco/1.8.0#pocoproject/stable: Already installed!
1> PROJECT: Generator cmake created conanbuildinfo.cmake
1> PROJECT: Generator txt created conanbuildinfo.txt
1> PROJECT: Generated conaninfo.txt
1> -- Conan: Loading conanbuildinfo.cmake
1> -- Current conanbuildinfo.cmake directory: /var/tmp/build/03967bd6-44be-4e31-b449-a34a45d7109d/build/Linux-Debug
1> -- Conan: Compiler GCC>=5, checking major version 5
1> -- Conan: Checking correct version: 5
1> -- Conan: Using cmake targets configuration
1> -- Library PocoUtild found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoUtild.a
1> -- Library PocoMongoDBd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoMongoDBd.a
1> -- Library PocoNetd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoNetd.a
1> -- Library PocoNetSSLd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoNetSSLd.a
1> -- Library PocoCryptod found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoCryptod.a
1> -- Library PocoDatad found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoDatad.a
1> -- Library PocoDataSQLited found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoDataSQLited.a
1> -- Library PocoZipd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoZipd.a
1> -- Library PocoXMLd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoXMLd.a
1> -- Library PocoJSONd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoJSONd.a
1> -- Library PocoFoundationd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoFoundationd.a
1> -- Library pthread not found in package, might be system one
1> -- Library dl not found in package, might be system one
1> -- Library rt not found in package, might be system one
1> -- Library ssl found /root/.conan/data/OpenSSL/1.0.2l/conan/stable/package/f68b4e006611addfaec53a2f3d5c0e6b0406266d/lib/libssl.a
1> -- Library crypto found /root/.conan/data/OpenSSL/1.0.2l/conan/stable/package/f68b4e006611addfaec53a2f3d5c0e6b0406266d/lib/libcrypto.a
1> -- Library dl not found in package, might be system one
1> -- Library z found /root/.conan/data/zlib/1.2.11/conan/stable/package/15c6f8a55cbf8b39b86ca055629a91be1b2d3cf5/lib/libz.a
1> -- Conan: Adjusting default RPATHs Conan policies
1> -- Conan: Adjusting language standard
1> -- Configuring done
1> -- Generating done
1> -- Build files have been written to: /var/tmp/build/03967bd6-44be-4e31-b449-a34a45d7109d/build/Linux-Debug
1> Starting CMake target info extraction ...
1> Extracted source files and headers.
1> Extracted global settings.
1> Extracted code model.
1> Collating data ...
1> Target info extraction done.
CMakeLists.txt updated
project(CppLinuxVS)
cmake_minimum_required(VERSION 3.1.2)
add_definitions("-std=c++11")
include(conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
add_executable(CppLinuxVS Main.cpp)
target_link_libraries(CppLinuxVS ${CONAN_LIBS})

#lusocoding here is a project i setup to demonstrate a working combination of VS -> Cmake -> Conan.
https://github.com/solvingj/vs-cmake-conan-demo
One of the critical parts (as I recall) was CMakeSettings.json, which is supposed to be a machine-specific setting that you don't typically commit to git. However, at the time, there were customizations (i think it was the CLI flags passed to CMake) which i had to add to to make it work. So, i committed that file to git for the demonstration.
See if you can clone and use the project as is, and then slowly compare with your project to find differences.
Hope this helps.

Related

OpenCV & OpenCV contrib build Windows 11

I'm trying to play around with OpenCV and OpenCV Face (a contrib module). Unfortunately I'm bound to a Windows devivce. Furhermore the OpenCV Windows download does not contain the contrib modules e.g. the face one which I need, so I tried to build OpenCV with OpenCV contrib myself. The project itself should run on Windows & Linux.
If I use the prebuild OpenCV files (except the face module), everything works just fine.
Windows specs:
CMake file
cmake_minimum_required(VERSION 3.24)
project(smart_mirror)
set(CMAKE_CXX_STANDARD 23)
include(FetchContent)
add_compile_definitions(JM_DEBUG_MODE=true)
# Add the main target
add_executable(smart_mirror main.cpp src/CameraDevice.cpp "src/VideoProcessor.h" "src/MotionVideoProcessor.cpp" "src/FaceRecognitionVideoProcessor.cpp" "src/FaceDetectorVideoProcessor.cpp")
find_package(OpenCV REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Core WebSockets)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.11.0
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(spdlog)
# Add the OpenCV include directories to the main target
target_include_directories(smart_mirror PRIVATE ${OpenCV_INCLUDE_DIRS})
# Link the main target with OpenCV
target_link_libraries(smart_mirror ${OpenCV_LIBS} spdlog Qt6::Core Qt6::WebSockets)
message(STATUS "Add libs: ${OpenCV_LIBS} and includes: ${OpenCV_INCLUDE_DIRS}")
Project CMake configure (contains a line with all OpenCV_LIBS printed as STATUS message for debugging)
1> CMake generation started for default configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="Y:\smart-mirror\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "Y:\smart-mirror" 2>&1"
1> Working directory: Y:\smart-mirror\out\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.34.31937.0
1> [CMake] -- The CXX compiler identification is MSVC 19.34.31937.0
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Found OpenCV: C:/opencv (found version "4.7.0")
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
1> [CMake] -- Looking for pthread_create in pthreads
1> [CMake] -- Looking for pthread_create in pthreads - not found
1> [CMake] -- Looking for pthread_create in pthread
1> [CMake] -- Looking for pthread_create in pthread - not found
1> [CMake] -- Found Threads: TRUE
1> [CMake] -- Performing Test HAVE_STDATOMIC
1> [CMake] -- Performing Test HAVE_STDATOMIC - Success
1> [CMake] -- Found WrapAtomic: TRUE
1> [CMake] -- Build spdlog: 1.11.0
1> [CMake] -- Build type: Debug
1> [CMake] -- Add libs: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_aruco;opencv_barcode;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_cvv;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_fuzzy;opencv_hfs;opencv_img_hash;opencv_intensity_transform;opencv_line_descriptor;opencv_mcc;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_rapid;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_wechat_qrcode;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto and includes: C:/opencv/include
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: Y:/smart-mirror/out/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.
CMake build command respectively with and without -DBUILD_opencv_world
cmake -B "build" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_OPENGL=ON -DWITH_QT=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DBUILD_JAVA=OFF -DBUILD_FAT_JAVA_LIB=OFF -DBUILD_DOCS=OFF -DVIDEOIO_PLUGIN_LIST=all -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_EXAMPLES=OFF .
I encountered two error cases depending on the CMake settings
1. BUILD_opencv_world=ON
If I run cmake --build build --config Release to build the libs it stops kind of after building opencv_world. If I open the Visual Studio solution to build I get error messages related to opencv_world
Error output (cmake --build runs until the very first marked line and stop without any output, so first I thought everything built without error)
Error list
2. -DBUILD_opencv_world=OFF
Because I rooted the build issue cause at the opencv_world module (which normally comes with the prebuild binaries), I tried to build without them. This build works but then I get undefined reference error of the linker.
Linker error in Visual Studio while building my project
Edit
I also tried the combi ninja + clang but also no luck. Here it fails even earlier
Ninja + clang fail

Configuring czmq, zmq, and sodium with CMake

I'm having trouble configuring/building czmq with CMake. This is the current project structure with the three libraries' source under "extlibs":
root
|--CMakeLists.txt
|--src
|--include
|--extlibs
| |--CMakeLists.txt
| |--sodium
| |--zmq
| |--czmq
The root CMakeLists.txt:
cmake_minimum_required (VERSION 3.15)
set(project czmq_build_project)
set(project_root ${CMAKE_CURRENT_SOURCE_DIR})
set(extlibs ${project_root}/extlibs)
set(msbuild "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/MSBuild.exe")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(project_cfg Release)
project(${project} CXX)
# Add source
add_executable (${project} "src/main.cpp" "include/class.hpp")
# Directories to search for headers -----------
include_directories(${extlibs})
include_directories(${project_root}/include)
# Add 3rd Party Libraries
add_subdirectory(${extlibs})
And the "extlibs/CMakeLists.txt"
# ----------------------------------------------
# Third Party Libraries
# Note: All libraries are being built under a
# static release config for x64 (at the moment)
# ----------------------------------------------
# czmq requires libzmq. Additionaly, libsodium is
# used for the curve encryption library for libzmq.
# Therefore, we build: libsodium->libzmq->czmq.
# ----------------------------------------------
include(ExternalProject)
set(lib_out "${CMAKE_BINARY_DIR}/extlibs")
add_custom_target(buildsodium ALL)
# Configure libsodium -------------------------
function(build_libsodium)
set(sodium_root "${extlibs}/sodium")
set(sodium_sln "${sodium_root}/builds/msvc/vs2019/libsodium.sln")
set(sodium_bin "${sodium_root}/bin")
set(sodium_lib "${sodium_root}/bin/x64/${project_cfg}/v142/static/libsodium.lib")
set(sodium_out "${lib_out}/sodium/libsodium.lib")
set(sodium_bldcmd ${msbuild} -m -t:Build -p:configuration=Static${project_cfg} -p:platform=x64 ${sodium_sln})
ExternalProject_Add(libsodium
SOURCE_DIR "${sodium_root}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${sodium_bldcmd}
INSTALL_COMMAND ""
ALWAYS TRUE
)
add_custom_command(TARGET libsodium POST_BUILD
BYPRODUCTS ${sodium_out}
COMMAND echo "Copying libsodium.lib to ${sodium_out}"
COMMAND ${CMAKE_COMMAND} -E copy ${sodium_lib} ${sodium_out}
COMMAND echo "Removing ${sodium_bin}"
COMMAND ${CMAKE_COMMAND} -E remove_directory ${sodium_bin}
)
add_dependencies(buildsodium libsodium)
endfunction()
add_custom_target(buildzmq ALL)
# Configure libzmq ----------------------------
function(build_libzmq)
set(ENABLE_CURVE OFF )
set(WITH_LIBSODIUM_STATIC ON)
set(ENABLE_CPACK OFF)
set(BUILD_SHARED OFF)
set(BUILD_STATIC ON)
set(BUILD_TESTS OFF)
set(CMAKE_INCLUDE_PATH ${extlibs}/sodium/src/libsodium/include)
set(CMAKE_LIBRARY_PATH ${lib_out}/sodium)
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_INSTALL_PREFIX ${lib_out}/zmq)
add_subdirectory(zmq)
add_dependencies(buildzmq buildsodium)
endfunction()
add_custom_target(buildczmq ALL)
# Configure czmq ------------------------------
function(build_libczmq)
set(ZeroMQ_DIR ${lib_out}/zmq/lib)
set(CZMQ_BUILD_SHARED OFF)
set(CZMQ_BUILD_STATIC ON)
set(BUILD_TESTING OFF)
set(CMAKE_PREFIX_PATH ${lib_out}/zmq)
set(LIBZMQ_INCLUDE_DIRS ${extlibs}/zmq/include)
set(LIBZMQ_LIBRARIES ${lib_out}/zmq/lib)
set(CMAKE_CXX_FLAGS_RELEASE "-DZMQ_STATIC /MT /O2 /Ob2 /DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-DZMQ_STATIC /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_INSTALL_PREFIX ${lib_out}/czmq)
add_subdirectory(czmq)
add_dependencies(buildczmq buildzmq)
endfunction()
build_libsodium()
build_libzmq()
build_libczmq()
CMake output:
CMake generation started for configuration: 'x64'.
1> Working directory: ...<root>\build\x64
1> [CMake] -- Detected ZMQ Version - 4.3.4
1> [CMake] -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
1> [CMake] -- Not building draft classes and methods
1> [CMake] -- Using builtin sha1
1> [CMake] -- CURVE security is disabled
1> [CMake] -- Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: 0x0A00
1> [CMake] -- Using polling method in I/O threads: epoll
1> [CMake] -- Including wepoll
1> [CMake] -- Using polling method in zmq_poll(er)_* API: poll
1> [CMake] -- Using 64 bytes alignment for lock-free data structures
1> [CMake] -- Using condition_variable_t implementation: stl11
1> [CMake] -- Checking whether noexcept is supported
1> [CMake] -- Could NOT find AsciiDoc (missing: ASCIIDOC_EXECUTABLE)
1> [CMake] CMake Deprecation Warning at extlibs/zmq/tests/CMakeLists.txt:2 (cmake_minimum_required):
1> [CMake] Compatibility with CMake < 2.8.12 will be removed from a future version of
1> [CMake] CMake.
1> [CMake]
1> [CMake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
1> [CMake] CMake that the project does not need compatibility with older versions.
1> [CMake]
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_bind_stream_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_bind_ws_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_connect_stream_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_connect_ws_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_socket_options_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Deprecation Warning at extlibs/zmq/unittests/CMakeLists.txt:2 (cmake_minimum_required):
1> [CMake] Compatibility with CMake < 2.8.12 will be removed from a future version of
1> [CMake] CMake.
1> [CMake]
1> [CMake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
1> [CMake] CMake that the project does not need compatibility with older versions.
1> [CMake]
1> [CMake]
1> [CMake] CMake Warning (dev) at C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:426 (message):
1> [CMake] The package name passed to `find_package_handle_standard_args` (LIBZMQ)
1> [CMake] does not match the name of the calling package (libzmq). This can lead to
1> [CMake] problems in calling code that expects `find_package` result variables
1> [CMake] (e.g., `_FOUND`) to follow a certain pattern.
1> [CMake] Call Stack (most recent call first):
1> [CMake] extlibs/czmq/Findlibzmq.cmake:83 (find_package_handle_standard_args)
1> [CMake] extlibs/czmq/CMakeLists.txt:133 (find_package)
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake] -- Could NOT find LIBZMQ (missing: LIBZMQ_LIBRARIES)
1> [CMake] CMake Error at extlibs/czmq/CMakeLists.txt:144 (message):
1> [CMake] libzmq not found.
1> [CMake]
1> [CMake]
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "<root>/build/x64/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "<root>/build/x64/CMakeFiles/CMakeError.log".
The sodium and zmq functions work correctly but czmq does not. Since I am building the libzmq library, I do not have the .lib at configuration time when calling CMake, so czmq complains about not being able to find libzmq.
I have each library installing to "root/build/x64/extlibs/". I have tried a custom target dependency structure but am having no luck with getting czmq to be okay with not seeing the .lib at config time. What can I try to make this work? Thanks!
I suggest that you switch to the conan package manager
https://conan.io/center/libsodium
You can find an example here: https://github.com/damian123/crypto

VCPKG_ROOT not defined for CMake

I am trying to set up vcpkg with a CMake project. Since I intend to have multiple people with different platforms working on this project, I wanted to use an Environment Variable to set CMAKE_TOOLCHAIN_FILE instead of a command line argument as recommended here for cmake: https://vcpkg.readthedocs.io/en/latest/users/integration/
However, It appears that CMake is unable to find the VCPKG_ROOT environment variable. I made a small example separate from my project to see if the problem still exists and it does. Here is my CMakeLists.txt file:
cmake_minimum_required (VERSION 3.8)
#vcpkg init
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
MESSAGE("vcpkg root found")
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
else()
MESSAGE("vcpkg not found")
endif()
project ("CmakeVcpkgTestF")
add_executable (CmakeVcpkgTestF "CmakeVcpkgTestF.cpp" "CmakeVcpkgTestF.h")
And here is the associated output when buliding, note that "vcpkg not found is output" instead of "vcpkg root found"
1> CMake generation started for default configuration: 'x64-Debug (default)'.
1> Command line: "cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="F:\VisualStudio2019\CmakeVcpkgTestF\out\install\x64-Debug (default)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "F:\VisualStudio2019\CmakeVcpkgTestF" 2>&1"
1> Working directory: F:\VisualStudio2019\CmakeVcpkgTestF\out\build\x64-Debug (default)
1> [CMake] vcpkg not found
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: F:/VisualStudio2019/CmakeVcpkgTestF/out/build/x64-Debug (default)
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted includes paths.
1> CMake generation finished.
So far all I have done install vcpkg (running the required bootstrap as well), is there something else I need to do to get this to work? Also it is worth noting that vcpkg is installed at the root of my drive(specifically F:/vcpkg/vcpkg), not at root of the code, but I don't imagine that is causing the problem.
Thanks in advance for any assistance.
Based on your output, this is the second time your code has run. Your if condition asks whether CMAKE_TOOLCHAIN_FILE is defined at all, but it is! You defined it as a cache variable, which was then loaded into the global scope on the second run.
You probably want a test more like this:
set(vcpkg "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
if(NOT CMAKE_TOOLCHAIN_FILE AND EXISTS "${vcpkg}")
set(CMAKE_TOOLCHAIN_FILE "${vcpkg}"
CACHE FILEPATH "CMake toolchain file")
message(STATUS "vcpkg toolchain found: ${CMAKE_TOOLCHAIN_FILE}")
endif()

CMake project compilation error on VisualStudio using external SDK toolchain file

I am using VisualStudio CMake project on Windows machine.
I am using an external SDK in order to cross compile my C++ program for Linux arm architecture.
I added the SDK toolchain to cmakeToolchain path which is :
/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
and this is my CMakeLists.txt file :
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
#list(APPEND CMAKE_PREFIX_PATH /home/ubuntu/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/boost/usr/include/boost)
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include)
Set(Boost_NO_BOOST_CMAKE ON)
#set(BOOST_ROOT "/home/ubuntu/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/boost")
message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
set(CROSS_COMPILER_DIR /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr)
set(CMAKE_C_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
#set(CMAKE_SYSTEM_NAME Linux)
message(STATUS "CMAKE_C_COMPILER='${CMAKE_C_COMPILER}'")
message(STATUS "CMAKE_CXX_COMPILER='${CMAKE_CXX_COMPILER}'")
find_package(Boost 1.66.0)
if(Boost_FOUND)
message (STATUS "success!")
add_executable (CMakeProject4 "CMakeProject4.cpp" "CMakeProject4.h")
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(CMakeProject4 ${Boost_LIBRARIES})
endif()
As you can see I am setting my SDK compilers bin paths to CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables.
When I Debug, I find that :
1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> [rsync] rsync -t --delete --delete-excluded -v -r --exclude=.vs --exclude=.git --exclude=out "." rsync://ubuntu#localhost:56934/-home-ubuntu-CMake-RemoteCML
1> [rsync] sending incremental file list
1> [rsync]
1> [rsync] sent 229 bytes received 13 bytes 161.33 bytes/sec
1> [rsync] total size is 4,429 speedup is 18.30
1> Finished copying files (elapsed time 00h:00m:04s:043ms).
1> CMake generation started for configuration: 'Linux-Release'.
1> Found cmake executable at /home/ubuntu/.vs/cmake/bin/cmake.
1> /home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_TOOLCHAIN_FILE="/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML/CMakeLists.txt";
1> [CMake] -- The C compiler identification is GNU 7.4.0
1> [CMake] -- The CXX compiler identification is GNU 7.3.0
1> [CMake] -- Check for working C compiler: /usr/bin/cc
1> [CMake] -- Check for working C compiler: /usr/bin/cc -- works
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Check for working CXX compiler: /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
1> [CMake] -- Check for working CXX compiler: /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -- broken
1> [CMake] CMake Error at /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message):
1> [CMake] The C++ compiler
1> [CMake]
1> [CMake] "/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
1> [CMake]
1> [CMake] is not able to compile a simple test program.
1> [CMake]
1> [CMake] It fails with the following output:
1> [CMake]
1> [CMake] Change Dir: /home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command(s):/usr/bin/make cmTC_2cb5a/fast && /usr/bin/make -f CMakeFiles/cmTC_2cb5a.dir/build.make CMakeFiles/cmTC_2cb5a.dir/build
1> [CMake] make[1]: Entering directory '/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp'
1> [CMake] Building CXX object CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -o CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o -c /home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
1> [CMake] Linking CXX executable cmTC_2cb5a
1> [CMake] /home/ubuntu/.vs/cmake/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2cb5a.dir/link.txt --verbose=1
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o -o cmTC_2cb5a
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crt1.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crti.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtbegin.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc_s
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lc
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc_s
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtend.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtn.o: No such file or directory
1> [CMake] collect2: error: ld returned 1 exit status
1> [CMake] CMakeFiles/cmTC_2cb5a.dir/build.make:86: recipe for target 'cmTC_2cb5a' failed
1> [CMake] make[1]: *** [cmTC_2cb5a] Error 1
1> [CMake] make[1]: Leaving directory '/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp'
1> [CMake] Makefile:121: recipe for target 'cmTC_2cb5a/fast' failed
1> [CMake] make: *** [cmTC_2cb5a/fast] Error 2
1> [CMake]
1> [CMake]
1> [CMake] CMake will not be able to correctly generate this project.
1> [CMake] Call Stack (most recent call first):
1> [CMake] CMakeLists.txt:6 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeError.log".
1> cd "/home/ubuntu/CMake/RemoteBR";/home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_TOOLCHAIN_FILE="/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML" 2>&1; returned with exit code: 1
I can see here that CMake can identify the SDK toolchain compiler which I want to use which is GNU 7.3.0 but it's broken!
When I open CMakeCache.txt , I find this :
//No help, variable specified on the command line.
CMAKE_CXX_COMPILER:UNINITIALIZED=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7
CMAKE_CXX_FLAGS:STRING=
//Flags used by the CXX compiler during DEBUG builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g
//Flags used by the CXX compiler during MINSIZEREL builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
//Flags used by the CXX compiler during RELWITHDEBINFO builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
//No help, variable specified on the command line.
CMAKE_TOOLCHAIN_FILE:UNINITIALIZED=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
This is my C++ .cpp file program :
#include "CMakeProject4.h"
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
typedef std::istream_iterator<int> in;
std::cout << "Type in any number: ";
std::for_each(
in(std::cin), in(), std::cout
<< (boost::lambda::_1 * 10)
<< "\nType in another number: ");
}
But when I try to run CMake in order to compile my program using :
cmake -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
I have this error :
Error Compilation
Any help please ?
When you use a toolchain file, you shouldn't set the compiler yourself. You should let it to the toolchain file, as it know how to cross compile. Things like CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR should be left to the toolchain file.
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_NO_BOOST_CMAKE ON)
# I think the prefix should point to usr directly, not the include directory
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr)
message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
message(STATUS "CMAKE_C_COMPILER='${CMAKE_C_COMPILER}'")
message(STATUS "CMAKE_CXX_COMPILER='${CMAKE_CXX_COMPILER}'")
project(whatever CXX)
# Better to fail fast when there's a package missing
find_package(Boost 1.66.0 REQUIRED)
add_executable (CMakeProject4 CMakeProject4.cpp CMakeProject4.h)
target_link_libraries(CMakeProject4 PRIVATE Boost::headers)
And your CMake arguments should look like this:
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake

CMake found Boost but not requested libraries

I am trying to add Boost to a C++ application using CMake. I have read through all relevant questions I can find on SO, and I feel I am getting closer to a solution. But the CMake still can't find the requested Boost library for some reasons.
I am trying to find "boost_filesystem". The debug shows CMake is looking for "boost_filesystem-vc141-mt-gd-1_65_1". I do have the file "libboost_filesystem-vc141-mt-gd-1_65_1.lib" in the folder "C:\boost\boost_1_65_1\stage\lib". I suppose this is the file CMake is looking for, but for some reasons CMake says it can't find it.
Here is the procedure I used to build the Boost. This may be too much details for most people but I suspect it may be helpful to another newbie.
download and extract Boost 1.65.1 in folder C:\boost\boost_1_65_1
go to developer prompt command line and run bootstrap.bat under the above folder.
updated file visualc.hpp under C:\boost\boost_1_65_1\boost\config\compiler (see Unknown compiler version while compiling Boost with MSVC 14.0 (VS 2015)!
Replaced the lines in the bottom of the file visualc.hpp :
// last known and checked version is 19.11.25506 (VC++ 2017.3):
#if (_MSC_VER > 1911)
with
// last known and checked version is 19.13.26128 (VC++ 2017.5.6):
#if (_MSC_VER > 1913)
Open another file project-config.jam under the folder boost_1_65_1 and updated the second line to the following:
using msvc : 14.1 : "C:\Program Files (x86)\Microsoft Visual Studio\2017
\Professional\VC\Tools\MSVC\14.13.26128\bin\Hostx64\x64\cl.exe" ;
Go back to developer prompt command line and run the following to build Boost:
b2 toolset=msvc-14.1 address-model=64
It seems I have done the following items correctly:
properly built the libraries, though not using the default directory. I confirmed that the requested library is built.
assigned the path correctly to the CMake designated directories
used CMake find_package() correctly
Here are the relevant versions I am using:
VS: 2017 v15.6.1 with CMake 3.10
Boost version: 1.65.1, built with tool MSVC 14.1
Here is the CMakelist.txt:
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(test)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)
set(BOOST_ROOT C:\\boost\\boost_1_65_1)
set(BOOST_INCLUDEDIR C:\\boost\\boost_1_65_1)
set(BOOST_LIBRARYDIR C:\\boost\\boost_1_65_1\\stage\\lib)
set(Boost_DEBUG 1)
find_package(Boost COMPONENTS filesystem REQUIRED)
message(STATUS "Boost LIBRARIES: " ${Boost_LIBRARIES})
add_executable(test_Boost main.cpp)
target_link_libraries(test_Boost ${Boost_LIBRARIES})
here is part of the output that may be relevant:
1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake"
1> Working directory: C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\build\x64-Release
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1073 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1075 ] Boost_USE_MULTITHREADED = ON
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1077 ] Boost_USE_STATIC_LIBS = OFF
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1079 ] Boost_USE_STATIC_RUNTIME = OFF
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1081 ] Boost_ADDITIONAL_VERSIONS =
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1083 ] Boost_NO_SYSTEM_PATHS =
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1151 ] Declared as CMake or Environmental Variables:
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1153 ] BOOST_ROOT = C:\boost\boost_1_65_1
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1155 ] BOOST_INCLUDEDIR = C:\boost\boost_1_65_1
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1157 ] BOOST_LIBRARYDIR = C:\boost\boost_1_65_1\stage\lib
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1159 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1258 ] location of version.hpp: C:/boost/boost_1_65_1/boost/version.hpp
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1282 ] version.hpp reveals boost 1.65.1;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1368 ] guessed _boost_COMPILER = -vc141;-vc140
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1378 ] _boost_MULTITHREADED = -mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1422 ] _boost_RELEASE_ABI_TAG = -
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1424 ] _boost_DEBUG_ABI_TAG = -gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1486 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:\boost\boost_1_65_1\stage\lib;C:\boost\boost_1_65_1/lib;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-vc141-mt-1_65_1;boost_filesystem-vc141-mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-vc141-mt-gd-1_65_1;boost_filesystem-vc141-mt-gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_65_1;boost_system-vc141-mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-vc141-mt-gd-1_65_1;boost_system-vc141-mt-gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1762 ] Boost_FOUND = 1
1> -- Boost LIBRARIES:
1> CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
1> Unable to find the requested Boost libraries.
1>
1> Boost version: 1.65.1
1>
1> Boost include path: C:/boost/boost_1_65_1
1>
1> Could not find the following Boost libraries:
1>
1> boost_filesystem
1>
1> Some (but not all) of the required Boost libraries were found. You may
1> need to install these additional Boost libraries. Alternatively, set
1> BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
1> to the location of Boost.
1> Call Stack (most recent call first):
1> CMakeLists.txt(17): (find_package)
1>
1>
1> -- Configuring incomplete, errors occurred!
1> See also "C:/Users/david/CMakeBuilds/94321a3b-9fa8-083f-a86f-e151c3abae79/build/x64-Release/CMakeFiles/CMakeOutput.log".
1> C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake" returned with exit code: 1
CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: C:/boost/boost_1_65_1
Could not find the following Boost libraries:
boost_filesystem
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.
Call Stack (most recent call first):
CMakeLists.txt:17 (find_package)
libboost_filesystem-vc141-mt-gd-1_65_1.lib is the static version of the filesystem library (the name starts with lib)
In CMake you are searching for the dynamic version:
set(Boost_USE_STATIC_LIBS OFF)
This cannot work. Now you have to options:
switch the OFF to ON
rebuild boost with the following addition:
b2 toolset=msvc-14.1 address-model=64 --build-type=complete
The command --build-type=complete build all supported variants of the libraries. Just to be on the safe side ;-)