Is there a way to run cmake using intel compilers? - cmake

I was trying to run a program using intel compilers but while compiling the program it showed error.
It was was due to cmake.
cmake -G "Visual Studio 17 2022" -A x64 -T "Intel(R) oneAPI DPC++ Compiler" ..
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.25099.
CMake Error at CMakeLists.txt:81 (project):
Failed to run MSBuild command:
C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
to get the value of VCTargetsPath:
MSBuild version 17.3.1+2badb37d1 for .NET Framework
Build started 9/2/2022 10:51:43 AM.
Project "C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(460,5): error MSB8020: The build tools for Intel(R) oneAPI DPC++ Compiler (Platform Toolset = 'Intel(R) oneAPI DPC++ Compiler') cannot be found.
To build using the Intel(R) oneAPI DPC++ Compiler build tools, please install Intel(R) oneAPI DPC++ Compiler build tools.
Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj]
Done Building Project "C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj" (default targets) -- FAILED
"C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(460,5): error MSB8020: The build tools for Intel(R) oneAPI DPC++ Compiler (Platform Toolset = 'Intel(R) oneAPI DPC++ Compiler') cannot be found. To build using the Intel(R) oneAPI DPC++ Compiler build tools,
please install Intel(R) oneAPI DPC++ Compiler build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\mtc\source\repos\onednn\build\CMakeFiles\3.23.1\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.15
Exit code: 1

Ninja is the only CMake generator for Windows that works with the oneAPI DPC++ Compiler.
Please adhere to the instructions in the following link if you wish to utilise the Intel oneAPI DPC++ compiler:
https://oneapi-src.github.io/oneDNN/dev_guide_build.html#id1
To use the Intel NextGen Compiler, could you please use the below command:
cmake -G ""Visual Studio 17 2022"" -T ""Intel C++ Compiler 2022"" ...

There are a couple things that might be causing your problem.
Make sure that the compiler is loaded in your current command environment. For the intel compiler this is usually C:\Program Files (x86)\Intel\oneAPI\setvars.bat.
Make sure that the installed version of CMake is newer than the toolset that you are trying to use. Specifically, CMake version > 3.22.2 if you are using intel 2022.
Your CMakeLists.txt is not posted, but according to Intel's documentation, you need to add find_package(IntelDPCPP REQUIRED).
Also, once you are able to get your target to build, I recommend that you switch to using a CMakePresets.json file to configure your CMake build. I have one that looks like this:
In this preset file, the cache variable INTEL_COMPILER is used to turn on/off specific intel compiler flags in my CMakeLists.txt such as /fp:precise.
CMakePresets.json
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 2
},
"configurePresets": [
{
"name": "base",
"hidden": true,
"binaryDir": "${sourceDir}/_build/${presetName}"
},
{
"name": "Windows",
"hidden": true,
"inherits": [
"base"
],
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": "Windows"
}
}
},
{
"name": "Debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "Release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "Intel - IDE",
"hidden": true,
"toolset": "Intel C++ Compiler 2022",
"cacheVariables": {
"INTEL_COMPILER": "ON"
}
},
{
"name": "Visual Studio 2022 - Intel",
"displayName": "Visual Studio 2022 using Intel compiler",
"inherits": [
"Windows",
"Intel - IDE"
],
"generator": "Visual Studio 17 2022"
}
],
"buildPresets": [
{
"name": "Windows",
"hidden": true,
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": "Windows"
}
}
},
{
"name": "Visual Studio 2022 - Intel",
"displayName": "Visual Studio 2022 using Intel compiler",
"inherits": [
"Windows"
],
"configurePreset": "Visual Studio 2022 - Intel"
}
]
}

Related

How to set working directory in CMake Visual Studio 2022?

