Build project using CMake, Ninja and clang for VS 2019 - c++

So, I want to build my project using CMake and clang as a frontend for VS2019. What I already try:
CMakeLists.txt
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
#(CMAKE_INSTALL_PREFIX "C:\\Program Files\\LLVM\\bin")
project(sink)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++17 -pedantic")
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}/bin")
file(GLOB SOURCES "${SRC_DIR}/*.cpp" "${SRC_DIR}/*.cc" "${SRC_DIR}/*.c")
file(GLOB HEADERS "${INCLUDE_DIR}/*.h" "${INCLUDE_DIR}/*.hpp")
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
CMakeSettings.json
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-H. -G Ninja -Bbuild -DCMAKE_CXX_COMPILER:PATH=\"C:\\Program Files\\LLVM\\bin\\clang-cl.exe\"",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
}
]
}
And which errors I get:
1> CMake generation started.
1> Command line: E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\theha\CMakeBuilds\7c084052-2033-9235-9a50-93f9ca5000be\install\x64-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -DCMAKE_C_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -H. -G Ninja -Bbuild -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\theha\projects\sink"
1> Working directory: C:\Users\theha\CMakeBuilds\7c084052-2033-9235-9a50-93f9ca5000be\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.20.27404.0
1> [CMake] -- The CXX compiler identification is Clang 7.0.1
1> [CMake] -- Check for working C compiler: E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe
1> [CMake] -- Check for working C compiler: E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe -- 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: C:/Program Files/LLVM/bin/clang-cl.exe
1> [CMake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- broken
1> [CMake] CMake Error at E:/VS19/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.13/Modules/CMakeTestCXXCompiler.cmake:45 (message):
1> [CMake] The C++ compiler
1> [CMake]
1> [CMake] "C:/Program Files/LLVM/bin/clang-cl.exe"
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: C:/Users/theha/CMakeBuilds/7c084052-2033-9235-9a50-93f9ca5000be/build/x64-Debug/build/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command:"E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "cmTC_9e38f"
1> [CMake] [1/2] Building CXX object CMakeFiles\cmTC_9e38f.dir\testCXXCompiler.cxx.obj
1> [CMake] FAILED: CMakeFiles/cmTC_9e38f.dir/testCXXCompiler.cxx.obj
1> [CMake] C:\PROGRA~1\LLVM\bin\clang-cl.exe /nologo -TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /JMC /showIncludes /FoCMakeFiles\cmTC_9e38f.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_9e38f.dir\ -c testCXXCompiler.cxx
1> [CMake] clang-cl.exe: error: no such file or directory: '/JMC'
1> [CMake] ninja: build stopped: subcommand failed.
1> [CMake]
1> [CMake]
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:5 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "C:/Users/theha/CMakeBuilds/7c084052-2033-9235-9a50-93f9ca5000be/build/x64-Debug/build/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "C:/Users/theha/CMakeBuilds/7c084052-2033-9235-9a50-93f9ca5000be/build/x64-Debug/build/CMakeFiles/CMakeError.log".
1> [CMake]
1> CMake generation finished.
1> E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\theha\CMakeBuilds\7c084052-2033-9235-9a50-93f9ca5000be\install\x64-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -DCMAKE_C_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -H. -G Ninja -Bbuild -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\theha\projects\sink" returned with exit code: 1
So, how I can fix that? Maybe I'm doing something wrong but I cannot understand what actually? I also see advices with using vcvarsall.bat and set CXX and CXXFLAGS but it isn't help.

There are two problems with your solution:
You are defining a build directory with "-Bbuild", which is different than the one defined in CMakeSettings.json in the "buildRoot" property. This would make Visual Studio misbehave, as e.g. it will look for CMakeCache.txt in the '${buildRoot}', not in '${buildRoot}/build'.
You are passing two definitions of CMAKE_CXX_COMPILER to CMake, one with "cl.exe", another with "clang-cl.exe".
You can solve both problems by passing these values instead:
{
"configurations": [
{
"name": "Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_CXX_COMPILER",
"type": "PATH",
"value": "C:\\Program Files\\LLVM\\bin\\clang-cl.exe"
},
{
"name": "CMAKE_C_COMPILER",
"type": "PATH",
"value": "C:\\Program Files\\LLVM\\bin\\clang-cl.exe"
}
]
}
]
}
Regarding the error related to /JMC unrecognized flag being passed to clang-cl.exe, that flag is not currently supported by clang-cl.exe, so you need to apply this patch to your local CMake installation (located under
VS_INSTALLATION_FOLDER\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake)

