cmake -H to generate build files for CMake project? - visual-studio-code

I recently observed that the CMake Tools Extension in VS Code runs this command to generate the build file for a project I'm working on:
/usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H/home/tirthankar/projects/physicc/Light/Editor -B/home/tirthankar/projects/physicc/Light/build -G Ninja
The part I am confused about is the -H/home/tirthankar/projects/physicc/Light/Editor part. I searched the CMake Docs for this behavior, but all I could find for the -H was this:
CMake Docs saying that -H is for printing the help docs to the terminal
So the question is, what does -H do in CMake? Is it a standard feature? Is it a deprecated feature? Did the CMake Tools Extension make a mistake?
For reference, here is the entire output:
[kit] Successfully loaded 3 kits from /home/tirthankar/.local/share/CMakeTools/cmake-tools-kits.json
[main] Configuring folder: Light
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H/home/tirthankar/projects/physicc/Light/Editor -B/home/tirthankar/projects/physicc/Light/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 10.3.0
[cmake] -- The CXX compiler identification is GNU 10.3.0
[cmake] -- Check for working C compiler: /usr/bin/cc
[cmake] -- Check for working C compiler: /usr/bin/cc -- works
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Check for working CXX compiler: /usr/bin/c++
[cmake] -- Check for working CXX compiler: /usr/bin/c++ -- works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - found
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
[cmake] -- Looking for pthread_create in pthreads
[cmake] -- Looking for pthread_create in pthreads - not found
[cmake] -- Looking for pthread_create in pthread
[cmake] -- Looking for pthread_create in pthread - found
[cmake] -- Found Threads: TRUE
[cmake] -- Using X11 for window creation
[cmake] -- Found X11: /usr/include
[cmake] -- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
[cmake] -- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
[cmake] -- Looking for gethostbyname
[cmake] -- Looking for gethostbyname - found
[cmake] -- Looking for connect
[cmake] -- Looking for connect - found
[cmake] -- Looking for remove
[cmake] -- Looking for remove - found
[cmake] -- Looking for shmat
[cmake] -- Looking for shmat - found
[cmake] -- Looking for IceConnectionNumber in ICE
[cmake] -- Looking for IceConnectionNumber in ICE - found
[cmake] -- Build spdlog: 1.8.5
[cmake] -- Build type: Debug
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/tirthankar/projects/physicc/Light/build
Edit: I opened an issue on the CMake Tools GitHub page.

The -H option is used for printing the help documentation for CMake.
-H has never been a standard or documented CMake flag for generating a project. You should not use it and you should disregard any "resources" that encourage you to use undocumented flags. If a Visual Studio Code extension is using it, you should open an issue with the authors of the extension.
The documented equivalent is -S, which sets the source directory. By default, it is the current directory. It was introduced in CMake 3.13. See the latest documentation here: https://cmake.org/cmake/help/latest/manual/cmake.1.html#generate-a-project-buildsystem
There might be subtle behavioral differences between -H and -S. Do not use undocumented/internal flags.

-H is indeed the flag for displaying the help docs, as #Alex Reinking, but there is another undocumented meaning.
While looking for good resources for learning CMake, I stumbled across CGold, which also mentions the -H flag as a way to supply the path to the source.
Add -H<path-to-source-tree> to set directory with CMakeLists.txt. This internal option is not documented but widely used by community. There must be no spaces between -H and <path-to-source-tree> (otherwise option will be interpreted as synonym to --help). Always must be used with -B option.
Here are some specific pointers to projects which use (or recommend using) the -H flag to point to the source directory.
In fact, as CGold suggests, there was a patch submitted a long time ago which aimed to actually document the internal -H flag.
However, it should be noted that one of the developers replied with
These are undocumented because they are internal options that
are not meant for public use.
So, we should not use those flags, and stick to the functionally equivalent (as pointed out by #Alex Reinking) -S flag if we need to pass in the source directory.

Related

msbuild: command line error D8021: invalid numeric argument /Werror

I am a student of TU Wien and quite new in programming. I would like to install a GitHub repository (https://github.com/SICKAG/sick_safetyscanners_base) which is basically for Linux, but I asked one the of the contributors and he said it should work on windows too.
According to the README the following steps have to be done to install this the repository:
git clone https://github.com/SICKAG/sick_safetyscanners_base.git
cd sick_safetyscanners_base
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=<path to install folder> ..
make -j8
make install
Here is a list of the softwares and tools I have already installed:
Visual Studio 2022 Community (because of MSVC)
Visual Studio Code
Scoop (to install cmake and make)
Boost 1.80.0
Git
And here are all the commands which are just working fine:
git clone https://github.com/SICKAG/sick_safetyscanners_base.git
cd sick_safetyscanners_base
mkdir build
cd build
cmake -DBoost_USE_STATIC_LIBS=ON .. (-DBoost_USE_STATIC_LIBS=ON, otherwise cmake does not find boost)
The problem is in the command line "make -j8". After this command, I recieve the following message: *** No targets specified and no makefile found. Stop. I have done some research and I found out that make will not work on windows (I use windows 10).
PS C:\Users\ader\sick_safetyscanners_base> mkdir build
Directory: C:\Users\ader\sick_safetyscanners_base
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 09/11/2022 13:04 build
PS C:\Users\ader\sick_safetyscanners_base> cd build
PS C:\Users\ader\sick_safetyscanners_base\build> cmake -DBoost_USE_STATIC_LIBS=ON ..
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The CXX compiler identification is MSVC 19.33.31630.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Found Boost: C:/boost/boost_1_80_0 (found version "1.80.0") found components: system thread chrono atomic
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/ader/sick_safetyscanners_base/build
PS C:\Users\ader\sick_safetyscanners_base\build> make -j
make: *** No targets specified and no makefile found. Stop.
Since Make will not work, I tried the command "msbuild" in the Developer PowerShell for VS 2022, but the repository will still not be installed, because I have the following error message: command line error D8021: invalid numeric argument /Werror.
PS C:\Users\ader\sick_safetyscanners_base\build> msbuild sick_safetyscanners_base.vcxproj
MSBuild version 17.3.1+2badb37d1 for .NET Framework
Build started 09/11/2022 13:07:41.
Project "C:\Users\ader\sick_safetyscanners_base\build\sick_safetyscanners_base.vcxproj" on node 1 (default targets).
Project "C:\Users\ader\sick_safetyscanners_base\build\sick_safetyscanners_base.vcxproj" (1) is building "C:\Users\ader\
sick_safetyscanners_base\build\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
Creating directory "x64\Debug\ZERO_CHECK\".
Creating directory "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\".
InitializeBuildStatus:
Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
Checking Build System
FinalizeBuildStatus:
Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "C:\Users\ader\sick_safetyscanners_base\build\ZERO_CHECK.vcxproj" (default targets).
PrepareForBuild:
Creating directory "sick_safetyscanners_base.dir\Debug\".
Creating directory "C:\Users\ader\sick_safetyscanners_base\build\Debug\".
Creating directory "sick_safetyscanners_base.dir\Debug\sick_saf.78B012DA.tlog\".
InitializeBuildStatus:
Creating "sick_safetyscanners_base.dir\Debug\sick_saf.78B012DA.tlog\unsuccessfulbuild" because "AlwaysCreate" was spe
cified.
CustomBuild:
Building Custom Rule C:/Users/ader/sick_safetyscanners_base/CMakeLists.txt
ClCompile:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64\CL.exe /c /IC:\User
s\ader\sick_safetyscanners_base\include /IC:\boost\boost_1_80_0 /Zi /nologo /Wall /WX- /diagnostics:column /Od /Ob0 /
D _WINDLL /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D sick_safetyscanners_base_EXPORTS /Gm- /EHsc /R
TC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"sick_safetyscanners_base.dir\Debug\\" /Fd"sick_s
afetyscanners_base.dir\Debug\vc143.pdb" /external:W4 /Gd /TP /errorReport:queue -std=c++11 -Werror C:\Users\ader\sic
k_safetyscanners_base\src\SickSafetyscanners.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\ApplicationNameVari
ableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\ChangeCommSettingsCommand.cpp C:\Users\ader\sick_saf
etyscanners_base\src\cola2\CloseSession.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\Cola2Session.cpp C:\User
s\ader\sick_safetyscanners_base\src\cola2\Command.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\ConfigMetadata
VariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\CreateSession.cpp C:\Users\ader\sick_safetyscann
ers_base\src\cola2\DeviceNameVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\DeviceStatusVariabl
eCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\FieldGeometryVariableCommand.cpp C:\Users\ader\sick_saf
etyscanners_base\src\cola2\FieldHeaderVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\FieldSetsV
ariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\FindMeCommand.cpp C:\Users\ader\sick_safetyscanne
rs_base\src\cola2\FirmwareVersionVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\LatestTelegramV
ariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\MeasurementCurrentConfigVariableCommand.cpp C:\Us
ers\ader\sick_safetyscanners_base\src\cola2\MeasurementPersistentConfigVariableCommand.cpp C:\Users\ader\sick_safetys
canners_base\src\cola2\MethodCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\MonitoringCaseTableHeaderVa
riableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\MonitoringCaseVariableCommand.cpp C:\Users\ader\si
ck_safetyscanners_base\src\cola2\OrderNumberVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\Proj
ectNameVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\RequiredUserActionVariableCommand.cpp C:\
Users\ader\sick_safetyscanners_base\src\cola2\SerialNumberVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\
src\cola2\StatusOverviewVariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\TypeCodeVariableCommand.
cpp C:\Users\ader\sick_safetyscanners_base\src\cola2\UserNameVariableCommand.cpp C:\Users\ader\sick_safetyscanners_ba
se\src\cola2\VariableCommand.cpp C:\Users\ader\sick_safetyscanners_base\src\communication\TCPClient.cpp C:\Users\ader
\sick_safetyscanners_base\src\communication\UDPClient.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\
ParseApplicationData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseApplicationNameData.cpp C:\U
sers\ader\sick_safetyscanners_base\src\data_processing\ParseConfigMetadata.cpp C:\Users\ader\sick_safetyscanners_base
\src\data_processing\ParseData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseDataHeader.cpp C:\
Users\ader\sick_safetyscanners_base\src\data_processing\ParseDatagramHeader.cpp C:\Users\ader\sick_safetyscanners_bas
e\src\data_processing\ParseDerivedValues.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseDeviceNa
me.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseDeviceStatus.cpp C:\Users\ader\sick_safetyscan
ners_base\src\data_processing\ParseFieldGeometryData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\P
arseFieldHeaderData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseFieldSetsData.cpp C:\Users\ad
er\sick_safetyscanners_base\src\data_processing\ParseFirmwareVersion.cpp C:\Users\ader\sick_safetyscanners_base\src\d
ata_processing\ParseGeneralSystemState.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseIntrusionD
ata.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseMeasurementCurrentConfigData.cpp C:\Users\ade
r\sick_safetyscanners_base\src\data_processing\ParseMeasurementData.cpp C:\Users\ader\sick_safetyscanners_base\src\da
ta_processing\ParseMeasurementPersistentConfigData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\Par
seMonitoringCaseData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseOrderNumber.cpp C:\Users\ade
r\sick_safetyscanners_base\src\data_processing\ParseProjectName.cpp C:\Users\ader\sick_safetyscanners_base\src\data_p
rocessing\ParseRequiredUserAction.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseSerialNumber.cp
p C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseStatusOverview.cpp C:\Users\ader\sick_safetyscanner
s_base\src\data_processing\ParseTCPPacket.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseTypeCod
eData.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\ParseUserNameData.cpp C:\Users\ader\sick_safetys
canners_base\src\data_processing\TCPPacketMerger.cpp C:\Users\ader\sick_safetyscanners_base\src\data_processing\UDPPa
cketMerger.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\ApplicationData.cpp C:\Users\ader\sick_safety
scanners_base\src\datastructure\ApplicationInputs.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\Applic
ationName.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\ApplicationOutputs.cpp C:\Users\ader\sick_safe
tyscanners_base\src\datastructure\CommSettings.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\ConfigDat
a.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\ConfigMetadata.cpp C:\Users\ader\sick_safetyscanners_b
ase\src\datastructure\Data.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\DatagramHeader.cpp C:\Users\a
der\sick_safetyscanners_base\src\datastructure\DataHeader.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructur
e\DerivedValues.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\DeviceName.cpp C:\Users\ader\sick_safety
scanners_base\src\datastructure\DeviceStatus.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\FieldData.c
pp C:\Users\ader\sick_safetyscanners_base\src\datastructure\FieldSets.cpp C:\Users\ader\sick_safetyscanners_base\src\
datastructure\FirmwareVersion.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\GeneralSystemState.cpp C:\
Users\ader\sick_safetyscanners_base\src\datastructure\IntrusionData.cpp C:\Users\ader\sick_safetyscanners_base\src\da
tastructure\IntrusionDatum.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\LatestTelegram.cpp C:\Users\a
der\sick_safetyscanners_base\src\datastructure\MeasurementData.cpp C:\Users\ader\sick_safetyscanners_base\src\datastr
ucture\MonitoringCaseData.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\OrderNumber.cpp C:\Users\ader\
sick_safetyscanners_base\src\datastructure\PacketBuffer.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\
ParsedPacketBuffer.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\ProjectName.cpp C:\Users\ader\sick_sa
fetyscanners_base\src\datastructure\RequiredUserAction.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\S
canPoint.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\SerialNumber.cpp C:\Users\ader\sick_safetyscann
ers_base\src\datastructure\StatusOverview.cpp C:\Users\ader\sick_safetyscanners_base\src\datastructure\TypeCode.cpp C
:\Users\ader\sick_safetyscanners_base\src\datastructure\UserName.cpp
cl : befehlszeile error D8021: Ungültiges numerisches Argument /Werror. [C:\Users\ader\sick_safetyscanners_base\build\
sick_safetyscanners_base.vcxproj]
Done Building Project "C:\Users\ader\sick_safetyscanners_base\build\sick_safetyscanners_base.vcxproj" (default targets)
-- FAILED.
Build FAILED.
"C:\Users\ader\sick_safetyscanners_base\build\sick_safetyscanners_base.vcxproj" (default target) (1) ->
(ClCompile target) ->
cl : befehlszeile error D8021: Ungültiges numerisches Argument /Werror. [C:\Users\ader\sick_safetyscanners_base\buil
d\sick_safetyscanners_base.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.43
At this stage, I do not really know, what else should I try to get this lilbrary finally installed. My goal is to call it with #include in my C++ program.
Do you have a solution here on how to get rid of the error message and how to install this library? I think the only thing missing is this step. I would be very grateful for any suggestions.
Thank you in advance!
== UPDATE after the answer of MadScientist ==
Brief history: After installing boost, I got the following message...
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
C:\boost\boost_1_80_0
The following directory should be added to linker library paths:
C:\boost\boost_1_80_0\stage\lib
... but I don't know exactly where to put these paths. I'm assuming that's exactly why Cmake doesn't find Boost. This problem was solved with -DBoost_USE_STATIC_LIBS=ON.
Now, if I use the command line cmake -DBoost_USE_STATIC_LIBS=ON -G "Unix Makefiles" .., CMake fails to find Boost again.
Here is what I can see on the terminal:
PS C:\Users\ader\sick_safetyscanners_base\build> cmake -G "Unix Makefiles" -DBoost_USE_STATIC_LIBS=ON ..
-- The CXX compiler identification is GNU 12.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
CMake Error at C:/Users/ader/scoop/apps/cmake/3.24.3/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: system thread chrono) (found version
"1.80.0")
Call Stack (most recent call first):
C:/Users/ader/scoop/apps/cmake/3.24.3/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
C:/Users/ader/scoop/apps/cmake/3.24.3/share/cmake-3.24/Modules/FindBoost.cmake:2376 (find_package_handle_standard_args)
CMakeLists.txt:11 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/ader/sick_safetyscanners_base/build/CMakeFiles/CMakeOutput.log".
PS C:\Users\ader\sick_safetyscanners_base\build>
Make absolutely does work on Windows (if you install it). In fact, you can tell it works since you ran it and it worked!!
The problem is that cmake can create project files for lots of different build systems, and the default on Windows is Visual Studio, not make. So when you ran cmake you got a bunch of files that tell Visual Studio how to build your code, but no files that tell make how to build your code.
Delete the directory and unpack it again, then run cmake again and add the -G "Unix Makefiles" option to the command.
However, the option -Werror is an option to the GCC compiler. It won't work if you're trying to run the Visual Studio compiler (even if you use a makefile to build the code, it will still use the Visual Studio compiler to compile it).
My suspicion is that whomever told you that "it should work" to build this code on Windows, was overly optimistic and in fact it will require some porting effort to make this work.

CMake doesn't recognize NVTX after CUDA network install on Win10

Have a look at this GitHub actions run result on a machine running Windows 10:
nvcc_11.7 visual_studio_integration_11.7 curand_dev_11.7 nvrtc_dev_11.7 nvtx_11.7 cudart_11.7 visual_studio_integration_11.7 nsight_nvtx_11.7
Downloading CUDA Network Installer for 11.7.0 from: https://developer.download.nvidia.com/compute/cuda/11.7.0/network_installers/cuda_11.7.0_windows_network.exe
Downloading Complete
Installing CUDA 11.7.0. Subpackages nvcc_11.7 visual_studio_integration_11.7 curand_dev_11.7 nvrtc_dev_11.7 nvtx_11.7 cudart_11.7 visual_studio_integration_11.7 nsight_nvtx_11.7
CUDA_PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
CUDA_PATH_VX_Y CUDA_PATH_V11_7
Adding CUDA to CUDA_PATH, CUDA_PATH_X_Y and PATH
1m 2s
Run cmake -B build -G "Visual Studio 16 2019" -A x64 -DBUILD_EXAMPLES=ON
-- The CUDA compiler identification is NVIDIA 11.7.64
-- The CXX compiler identification is MSVC 19.29.30145.0
-- 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.7/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA 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/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Unable to find cublas_v2.h in either "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include" or "C:/Program Files/NVIDIA GPU Computing Toolkit/math_libs/include"
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include (found suitable version "11.7.64", minimum required is "9.0")
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - not found
-- Found Threads: TRUE
-- Automatic GPU detection failed. Building for common architectures.
-- Autodetected CUDA architecture(s): 5.3;6.0;6.1;7.0;7.5;8.0;8.6;8.6+PTX
-- Configuring done
CMake Error at CMakeLists.txt:58 (target_link_libraries):
The link interface of target "nvtx" contains:
-- Generating done
CUDA::nvToolsExt
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
CMake Generate step failed. Build files cannot be regenerated correctly.
Error: Process completed with exit code 1.
It seems the installer is installing everything it needs, including NVTX - but somehow, CMake is not then able to locate the installed NVTX library.
Why would this happen? What can I do about it?
This is an open bug against CMake:
Bug 22893: FindCUDAToolkit: Fails to locate nvToolsExt, no error nor warning
Please let Kitware know it's important to you, because they don't seem very keen on fixing it for some reason.

CMake couldn't find MatLab libraries, even though MatLab is detected

I have been trying to build BlockFactory and I keep getting following error when trying to build it.
PS F:\simconnect-monitor\blockfactory> cmake -S . -B build
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19044.
-- The CXX compiler identification is MSVC 19.16.27045.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find Matlab (missing: Matlab_MEX_LIBRARY Matlab_MX_LIBRARY ENG_LIBRARY) (found version "9.10")
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find Matlab (missing: Matlab_MEX_LIBRARY Matlab_MX_LIBRARY MX_LIBRARY) (found version "9.10")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
cmake/FindMatlab.cmake:1873 (find_package_handle_standard_args)
deps/mxpp/CMakeLists.txt:45 (find_package)
As you can see, MatLab was detected but the correct library cannot be found. I have tried with CMake 3.18.14 and 3.22.3 with no difference. I am really loss right now honestly. I have posted an issue in the BlockFactory GitHub but so far, it is still unresolved.
So, I found the solution. I am using VS2017. By default for VS2017, cmake makes 32-bit project. You have to pass cmake -A x64 to force it to a 64-bit project. In addition to that, though, I have to force finfmatlab.cmake to only look for 64-bit library by basically setting _matlab_64build to always be true. Make sure you have 64-bit MatLab if you do this.
Edit: Alternatively, you can install VS2019 instead since it defaulted to 64-bit project.

Cmake fail to compile cant find python.h (Flutter, dart:ffi)

I need to connect .C/.CPP code that makes use of Python in to Flutter app.
Luckily I can use dart:ffi for it. and therefore the
but when I'm trying to compile the apk I am getting the following error:
Launching lib/main.dart on AOSP on IA Emulator in debug mode...
lib/main.dart:1
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /home/*usr_name*/Android/Sdk/cmake/3.18.1/bin/ninja with arguments {-C /home/*usr_name*/flutter/final4/android/app/.cxx/cmake/debug/x86_64 weather}
ninja: Entering directory `/home/*usr_name*/flutter/final4/android/app/.cxx/cmake/debug/x86_64'
[1/2] Building C object CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o
FAILED: CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o
/home/*usr_name*/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=x86_64-none-linux-android21 --gcc-toolchain=/home/*usr_name*/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/*usr_name*/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Dweather_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o -MF CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o.d -o CMakeFiles/weather.dir/home/*usr_name*/flutter/final4/src/weather.c.o -c /home/*usr_name*/flutter/final4/src/weather.c
/home/*usr_name*/flutter/final4/src/weather.c:43:10: fatal error: 'Python.h' file not found
#include <Python.h>
^~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
at first my CMakeLists.txt file looked like this:
cmake_minimum_required(VERSION 3.18)
project(py)
add_library(
weather
SHARED
../../src/weather.c
)
So I edit it to find Python and make sure that he indeed find it and the development version that I have installed :
cmake_minimum_required(VERSION 3.18)
project(py)
find_package(Python COMPONENTS Interpreter Development)
message("Python_FOUND:${Python_FOUND}")
message("Python_VERSION:${Python_VERSION}")
message("Python_Development_FOUND:${Python_Development_FOUND}")
message("Python_LIBRARIES:${Python_LIBRARIES}")
message("Python_LIBRARY_DIRS:${Python_LIBRARY_DIRS}")
message("Python_INCLUDE_DIRS:${Python_INCLUDE_DIRS}")
message("Python_LINK_OPTIONS:${Python_LINK_OPTIONS}")
message("Python_NumPy_FOUND:${Python_NumPy_FOUND}")
add_library(
weather
SHARED
../../src/weather.c
)
Now cmake . prints:
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter Development Development.Module Development.Embed
Python_FOUND:TRUE
Python_VERSION:3.8.10
Python_Development_FOUND:TRUE
Python_LIBRARIES:/usr/lib/x86_64-linux-gnu/libpython3.8.so
Python_LIBRARY_DIRS:/usr/lib/x86_64-linux-gnu
Python_INCLUDE_DIRS:/usr/include/python3.8
Python_LINK_OPTIONS:
Python_NumPy_FOUND:FALSE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/*usr_name*/flutter/final4/android/app
Great, now Cmake knows where python is but still returns the same error when trying to create the apk.
I tried as well to include the include/python3.8 path for the compiler with the -I flag but that caused a bunch of different issues that make me force outer paths which just felt wrong and ended up with no solution.
I added the project to github so you guys can take a look at it as well:
https://github.com/Eidantz/Flutter_python_c
you can find weather.c and another .C file that I tried in /src folder.
the CMakeLists.txt is of course in /android/app folder
Thanks in advance guys!

Generate CMake compile commands on Windows

I'm setting up a C/C++ build environment on Windows using Eclipse CDT, CMake and the cmake4eclipse plugin. Everything works fine except the generation of compile_commands.json. This file is required by the cmake4eclipse plugin in order to use the two CMAKE_EXPORT_COMPILE_COMMANDS providers for automatic include detection etc. (as far as I understood that correctly).
I'm using Windows builds of CMake (3.20) and ninja as well as the MSYS2 version of gcc. All tools are accessible via the PATH variable (compilation works fine as I already mentioned).
My cmake command roughly looks like this:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -G Ninja "C:\\path\\to\\source"
During configuration I always get the warning
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_EXPORT_COMPILE_COMMANDS
and no compile_commands.json is generated in the build directory.
I understand that this is often a problem when trying to export compile commands for generators which are not supported, e.g. Visual Studio. But since I'm using ninja, I would expect a successful generation of the JSON file.
Did anyone experience similar issues or has any ideas?
Thanks!
Edit:
Here's the output with message(STATUS "gen = ${CMAKE_GENERATOR}"):
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -G Ninja "C:\\path\\to\\source"
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/usr/bin/cc.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:/msys64/usr/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- gen = Ninja
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_EXPORT_COMPILE_COMMANDS
-- Build files have been written to: C:/path/to/build
10:52:57 Buildscript generation finished (took 9351 ms)
Unfortunately I can't post my whole CMakeLists.txt since it belongs to a project in our company. The top-level CMakeLists.txt does not define any targets, but adds a couple of ExternalProjects to support cross-compilation.
I was able to reproduce your error message with the following CMakeLists.txt. This is not a bug:
cmake_minimum_required(VERSION 3.20)
project(test)
I then ran
> cmake -G Ninja -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-- The C compiler identification is MSVC 19.28.29915.0
-- The CXX compiler identification is MSVC 19.28.29915.0
-- 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.28.29910/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.28.29910/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_EXPORT_COMPILE_COMMANDS
-- Build files have been written to: D:/test/build
The reason for this is because, as you say,
The top-level CMakeLists.txt does not define any targets, but adds a couple of ExternalProjects to support cross-compilation.
The commands for custom targets are not included in the compile_commands.json, and the variable is only inspected by CMake when processing the first compiled target (either add_executable or add_library).
There is no simple fix; setting CMAKE_EXPORT_COMPILE_COMMANDS in each of your sub-projects will result in one compile_commands.json file for each. Merging them such that Eclipse will understand the result is beyond the scope of this question.
This is part of a larger issue with ExternalProject -- it's too separated. It boils down to automating the creation of some relatively complicated custom targets and commands, so the parent project has no idea what's going on in its children.
A better approach for cross-compiling with host tools is to allow the user to call your build twice: first with a host toolchain in one directory and second with a target toolchain in a different directory with variables set so that the first build will be scanned for host tools instead of re-creating the targets in the target build. The export() and find_package() commands are useful for this.