Can't tell cmake to use vcpkg for library link - cmake

I'm using a Cmake for a cross-platform project that use glibmm. Under Linux, the project build successfully without any problem (and works fine when executed).
But with Windows 10, Visual Studio 2019 (pro), I can't find how to build the project. I installed glibmm with vcpkg ("vcpkg install glibmm:x64-windows" and "vcpkg install glibmm:x86-windows")
I add to my cmake command the parameter -DCMAKE_TOOLCHAIN_FILE=D:\vcpkg\scripts\buildsystems\vcpkg.cmake
In the main CMakeLists.txt file, the following lines do not do their job.
find_package(PkgConfig REQUIRED)
pkg_check_modules(glibmm REQUIRED glibmm-2.4)
cmake -S D:\MachDrivetoolkit\libMachDrive -DCMAKE_TOOLCHAIN_FILE=D:\vcpkg\scripts\buildsystems\vcpkg.cmake -DPKG_CONFIG_EXECUTABLE:STRING="D:\vcpkg\downloads\tools\msys2\c809757c94447846\mingw32\bin\pkg-config.exe" -B D:\MachDrivetoolkit\libMachDriveVS
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- The CXX compiler identification is MSVC 19.28.29334.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: D:\vcpkg\downloads\tools\msys2\c809757c94447846\mingw32\bin\pkg-config.exe (found version "0.29.2")
-- Checking for module 'glibmm-2.4'
-- No package 'glibmm-2.4' found
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.18/Modules/FindPkgConfig.cmake:545 (message):
A required package was not found
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.18/Modules/FindPkgConfig.cmake:733 (_pkg_check_modules_internal)
libipc/CMakeLists.txt:37 (pkg_check_modules)
Then I modify the name of the glibmm library in the script to match the name of the installed file
find_package(PkgConfig REQUIRED)
pkg_check_modules(glibmm REQUIRED glibmm)
but it fail the same.
What parameters or what instruction should I use to link glibmm to my project ?

Related

cmake and clang++ windows build instead of MSVC

I am trying to create a build environment using cmake and i have both MSVC and clang installed on my system.
When I run cmake with the default settings it detectts MSVC as my cxx compiler.
However, I would like to use clang++ instead.
I tried specifying clang like this: cmake -DCMAKE_CXX_COMPILER=clang++
but even after that it still uses MSVC..
How can I tell it to use clang instead?
You should provide the complete path of the clang compiler. E.g.,
cmake -DCMAKE_CXX_COMPILER=/path/to/clang++ -DCMAKE_C_COMPILER=/path/to/clang
First of all you need to ensure that CLANG is visible through a regular command prompt window. If not then you need to put the CLANG installed directory path to your PATH environment variable.
In my case I had clang-cl installed through Visual Studio but it was still not visible through a regular command prompt window.
Regular command prompt window output:
>clang-cl -v
'clang++' is not recognized as an internal or external command,
operable program or batch file.
Developer command prompt window output:
>clang-cl -v
clang version 12.0.0
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\Llvm\bin
Moreover, I simply use the following command: cmake -T ClangCL to generate the project on a Windows 10 PC with Visual Studio 2019 Professional Edition.
This is the output I get:
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is Clang 12.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 12.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
I have tested the same on another Windows 10 PC with Visual Studio 2022 Community Edition and it works fine too.

How to use cmake on windows with vs2019 and custom installed llvm?

I found someone mentioned to use such command line to use cmake with vs2019 and llvm toolset:
cmake -G "Visual Studio 2019" -T ClangCL
However, this would use the llvm version, which is 11.0 for now, was installed by the visual studio instanller.
I want to use a new version, thus 12.0, of llvm which I already installed somewhere else but I don't know how to make cmake and vs to use that.
UPDATE:
What I tried to set the compiler via command line:
E:\my_proj>cmake -G "Visual Studio 16 2019" -A x64 -T "ClangCL" -DCMAKE_C_COMPILER="C:\Program Files\LLVM\bin\clang.exe" -DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\clang++.exe" .
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is Clang 11.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 11.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
As you could see the cmake picked the clang from the vs installed location and ignored the command line.
As described below, setting CMAKE flags explicitly has no effect when using VS generator. Thus choosing the default compiler installed by Visual Studio installer.
The VS generator produces .vcxproj files and uses MSBuild to actually
drive the build. The values of CMAKE_{C,CXX}_COMPILER are computed
automatically from the compiler MSBuild chooses so setting them has no
effect.