Ok, maybe someone will find my solution useful.
How I change my CMakeLists.txt:
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(sink)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Xclang -std=c++17 -Xclang -pedantic")
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}/bin")
file(GLOB SOURCES "${SRC_DIR}/*.cpp" "${SRC_DIR}/*.cc" "${SRC_DIR}/*.c")
file(GLOB HEADERS "${INCLUDE_DIR}/*.h" "${INCLUDE_DIR}/*.hpp")
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
And CMakeSettings.json:
{
"configurations": [
{
"name": "Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DCMAKE_CXX_COMPILER:PATH=\"C:\\Program Files\\LLVM\\bin\\clang-cl.exe\" -DCMAKE_CXX_FLAGS:STRING=\"/DWIN32 /D_WINDOWS /GR /EHsc\" -DCMAKE_CXX_FLAGS_DEBUG:STRING=\"/MDd /Zi /Ob0 /Od /RTC1\"",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
}
]
}
For now all works.

Related

set vcpkg x-buildtrees-root option in manifest or in cmakepresets.json

I've a CMake project that uses vcpkg.json for using vcpkg, and CMakePresets.json for setting the CMake options.
This is the vcpkg.json:
{
"name": "myproj",
"version": "1.0.0",
"dependencies": [
"boost",
"qt"
]
}
This is the CMakePresets.json:
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 1
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default config generator with ninja",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "e:/lib/vcpkg/scripts/buildsystems/vcpkg.cmake",
"VCPKG_DEFAULT_TRIPLET": "x64-windows",
"CMAKE_EXPORT_COMPILE_COMMANDS": "TRUE"
},
"environment": {
}
},
{
"inherits": "default",
"name": "debug",
"displayName": "Debug",
"description": "Debug build.",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"inherits": "default",
"name": "release",
"displayName": "Release",
"description": "Release build.",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "Debug",
"configurePreset": "debug"
},
{
"name": "Release",
"configurePreset": "release"
}
],
"testPresets": [
{
"name": "debugtest",
"configurePreset": "debug",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
]
}
When I open the project folder with Visual Studio 2022, it start to build the vcpkg libraries, and everything goes well, until it builds qtwebengine, that returns me an error:
1> [CMake] Installing 376/432 qtwebengine:x64-windows...
1> [CMake] Building qtwebengine[core,default-features,geolocation,spellchecker,webchannel]:x64-windows...
1> [CMake] -- Using cached pypa-get-pip-38e54e5de07c66e875c11a1ebbdb938854625dd8.tar.gz.
1> [CMake] -- Cleaning sources at E:/lib/vcpkg/buildtrees/qtwebengine/src/8854625dd8-861bd167bd.clean. Use --editable to skip cleaning for the packages you specify.
1> [CMake] -- Extracting source E:/lib/vcpkg/downloads/pypa-get-pip-38e54e5de07c66e875c11a1ebbdb938854625dd8.tar.gz
1> [CMake] -- Using source at E:/lib/vcpkg/buildtrees/qtwebengine/src/8854625dd8-861bd167bd.clean
1> [CMake] -- Setting up python virtual environmnent...
1> [CMake] -- Installing python packages: html5lib
1> [CMake] -- Setting up python virtual environmnent...finished.
1> [CMake] CMake Warning at ports/qtwebengine/portfile.cmake:85 (message):
1> [CMake] Buildtree path 'E:/lib/vcpkg/buildtrees/qtwebengine' is too long.
1> [CMake]
1> [CMake] Consider passing --x-buildtrees-root=<shortpath> to vcpkg!
1> [CMake]
1> [CMake] Trying to use 'E:/lib/vcpkg/buildtrees/qtwebengine/../tmp'
1> [CMake] Call Stack (most recent call first):
1> [CMake] scripts/ports.cmake:147 (include)
1> [CMake]
1> [CMake]
1> [CMake] CMake Error at ports/qtwebengine/portfile.cmake:90 (message):
1> [CMake] Buildtree path is too long. Build will fail! Pass
1> [CMake] --x-buildtrees-root=<shortpath> to vcpkg!
1> [CMake] Call Stack (most recent call first):
1> [CMake] scripts/ports.cmake:147 (include)
1> [CMake] error: building qtwebengine:x64-windows failed with: BUILD_FAILED
1> [CMake] error: Please ensure you're using the latest port files with `git pull` and `vcpkg update`.
Basically I need to set the --x-buildtrees-root=<shortpath> option when building the library with vcpkg. I can do it manually, but how can I set this option in order to be called automatically when I build the dependencies with Visual Studio? How can I update my configuration files?
The variable VCPKG_INSTALL_OPTIONS is meant for passing further options to vcpkg install. So just set it in your preset.

Build failed after change architecture from x64 to x86_64 using cmake preset on windows

I'm building a project using cmake preset in vs2019.
My CMakePresets.json as follows:
{
"name": "windows-x86_64-release",
"displayName": "Windows x86_64 Release",
"description": "Target Windows with the Visual Studio development environment.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"architecture": {
"value": "x64",
"strategy": "external"
},
My windows is 64 bit. The settings above works well.
Because VS is alway 32 bit, so I change architecture value to x86_64, then I get an error when cmake init:
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
1> [CMake] The C compiler
1> [CMake]
1> [CMake] "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/HostX64/x86/cl.exe"
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: D:/code_repo/repo_sun/qrlib/alib/code/build/windows-x86_64-release/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_c3232 && [1/2] Building C object CMakeFiles\cmTC_c3232.dir\testCCompiler.c.obj
1> [CMake] [2/2] Linking C executable cmTC_c3232.exe
1> [CMake] FAILED: cmTC_c3232.exe
1> [CMake] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_c3232.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\HostX64\x86\link.exe /nologo CMakeFiles\cmTC_c3232.dir\testCCompiler.c.obj /out:cmTC_c3232.exe /implib:cmTC_c3232.lib /pdb:cmTC_c3232.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
1> [CMake] RC Pass 1: command "rc /fo CMakeFiles\cmTC_c3232.dir/manifest.res CMakeFiles\cmTC_c3232.dir/manifest.rc" failed (exit code 0) with the following output:
1> [CMake] 系统找不到指定的文件。
1> [CMake] ninja: build stopped: subcommand failed.
Mean while, the follow script works well in cmd prompt:
set build_type=windows-x86_64-release
md build
cd build
cmake .. --preset=%build_type%
cd %build_type%
ninja install
Any idea about that?

ninja: error: build.ninja: bad $-escape (literal $ must be written as $$)

I am getting the following error while compiling SeqAn Framework:
1> [CMake] CMake Error:
1> [CMake] Running
1> [CMake]
1> [CMake] 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe' '-C' 'C:/Users/pc/source/repos/seqan/out/build/x64-Clang-Debug' '-t' 'recompact'
1> [CMake]
1> [CMake] failed with:
1> [CMake]
1> [CMake] ninja: error: build.ninja:152: bad $-escape (literal $ must be written as $$)
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake] CMake Generate step failed. Build files cannot be regenerated correctly.
1> 'C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\pc\Source\Repos\seqan\out\install\x64-Clang-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\pc\Source\Repos\seqan" 2>&1"' execution failed with error: ''C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\pc\Source\Repos\seqan\out\install\x64-Clang-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\pc\Source\Repos\seqan" 2>&1"' returned with exit code: 1'.
The following is my CMakeSettings_schema.json file:
{
"configurations": [
{
"name": "x64-Clang-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64_x64" ],
"variables": []
}
]
}
The following is the content of my build.ninja file from line # 152:
COMMAND = cmd.exe /C "cd /D C:\Users\pc\source\repos\seqan\out\build\x64-Clang-Debug && C:\Users\pc\source\repos\seqan\out\build\x64-Clang-Debug\bin\$(ConfigurationName)\alf.exe --write-ctd C:/Users/pc/source/repos/seqan/out/build/x64-Clang-Debug/workflow_plugin_dir/descriptors/alf.ctd"
What can I do to fix this?

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

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