I have a problem with setting the working directory with CMake (Visual Studio 2022).
I'm currently working on a project (some OpenGL learning stuff) and decided to switch from typical VS solution-project to CMake project. I need to load some files (.obj, shaders) from Resources folder (LearnOpenGL/Resources) but I see that paths in c++ code are relative to LearnOpenGL/out/build/x64-Debug/.
I've already tried :
setting property VS_DEBUGGER_WORKING_DIRECTORY like (also without trailing slash):
set_property(TARGET LearnOpenGL PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/")
adding "currentDir" or "cwd" to CMakeSettings.json like:
"currentDir": "${projectDir}"
"cwd": "${projectDir}"
but there is no effect of any of those changes. Does anyone have some ideas what else can I do? Or maybe I'm doing here something wrong?
You can add currentDir property to your launch.vs.json which will typically be in ${workspaceRoot}/.vs directory.
To access it from Visual Studio 2022 CMake project you can follow these steps:
In the solution explorer click on Switch between solutions and available views button:
Then click on CMake Targets View
Now right click on your project and press Add Debug Configuration in context menu
This will open launch.vs.json file where you can edit currentDir property, for example - my project 02_texture.exe should start in root directory so my launch config looks like this:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "",
"name": "CMakeLists.txt"
},
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "02_texture.exe (02_texture\\02_texture.exe)",
"name": "02_texture.exe (02_texture\\02_texture.exe)",
"currentDir": "${workspaceRoot}"
}
]
}

Using CMake compile flags in preset for non-external projects only

I am adding a few external projects to my application. For instance, gtest.
In my CMake preset I set the following...
{
"version": 4,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"displayName": "debug",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/W4 /Wall /EHsc",
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_STANDARD_REQUIRED": "YES",
"CMAKE_CXX_EXTENSIONS": "OFF"
}
}
]
}
When I build with the above preset, I get a bunch of warnings from building gtest. I only would like to see the warnings coming from my internal build, not external projects.
In my root CMakeLists.txt I have the following...
cmake_minimum_required(VERSION 3.23.0)
project(ProjectName LANGUAGES C CXX CUDA)
include(CTest)
add_subdirectory(external) # This has a bunch of external dependencies.
add_subdirectory(src) # This builds a normal executable.
add_subdirectory(tests) # This has various unit tests.
Is there a way for me to make sure the flags are only used for my personal project, and nothing external?
I have looked into "https://cmake.org/cmake/help/v3.23/manual/cmake-presets.7.html" but nothing stood out to me.
Thank you
If you want to localize your settings you should not use globals. Use target_compile_options and other target_* commands instead of setting CMAKE_CXX_* global (cache) variables in your preset.
Alternatively, you can choose not to build external projects as part of your local project build. With that organization you wouldn't have the problem in the first place.

Can't link to bullet physics library - LNK2019,LNK2001

I have built bullet3-3.08 on Windows using cmake (commands have been executed from the build folder created in the bullet3-3.08 directory):
cmake -G "Visual Studio 15 2017" -A x64 -D "CMAKE_INSTALL_PREFIX:PATH=C:/MyLibs/bullet3-3.08" -D "USE_MSVC_RUNTIME_LIBRARY_DLL=ON" -D "INSTALL_LIBS=ON" ..
cmake --build . --config Release --parallel 8 --target install
I have an application which uses MD/MDd runtime library so I have built Bullet with the following option: USE_MSVC_RUNTIME_LIBRARY_DLL=ON. Bullet is built as a static library by default. I use Visual Studio 2017 and build my application using cmake. When I link to Bullet I get many linker errors (LNK2019, LNK2001), for example:
error LNK2019: unresolved external symbol "public: __cdecl btCollisionDispatcher::btCollisionDispatcher(class btCollisionConfiguration *)" (??0btCollisionDispatcher##QEAA#PEAVbtCollisionConfiguration###Z) referenced in function main
error LNK2001: unresolved external symbol "public: virtual void __cdecl btCollisionShape::getBoundingSphere(class btVector3 &,float &)const " (?getBoundingSphere#btCollisionShape##UEBAXAEAVbtVector3##AEAM#Z)
I use direct library paths in CMakeLists.txt:
target_link_libraries(${executableName} "C:/MyLibs/bullet3-3.08/lib/Bullet3Collision.lib"
"C:/MyLibs/bullet3-3.08/lib/Bullet3Dynamics.lib"
"C:/MyLibs/bullet3-3.08/lib/LinearMath.lib")
Here is CMakeSettings.json:
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}
What is wrong ?
As Bullet provides a BulletConfig.cmake file it is quite simple to link against Bullet.
First you need to install Bullet (if not done so) and add -DCMAKE_PREFIX_PATH=C:/MyLibs/bullet3-3.08 (or the appropriate installation directory) to your cmake command line.
Then in your CMakeLists.txt file you need to add
find_package(Bullet REQUIRED)
# your add_executable call follows here
add_executable(${executableName} .......)
target_compile_definitions(${executableName} PRIVATE ${BULLET_DEFINITIONS})
target_include_directories(${executableName} PRIVATE ${BULLET_INCLUDE_DIRS})
target_link_libraries(${executableName} PRIVATE ${BULLET_LIBRARIES})
This should be the steps necessary to link to Bullet.

ASPNET Core pre-RC2 dependency ambiguity

I am using:
.NET Command Line Tools (1.0.0-rc2-002439)
Product Information:
Version: 1.0.0-rc2-002439
Commit Sha: ef0c3b2cee
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
RID: win10-x64
and getting:
error CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)' and 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)'
I suspect there are multiple OptionsModel assemblies (different versions) included on "dotnet restore".
The proof may be here:
The second suggestion with different parameter name:
Project.lock.json file has few interesting lines ("Infrastructure" is a referenced assembly):
"Infrastructure/1.0.0": {
"type": "project",
"framework": ".NETFramework,Version=v4.6.1",
"dependencies": {
"Domain": "1.0.0",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.OptionsModel": "1.0.0",
"Newtonsoft.Json": "8.0.3",
"WindowsAzure.Storage": "6.2.1"
},
"compile": {
"net461/Infrastructure.dll": {}
},
"runtime": {
"net461/Infrastructure.dll": {}
}
}
while the web application uses Microsoft.Extensions.OptionsModel/1.0.0-rc2-15914
Here is the configuration section of Infrastructure assembly:
"dependencies": {
"Domain": "1.0.0-*",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0-*",
"Microsoft.Extensions.OptionsModel": "1.0.0-*",
"Newtonsoft.Json": "8.0.3",
"WindowsAzure.Storage": "6.2.1-*"
}
The question is: why different versions (1.0.0 and 1.0.0-rc2-15914) are chosen while executing "dotnet restore"?
UPDATE: I tried changing project.json of Infrastructure project to "Microsoft.Extensions.OptionsModel": "1.0.0-rc2-15914" but I am still can't compile because of ambiguity displayed in screenshots. Are any assemblies cached somewhere on my computer?
The solution is:
Microsoft.Extensions.Options instead of Microsoft.Extensions.OptionsModel package had to be used in a referenced project.

