I use Windows 10, QtCreator 4.7.1, CMake 3.11.4 (Ninja, CodeBlocks), MSVC 2017. Try to integrate PVS-Studio to CMake project.
cmake_minimum_required(VERSION 3.10)
project(tst CXX)
add_executable(${PROJECT_NAME} main.cpp)
include(PVS-Studio.cmake)
pvs_studio_add_target(
TARGET ${PROJECT_NAME}.analyze ALL
OUTPUT FORMAT errorfile
ANALYZE ${PROJECT_NAME}
BIN "C:/Program Files (x86)/PVS-Studio/x64/PVS-Studio.exe")
I get error
[3/6 4.2/sec] Generating PVS-Studio.cfg
[4/6 5.1/sec] Analyzing CXX file main.cpp
FAILED: PVS-Studio/main.cpp.plog
cmd.exe /C "cd /D D:\work\v2.0\ui_tools\build-tst-Desktop_Qt_5_11_2_MSVC2017_64bit-u041eu0442u043bu0430u0434u043au0430 && "C:\Program Files\CMake\bin\cmake.exe" -E make_directory D:/work/v2.0/ui_tools/build-tst-Desktop_Qt_5_11_2_MSVC2017_64bit-u041eu0442u043bu0430u0434u043au0430/PVS-Studio && "C:\Program Files\CMake\bin\cmake.exe" -E remove_directory D:/work/v2.0/ui_tools/build-tst-Desktop_Qt_5_11_2_MSVC2017_64bit-u041eu0442u043bu0430u0434u043au0430/PVS-Studio/main.cpp.plog && "C:\Program Files\CMake\bin\cmake.exe" -D PVS_STUDIO_AS_SCRIPT=TRUE -D "PVS_STUDIO_COMMAND=C:/Program Files (x86)/PVS-Studio/x64/PVS-Studio.exe;analyze;--output-file;D:/work/v2.0/ui_tools/build-tst-Desktop_Qt_5_11_2_MSVC2017_64bit-u041eu0442u043bu0430u0434u043au0430/PVS-Studio/main.cpp.plog;--source-file;D:/work/v2.0/ui_tools/tst/main.cpp;--dep-file;D:/work/v2.0/ui_tools/build-tst-Desktop_Qt_5_11_2_MSVC2017_64bit-u041eu0442u043bu0430u0434u043au0430/PVS-Studio/main.cpp.plog.d;--dep-file-target;PVS-Studio/main.cpp.plog;--cfg;D:/work/v2.0/ui_tools/build-tst-Desktop_Qt_5_11_2_MSVC2017_64bit-u041eu0442u043bu0430u0434u043au0430/PVS-Studio.cfg;--platform;x64;--preprocessor;visualcpp;--cxx;C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/HostX86/x64/cl.exe;--cc;C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/HostX86/x64/cl.exe;--cl-params;;;-DPVS_STUDIO;D:/work/v2.0/ui_tools/tst/main.cpp" -P D:/work/v2.0/ui_tools/tst/PVS-Studio.cmake"
CMake Error at D:/work/v2.0/ui_tools/tst/PVS-Studio.cmake:46 (message):
Incorrect parameter syntax: An unknown parameter is present in the command
line: dep-file.
Any idea what to do?
In your CMake integration code, the 'BIN' parameter should point to the 'CompilerCommandsAnalyzer.exe' tool (under Windows) instead of the 'PVS-Studio.exe' C++ analyzer core.
However, PVS-Studio CMake module support for Windows will become available in PVS-Studio 6.26, which is expected to be released in a couple of days. The current 6.25 release is missing this tool.
Please check whether you have the 'CompilerCommandsAnalyzer.exe' inside your PVS-Studio installation folder ('c:\Program Files (x86)\PVS-Studio\' by default). If you do not have it, please write us at support#viva64.com, so we can give you a pre-release version to try. Or you can just wait for a 6.26 release which will become available quite soon.
Related
So I need to support .usd/.usda/.usdc for my renderer application, and I need to distribute the resulting project .exe and usd .libs/.dlls to our users on install. How do I build the library in a way that I can distribute? If I can't distribute it due to how the library is structured, how do I have the user install the needed dependencies automatically?
I was able to get oneTBB I believe (as TBB is a dependency of the library, but I don't know if USD can use it, here is how I compiled it)
::Issue this creates a .dll, would have been nice to have a static lib for not needed function culling
download: https://github.com/oneapi-src/oneTBB
extract: oneTBB-master folder
copy: include folder to destination (/I.\include in cl command when compiling)
open: cmd inside oneTBB-master folder (TIP: if you type cmd and hit enter in the folder path in the top it opens cmd there)
run: mkdir build && cd build
::if you want HWLOC then you need to rebuild with TBB bindings (for OpenMPI, I believe, but we don't currently use)
run: cmake .. -G "Visual Studio 15 2017 Win64" -DTBB_TEST=OFF -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Release
run: cmake --build . --config Release
run: cd msvc_19.16_cxx17_64_md_release
copy: tbb12.dll to destination
copy: tbb12.lib to destination (link against this)
:: don't think we need tbbmalloc.dll/tbbmalloc_proxy.dll and tbbmalloc.lib/tbbmalloc_proxy.lib
I tested TBB by compiling on the command line with a simple test program and build script like
#echo off
if not defined DevEnvDir (
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
)
set FILES=MinimalTBB.cpp
set LIBS=kernel32.lib user32.lib gdi32.lib
set DLLLIBS=tbb12.lib
:: tbbmalloc.lib tbbmalloc_proxy.lib
cl /nologo /W3 /Z7 /GS- /DEBUG:none /Gs999999 /MT /EHsc /O2 %FILES% -FeMinimalTBB.exe %LIBS% /I.\include /link %DLLLIBS% /incremental:no /opt:icf /opt:ref /subsystem:console
But then I need to do Boost.
And then I would love to do something like:
download: https://github.com/PixarAnimationStudios/USD
extract: USD-release folder
open: cmd inside USD-release folder
run: mkdir build && cd build
run: cmake .. -G "Visual Studio 15 2017 Win64" -DBUILD_SHARED_LIBS=ON -DPXR_BUILD_MONOLITHIC=OFF -DPXR_BUILD_IMAGING=OFF -DPXR_BUILD_USDVIEW=OFF -DPXR_ENABLE_PYTHON_SUPPORT=OFF -DPXR_BUILD_DOCUMENTATION=OFF -DPXR_BUILD_TESTS=OFF -DPXR_VALIDATE_GENERATED_CODE=OFF -DPXR_BUILD_PRMAN_PLUGIN=OFF -DPXR_BUILD_ALEMBIC_PLUGIN=OFF -DPXR_BUILD_DRACO_PLUGIN=OFF -DPXR_ENABLE_MATERIALX_SUPPORT=OFF -DCMAKE_BUILD_TYPE=Release
run: cmake --build . --config Release
to get .dll which i will distribute along with the .exe and then just link against the .lib in my project without the user installing anything
As an aside: I saw nVidia has a precompiled version too, I tried compiling with it, but it threw a bunch of python36.dll missing errors, when I am not even using python (only c++).
I found a ok solution from compiling from the command line, there is probably a much better way to do this, but to get it going here is what I did
The following wastes lots of memory on ur build machine, lots of files that don't need to be there, so go through and remove them:
download: lastest repo to C:\USD and create a USD-install folder inside of it
run: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat"
run: py C:\USD\build_scripts\build_usd.py C:\USD\USD-install --no-docs --no-embree --no-python --no-debug-python --no-draco --no-prman --no-materialx --no-alembic --no-hdf5 --no-opencolorio --no-openimageio --no-usdview --no-openvdb --no-ptex --no-imaging
I am compiling a windows program from the command line, so I created a new cpp project, but since we are compiling inside of Fuzor do not worry about this step
copied over the C:\USD\USD-install\bin, C:\USD\USD-install\include, and C:\USD\USD-install\lib folder to place of build. (copied .\include has to be included in include path)
moved tbb.dll, usd_ar.dll, usd_arch.dll, usd_gf.dll, usd_js.dll, usd_js.dll, usd_kind.dll, usd_pcp.dll, usd_plug.dll, usd_sdf.dll, usd_tf.dll, usd_trace.dll, usd_usd.dll, usd_vt.dll, and usd_work.dll all from lib folder to the level where my .exe will be generated and run from
In usd/pcp/types.h on line 119 change the numeric_limits<size_t>::max() to SIZE_MAX and in base/gf/ilmbase_halfLimits.h comment out the min and max functions on line 66 and 67
I then linked against lib/tbb.lib lib/usd_tf.lib lib/usd_sdf.lib lib/usd_vt.lib lib/usd_usd.lib
Create a resources folder at level of .exe and copy C:\USD\USD-install\plugin\usd\plugInfo.json to resources folder
In lib copy over C:\USD\USD-install\lib\usd up to the .exe level
distribute .exe, .dll's, and resources folder
I am running CMake from under CLion and when identifying CUDA compiler, it apperently uses too long paths, and fails (according to CMakeError.log file):
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
Build flags:
Id flags: --keep;--keep-dir;tmp -v
The output was:
1
D:\TESTS\CUDA_CLion\test01\cmake-build-debug\CMakeFiles\3.19.1\CompilerIdCUDA>call "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat"
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.2
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
The input line is too long.
The syntax of the command is incorrect.
#$ C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat
nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'
...
The command it runs is (according to CMake pane of CLion):
D:\Apps\CMake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug --debug-output -G "CodeBlocks - NMake Makefiles" D:\TESTS\CUDA_CLion\test01
If I run this command from CLI, it also fails, but with different error:
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
Build flags:
Id flags: --keep;--keep-dir;tmp -v
The output was:
1
nvcc fatal : Cannot find compiler 'cl.exe' in PATH
And finally, if I just run
cmake ..
from CLI it works: it finds itself Ok with long paths, it finds cl.exe, everything.
The question is: how to fix everything OR how to force CLion just to use only CMake without imagination?
Did your script invoke vcvarsall.bat or vcvars64.bat multiple times?
It could be solved by reduce them
I would like to convert my project from a Visual Studio solution to build with CMake and compile it with Makefiles.
This is a 2-part question.
Right now the CMakeLists.txt is:
cmake_minimum_required(VERSION 3.13.0)
project(Project2015 CXX)
add_executable(Project Source/main.cpp)
When I run cmake .. out of the build directory, it generates *.vcxproj and *.sln files, but there is no Makefile. How can I change the CMakeLists file to generate a Makefile?
What is the command line equivalent compiler to gcc for windows? And how do I set this compiler as the target for CMake and the generated Makefile?
Reading about the build tools https://learn.microsoft.com/en-us/cpp/build/walkthrough-compile-a-c-program-on-the-command-line?view=vs-2019
Do I need to target the cl.exe compiler? Would this work with CMake and Makefiles?
I'm reading online that these command line flags will set the compiler, how can I add these to the CMakeLists.txt to be used automatically?
DCMAKE_C_COMPILER=cl
DCMAKE_C_COMPILER_FORCED=ON
DCMAKE_CXX_COMPILER=cl
DCMAKE_CXX_COMPILER_FORCED=ON
DCMAKE_BUILD_TYPE=Debug
DCMAKE_INSTALL_PREFIX=%CFITSIO_DIR%
G"NMake Makefiles"
You should use the build tool mode of CMake for builds from the command line.
After configuring your project for a 64bit build using Visual Studio 2019 e.g. with
cmake -S <sourcedir> -B <builddir> -G "Visual Studio 16 2019" -A x64
you would run
cmake --build <builddir> --target ALL_BUILD --config Release
For further options see here for an almost quiet build from the command line see here.
As suggested by #vre, you can run everything from the command line, while still using the Visual Studio generator. Just use CMake's command line build tools:
cmake ..
cmake --build . --config Release
This way, you don't have to open Visual Studio at all to build your libraries/executables.
Another option is to use Microsoft's nmake utility, which will generate NMake Makefiles. You can tell CMake to use this generator instead using this:
cmake -G"NMake Makefiles" ..
The full list of CMake generators you can choose from is listed here.
If you don't want to manually set the CMake generator in the command line, you can set it at the top of your CMakeLists.txt file:
set (CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
It will be used on the second CMake configuration in this case, as the first run will use the system default generator. If you want CMake to use it on the first configuration, you can utilize the Preload.cmake procedure outlined in this answer.
I'm trying to build FLANN libriary on windows.But I have cygwin installed.
> "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
> cd flann-x.y.z-src
> mkdir build
> cd build
> cmake ..
> nmake
and when I use cmake .. it seems it uses cygwin and gcc compiler.
and then nmake don't work.
Quite unclear what you want to achieve:
You can build FLANN in cygwin environment by cygwin's cmake and make and then use it.
Or you can follow FLANN installation instructions and build it with window's native cmake and C++ compiler and use it (simply do not use cygwin at all, use cmd.exe).
In case you want to use VS2008 C++ compiler, do
cmake -G "Visual Studio 9 2008" ..
cmake --build . --config Release
I would like to build boost using two different compilers, MinGW and Visual C++ 2010 Express, using bjam:
bjam toolset=gcc,msvc variant=release link=static,shared threading=multi install
The problem is that I do not have bjam. I could not find it in the Boost directory, and the one I downloaded from somewhere else was a wrong version.
I should be able to build it from the code in Boost, but how? I read that I must launch build.bat from the BOOST_ROOT/tools/jam/src directory, but that directory does not exist !
Thank you!
Platform: Windows7
Compilers: MinGW and Visual C++ 2010 Express
Update:
I have been able to get bjam with: bootstrap.bat gcc
Then, launching bjam with the previous parameters, I only get libraries for MinGW (.dll and .a).
This is an extract of the error messages I get with regard to Visual C++ 10:
...
call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
cl /Zm800 -nologo #"bin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi\plain_report_formatter.obj.rsp"
...failed compile-c-c++ bin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi\plain_report_formatter.obj...
...
...skipped <pbin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi>boost_unit_test_framework-vc100-mt-1_48.dll for lack of <pbin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi>compiler_log_formatter.obj...
...
common.mkdir bin.v2\libs\thread\build\msvc-10.0\release\threading-multi
common.mkdir bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32
compile-c-c++ bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32\thread.obj
\Microsoft was unexpected at this time.
...
call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
cl /Zm800 -nologo #"bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32\thread.obj.rsp"
...failed compile-c-c++ bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32\thread.obj...
compile-c-c++ bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32\tss_dll.obj
\Microsoft was unexpected at this time.
...
...skipped <pC:\Boost\lib>boost_thread-vc100-mt-1_48.lib for lack of <pbin.v2\libs\thread\build\msvc-10.0\release\threading-multi>boost_thread-vc100-mt-1_48.lib
...
Trying to use:
bootstrap.bat vc100
I get the error: "Unknown toolset: vc100"
With either:
bootstrap.bat vc10
or:
bootstrap.bat mingw
I get: "\Microsoft was unexpected at this time."
Changing project-config.jam did not help.
So, I did a big step forward, but vc10 is not working, yet...
There is a bootstrap.bat in your boost directory. Run it.
It will build bjam automatically (probably using visual c++).
The directory structure in boost has changed in recent version, I think.
The sources for bjam are in tools/build/v2/engine. Run build.sh mingw from that directory using MinGW shell, and it should build bjam.exe and b2.exe and place them in tools/build/v2/engine/ntx86. Copy b2.exe to the boost root directory. You should then be able to build Visual c++ libraries with b2 toolset=msvc.
Hope that helps.
In my case, the solution from jork works!
I searched the bjam.exe file and found it located in the tools/build/src/engine directory and just copied it to the boost root directory. But I have to say this is awful, I felt like the codebase writer is trying to hide sth. And I found that my bjam.exe is exactly is the same size with b2.exe, which is 404KB.
I will turn back later to ensure that I solved this issue.