Qt-Cretor + CMake insists on using MSVC when I want to use MinGW

I am trying to build a CMake project with MinGW. I have installed MinGW 8.1 through the Qt installer. The CMakeList is unchanged from how Qt Creator created it when creating the project.
When running CMake, I can see how Qt Creator passes the compiler and linker's paths to CMake and how CMake completely ignores them.
Führe C:\Program Files\CMake\bin\cmake.exe -S [snip] -B [snip] "-DCMAKE_BUILD_TYPE:String=Debug" "-DQT_QMAKE_EXECUTABLE:STRING=C:/Qt/5.15.1/mingw81_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:STRING=C:/Qt/5.15.1/mingw81_64" "-DCMAKE_C_COMPILER:STRING=C:/Qt/Tools/mingw810_64/bin/gcc.exe" "-DCMAKE_CXX_COMPILER:STRING=C:/Qt/Tools/mingw810_64/bin/g++.exe" in [snip] aus.
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- The CXX compiler identification is MSVC 19.24.28314.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_BUILD_TYPE
CMAKE_C_COMPILER
QT_QMAKE_EXECUTABLE
Here I am using a system install of CMake, but the output is unchanged when using the CMake installed with Qt Creator. The CMake generator for the selected kit is set to MinGW Makefiles in the Qt Creator settings. Running CMake manually, without Qt Creator, allows me to configure the project. (although it still doesn't compile because of a linker error, that I expect to be independent of this problem)
It seems there is a caching issue. The caching is done by CMake (CMakeCache.txt) and by QtCreator (CMakeLists.txt.user) itself.
Maybe this helps:
Close QtCreator (by closing QtCreator the CMakeLists.txt.user file is saved or generated if the file don't exist)
delete QtCreator's CMakeLists.txt.user
the build folder
Open the project again and select the desired kit.

CMake Error at cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):Could NOT find MPI_C (missing: MPI_C_LIBRARIES)

I have a project .When I want to configure it in CMAKE3.9.6 with Visual Studio 2010 and support of Intel Parallel Studio 2015 with this command in command line
:
cmake -G "Visual Studio 10"
I get this error:
CMake Error at cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find MPI_C (missing: MPI_C_LIBRARIES)
Call Stack (most recent call first):
cmake/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindMPI.cmake:615 (find_package_handle_standard_args)
CMakeLists.txt:113 (FIND_PACKAGE)
Configuring incomplete, errors occurred!
All the output is as:
The Fortran compiler identification is Intel 15.0.2.20150121
The C compiler identification is MSVC 16.0.30319.1
The CXX compiler identification is MSVC 16.0.30319.1
Check for working Fortran compiler: C:/Program Files (x86)/Intel/Composer XE 2015/bin/ia32/ifort.exe
Check for working Fortran compiler: C:/Program Files (x86)/Intel/Composer XE 2015/bin/ia32/ifort.exe — works
Detecting Fortran compiler ABI info
Detecting Fortran compiler ABI info - done
Determine Intel Fortran Compiler Implicit Link Path
Determine Intel Fortran Compiler Implicit Link Path — done
Checking whether C:/Program Files (x86)/Intel/Composer XE 2015/bin/ia32/ifort.exe supports Fortran 90
Checking whether C:/Program Files (x86)/Intel/Composer XE 2015/bin/ia32/ifort.exe supports Fortran 90 — yes
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe — works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe — works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Deprecation Warning at CMakeLists.txt:47 (CMAKE_POLICY):
The OLD behavior for policy CMP0022 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Error at cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find MPI_C (missing: MPI_C_LIBRARIES)
Call Stack (most recent call first):
cmake/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindMPI.cmake:615 (find_package_handle_standard_args)
CMakeLists.txt:113 (FIND_PACKAGE)
Configuring incomplete, errors occurred!
See also "F:/FreshElmerForCmake396/elmerfem/CMakeFiles/CMakeOutput.log".
Fortran Compiler and Visual Studio works but I think there is a mistake in CMAKE so it could not find some internally files or correct PATH.I download binary MSI version of CMAKE. I used cmake-gui the error was same.so what should I do?
When CMake's dependency finding mechanism fails to automatically find dependency X (MPI in your case), and you know you have X available, the correct procedure is to tell CMake where to find X, or how to find it. Use either the CMake GUI or ccmake to set the appropriate variable(s).
In your case, the documentation for the FindMPI module indicates setting MPI_C_COMPILER to point to the appropriate MPI compiler wrapper could be enough for the dependency finder to catch on.

Errors when building TensorFlow with CMake on Windows 10

I am attempting a TensorFlow CMake build on Windows, but I'm running into problems.
First, I run
C:\work\tensorflow\tensorflow\contrib\cmake\build>cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release ^
More? -DSWIG_EXECUTABLE=C:/Program1/swigwin-3.0.12/swig.exe ^
More? -DPYTHON_EXECUTABLE=C:/Python3.5/python.exe ^
More? -DPYTHON_LIBRARIES=C:/Python3.5/libs/python35.lib ^
More? -Dtensorflow_ENABLE_GPU=ON ^
More? -DCUDNN_HOME="C:\Program1\cudnn\cuda"
and get the output
-- Building for: Visual Studio 14 2015
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED
-- Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED - Failed
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0 (found suitable version "8.0", minimum required is "8.0")
-- Found PythonInterp: C:/Python3.5/python.exe (found version "3.5")
-- Found PythonLibs: C:/Python3.5/libs/python35.lib (found version "3.5.0")
-- Found SWIG: C:/Program1/swigwin-3.0.12/swig.exe (found version "3.0.12")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/work/tensorflow/tensorflow/contrib/cmake/build
The only troubling line here is -- Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED - Failed, which I don't really know what it means or whether it's a serious problem. (Is it?)
Second, I run
MSBuild /p:Configuration=Release tf_tutorials_example_trainer.vcxproj
and this gives me several errors:
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_tutorials_example_trainer.vcxproj" (default target) (1) ->
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj" (default target) (90) ->
(CustomBuild target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_tutorials_example_trainer.vcxproj" (default target) (1) ->
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj" (default target) (91) ->
(ClCompile target) ->
c:\work\tensorflow\tensorflow\core\kernels\cuda_solvers.h(24): fatal error C1083: Cannot open include file: 'cuda/include/cusolverDn.h': No such file or directory (compiling source file C:\work\tensorflow\tensorflow\core\kernels\cholesky_op.cc) [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj]
c:\work\tensorflow\tensorflow\core\kernels\cuda_solvers.h(24): fatal error C1083: Cannot open include file: 'cuda/include/cusolverDn.h': No such file or directory (compiling source file C:\work\tensorflow\tensorflow\core\kernels\cuda_solvers.cc) [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj]
c:\work\tensorflow\tensorflow\contrib\cmake\build\external\eigen_archive\eigen\src\core\coreevaluators.h(1052): fatal error C1060: compiler is out of heap space (compiling source file C:\work\tensorflow\tensorflow\core\kernels\svd_op_float.cc) [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj]
696 Warning(s)
4 Error(s)
I don't know relative to which folder MSBuild is looking for cuda/include/cusolverDn.h. I don't have any folder called cuda in c:\work\tensorflow\tensorflow\core\kernels, and no file named cusolverDn.h exists anywhere in the tensorflow repository. (I do have the file cusolverDn.h in my CUDA install directory, though.) So,
What can I do to make MSBuild find cusolverDn.h? And what can I do to prevent the compiler from running out of heap space?
In a previous attempt to run the last command I also received the message
nvcc fatal : Microsoft Visual Studio configuration file 'vcvars64.bat' could not be found for installation at 'C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/../..'
Some recommend renaming a folder and a file in that folder. I can't really verify that this works right now since the problem temporarily seems to have disappeared (maybe masked by the "compiler is out of heap space" problem, which I didn't have before...).
Is renaming this file and this folder the correct solution?
As per tensorflow instructions check the following:
you must be running a 64 bit enabled Command Prompt for Visual Studio; you should run your msbuild.exe commands from such a prompt;
install CUDNN's Nvidia zio file and append its /bin/ directory to your PATH environment variable, it should contains two entries similar to the following:
D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
D:\YOURCUDNNPATH\cuda\bin
check whether both git and cmake command are available in the PATH; check whether you could run those commands from your prompt;