Visual Studio 2017 comes with CMake support and the integration with CMake is really nice. You just have to simply right click in the folder that CMakeLists.txt resides and then click on the new entry Open in Visual Studio in the context menu. Then Visual Studio automatically calls CMake and creates the project.
The issue is that Visual Studio uses a folder under %HOME%\AppData\Local\ to build the project and it is not obvious to find the path to this folder. For example for my current project it is -DCMAKE_INSTALL_PREFIX:PATH="%HOME%\AppData\Local\CMakeBuild\f8a8174e-5536-413f-8a74-caa4afced478\build\install". This means whenever I start my project with Visual Studio it fails, I have to manually copy paste the path into a terminal and then run conan install /path/to/recipe/ inside the build folder created by Visual Studio.
I am aware of the conan-cmake project but I prefer to have it integrated with conan. Some of the machines that I work on do not have network access, and I also do not want the cmake-conan repo to be part of the project. I already have too many CMake files and adding new files will make it even more confusing.
Is there a reason it is not already integrated with Conan in some way?
But how would it be integrated? It is just a cmake script, there is no conan command involved or anything. It is something that is called from cmake. Any suggestion about the UI/UX regarding this integration?
Hi @AliAskar you can try 2 different approaches:
conan install command in a local known directory and then Visual Studio will perform the real build in a different crazy lost directory.@lasote The second approach is interesting. I will look into it.
I guess you could do something like this in your CMakeLists.txt, before calling "include". The following code will cause the configuration step to fail and print the "Conan install" command that you can copy paste to a terminal.
if(NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(FATAL_ERROR "Conan build info not generated. Please run:\n"
"\tconan install --cwd ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}")
endif()
for Visual Studio 2017 + CMake + conan, I have the following script which install conan dependencies for all configurations:
REM workaround for conan which needs VS150COMNTOOLS environment variable
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property InstallationPath > .wswhere
set /p VS150COMNTOOLS= <.wswhere
set VS150COMNTOOLS=%VS150COMNTOOLS%\Common7\Tools\
del /f .wswhere
mkdir vs2017
cd vs2017
mkdir x64_debug
cd x64_debug
call conan install ..\..\.. -g cmake -s arch=x86_64 -s build_type=Debug -s compiler="Visual Studio" -s compiler.version=15 -s compiler.runtime=MDd --build missing --update
cd ..
mkdir x64_release
cd x64_release
call conan install ..\..\.. -g cmake -s arch=x86_64 -s build_type=Release -s compiler="Visual Studio" -s compiler.version=15 -s compiler.runtime=MD --build missing --update
cd ..
mkdir x86_debug
cd x86_debug
call conan install ..\..\.. -g cmake -s arch=x86 -s build_type=Debug -s compiler="Visual Studio" -s compiler.version=15 -s compiler.runtime=MDd --build missing --update
cd ..
mkdir x86_release
cd x86_release
call conan install ..\..\.. -g cmake -s arch=x86 -s build_type=Release -s compiler="Visual Studio" -s compiler.version=15 -s compiler.runtime=MD --build missing --update
cd ..
cd ..
and the following CMakeSettings.json file:
{
// See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
"configurations": [
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x86" ],
"buildRoot": "${projectDir}\\build\\vs2017\\x86_debug",
"cmakeCommandArgs": "-DBUILD_TESTING=ON",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x86" ],
"buildRoot": "${projectDir}\\build\\vs2017\\x86_release",
"cmakeCommandArgs": "-DBUILD_TESTING=ON",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64" ],
"buildRoot": "${projectDir}\\build\\vs2017\\x64_debug",
"cmakeCommandArgs": "-DBUILD_TESTING=ON",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64" ],
"buildRoot": "${projectDir}\\build\\vs2017\\x64_release",
"cmakeCommandArgs": "-DBUILD_TESTING=ON",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}
Most helpful comment
for Visual Studio 2017 + CMake + conan, I have the following script which install conan dependencies for all configurations:
and the following CMakeSettings.json file: