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

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.

Related

cmake . -B build - Compiling Neural Graphic Primitives

I trying compile NGP but after cmake . -B build I get this lines:
I've installed
Visual Studio 2019
CUDA Toolkit 11.6
CMake 3.22
Python 3.10
Optix 7.6
C:\NGP\instant-ngp>cmake . -B build
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.29.30147.0
-- The CXX compiler identification is MSVC 19.29.30147.0
-- The CUDA compiler identification is NVIDIA 11.6.124
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/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/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- **Obtained CUDA architectures automatically from installed GPUs**
**CMake Error: The source directory "SOURCES/CMakeFiles/CMakeTmp" does not exist.**
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error at dependencies/tiny-cuda-nn/CMakeLists.txt:107 (try_run):
Failed to configure test project build system.
Call Stack (most recent call first):
dependencies/tiny-cuda-nn/CMakeLists.txt:146 (TCNN_AUTODETECT_CUDA_ARCHITECTURES)
-- Configuring incomplete, errors occurred!
See also "C:/NGP/instant-ngp/build/CMakeFiles/CMakeOutput.log".
I am not coder I just want to try NERF. It ss possible download somewhere compiled NGP or it doesn't work that way?
EDIT: Noticed that OP is using the -S flag implicitly the issue seems to be elsewhere, hence the updated answer:
UPDATED ANSWER
Please bare in mind that with the limited information at my disposal. This is again only a wild guess, based on what I tried.
After re-examining the output of CMake I've noticed that the issue is within one of the dependencies i.e.
CMake Error at dependencies/tiny-cuda-nn/CMakeLists.txt:107 (try_run):
I was not able to completely replicate the problem, however I do believe I know how to debug these issues. My wild guess here is that either:
The individual dependencies were incorrectly pulled or
The CMake files were poorly generated due to some issue and you didn't clean them.
I would recommend trying the following:
Delete the build folder, and run cmake -S. -Bbuild again. And if that fails you can try the second option.
Remove the git repository (folder called instant-ngp) and clone it again using exactly this command:
git clone --recursive https://github.com/nvlabs/instant-ngp
Please note that the --recursive option is very important due to the fact that you need to pull the dependant repositories as well.
Now if all of that fails. You still have one more option and that is to go to the folder dependencies/tiny-cuda-nn/ and generate the CMake files yourself, however I do not recommend that due to the fact that if you have limited experience you may not know what exactly to do.
I've also checked the variables you wanted to set, and you may do that by running this in Powershell
$Env:CMAKE_CUDA_ARCHITECTURES=YOUR_VALUE_HERE (in my case it is 75 because I have a RTX2080). However bare in mind that
You shouldn't need it, because the architecture is discovered for you
You need to delete the build folder in order to clean up the cached CMake files
Hope it helps!

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.

Can't tell cmake to use vcpkg for library link

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 ?

Conan CMake and Embarcadero integration

I am trying to make Conan with CMake run with Embarcadero Tokyo 10.2.3 compiler. I can do CMake with Embarcadero following it's tutorial. But issue seems to happen with Conan. So I do the conan install. Then I do cmake .. -DCMAKE_CXX_COMPILER="bcc32c.exe" -DCMAKE_C_COMPILER="bcc32c.exe" -DCMAKE_VERBOSE_MAKEFILE=1 -G Ninja. I get the error
Incorrect 'Visual Studio'. Toolset specifies compiler as 'MSVC' but CMake
detected 'Embarcadero'
The default conan profile shows compiler=Visual Studio which I believe is where the issue originates from. But dont know how to change it to Embarcadero (does not recognize) or if changing the default profile is the way to go. My CMakeLists.txt file looks like this (mostly default)
project(Timer)
cmake_minimum_required(VERSION 3.11)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(timer timer.cpp)
target_link_libraries(timer ${CONAN_LIBS})
The full cmake output is below:
-- The C compiler identification is Embarcadero 7.30.36015
-- The CXX compiler identification is Embarcadero 7.30.36015
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Current conanbuildinfo.cmake directory: C:/Mathew Joy/Source/mytimer/build
CMake Error at build/conanbuildinfo.cmake:579 (message):
**Incorrect 'Visual Studio'. Toolset specifies compiler as 'MSVC' but CMake
detected 'Embarcadero'**
Call Stack (most recent call first):
build/conanbuildinfo.cmake:237 (conan_check_compiler)
CMakeLists.txt:5 (conan_basic_setup)
You need to customize the default settings.yml file which can be found in <userhome>/.conan/settings.yml
This file has defined some of the most popular compilers, you might add something like:
compiler:
sun-cc:
...
gcc:
version: ["4.1", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9",
Visual Studio:
runtime: [MD, MT, MTd, MDd]
version: ["8", "9", "10", "11", "12", "14", "15"]
...
Embarcadero:
version: ["V1", "V2"...]
This file can be shared and synchronized with the team and used in CI machines with the conan config install command.
Then you can add the values for convenience to your default profile, instead of the Visual Studio values.
It is likely that most of the logic that the built-in build helpers, like CMake are providing, would be limited for this compiler, as it doesn't recognize it. You can run your logic to call the build system directly if that is the case:
def build(self):
self.run("cmake . -G ....")
self.run("cmake --build . --config Release")
If you want to correctly build and create packages for different configurations, then you should parameterize the above using the settings and options, as necessary.
All of this assume that you will be creating and depending on your own packages, as the existing packages in the public conan-center repository will be for the popular compilers, so the binaries will be incompatible, and the recipes most likely won't implement building from sources with Embarcadero.
Visual Studio 2019 C++ is much better than Embarcadero. I have used both Tokyo and the Rio version, and there is no comparison. In addition you can download the Managed C++, which is called C++ CLR (not CLI), which will allow you to integrate .NET forms/consoles with native C++ applications.
Visual Studio 2019 C++ works well when creating Xamarin IOS libraries, which can easily be integrated with C# for Xamarin Forms. Xamarin Forms works for both Android and IOS (Xamarin).
In July 2019, Embarcadero finally added 64 bit Mac OS operating system, and MAC has been 64 bit since 2008.
That should tell you something right there.