VS2015 ASP.NET 5 beta7 dependency could not be resolved

This is a follow-up to this question. I started with an Empty ASP.NET project in VS2015 community, tried to add a couple packages based on a tutorial, and haven't gotten it to actually work yet. The initial problem in the linked question was due to some project dependencies using beta5 and some using beta7. Matching those up solved that, but now I get this error when I try to run the project in IIS Express:
Could not load file or assembly 'Microsoft.Dnx.Host.Clr' or one of its dependencies.
I think the problem is still version related--like the previous web.config assembly reference issues--but I don't know how to deal with it yet. I tried modifying global.json based on a similar issue I found on GitHub, but now it doesn't build. It looks like it can't find the newer version of the CLR I guess. From the Error List in VS2015:
The dependency Microsoft.AspNet.Mvc >= 6.0.0-beta7 could not be resolved.
The dependency Microsoft.AspNet.Server.IIS >= 1.0.0-beta7 could not be resolved.
The dependency Microsoft.AspNet.Server.WebListener >= 1.0.0-beta7 could not be resolved.
global.json:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta7",
"runtime": "clr",
"architecture": "x86"
}
}
My project's References tree has yellow error indicators but looking in the NuGet package manager for my project doesn't show any upgrades (or anything installed at all, as far as I can tell).
dnvm list:
1.0.0-beta5 clr x64
1.0.0-beta5 clr x86
1.0.0-beta5 coreclr x64
1.0.0-beta5 coreclr x86
* 1.0.0-beta7 clr x86 default
1.0.0-beta8-15585 clr x86
dnu list:
Microsoft .NET Development Utility CLR-x86-1.0.0-beta7-15532
I've restart VS but that didn't help. Changing back to beta5 in my global.json makes it compule successfully but then I get the IIS error.
project.json:
{
"webroot": "public",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"public",
"node_modules",
"bower_components"
]
}
package.json:
{
"version": "1.0.0",
"name": "ASP.NET",
"private": true,
"devDependencies": {
"angular2": "2.0.0-alpha.36",
"gulp": "3.9.0"
}
}
"To use ASP.NET 5 beta7 with Visual Studio 2015, you will need to download and install the beta7 version (14.0.60831.0) of ASP.NET and Web Tools 2015."
http://go.microsoft.com/fwlink/?LinkId=623894
https://github.com/aspnet/Home/releases