I am following this quick tutorial and I am not sure how to do the project setup part for my pre-existing VS 2017 project that uses the LunarG Vulkan SDK which includes the glslang and SPIRV folders. I tried using the table found here to convert the cmake commands in the tutorial; I was able to include the glslang directory but I cannot figure out what I should be adding to properties->linker->input->additional dependencies for linking with glslang and SPIRV. Do I have to somehow compile these first then link to them? In which case how do I do that?
Do I have to somehow compile these first then link to them? In which case how do I do that?
Yes. If you want to use the glslang tools at runtime instead of at build time, you need to first build them. The VulkanSDK contains the glslang source code, but not binaries. Since the interface to glslang is C++, not C like Vulkan, producing a binary that would work for everyone is basically a non-starter.
The tutorial you link to includes this:
add_subdirectory(${LIB_DIRECTORY}/glslang)
Which basically means "include this other CMake based project in my own", which would in turn mean that it would have the same build settings as your own CMake based project. In order to bypass CMake you would need to construct a Visual Studio project for glslang from scratch.
My advice to you is to stop trying to fit the tutorial into your pre-existing Visual Studio project and just use CMake to generate your VS project so that you can follow the tutorial directly. It's extremely unlikely that whatever settings you have in your pre-existing VS project can't be replicated in a CMake based VS project very quickly.
Alternatively, you can learn just enough CMake to create a project for glslang and build it, at which point you'll be able to use the binaries it creates as your linker inputs, BUT you'll need to make sure that the project settings in glslang generated project are sufficiently close to your own, in particular the Runtime Library and the 32/64 bit-edness and make sure that you don't mix and match release and debug builds across the dependency.
Here is a simple recipe for building glslang, assuming you have CMake installed and the VulkanSDK correctly installed:
mkdir %VULKAN_SDK%\..\glslang
cd %VULKAN_SDK%\glslang
mkdir build
cd build
cmake .. -G "Visual Studio 15 Win64" -DCMAKE_INSTALL_PREFIX=%VULKAN_SDK%\..\glslang
cmake --build . --config Release
cmake --build . --config Debug
cmake --build . --config Release --target INSTALL
cmake --build . --config Debug --target INSTALL
Related
I have a multiplatform CMake project, and occasionally I have to build it manually for Windows. I generate a buildsystem like this:
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" -A x64 ../path/to/source
Then I open *sln file and press F7 to build. It runs for 40 minutes, and after that I understand that I didn't select proper configuration in the combobox. It's annoying! When command line option was -DCMAKE_BUILD_TYPE=Release, but combobox was set to Debug, build fails after spending a decent time.
Is it possible to generate an MSVS project with build configuration selected from command line?
Note that I'm aware of msbuild command and it's -p:Configuration=xxxxx flag. The question is about cases when for some reason you need to build from Visual Studio's GUI.
Changing the selected configuration for the GUI is not possible with CMake at this moment.
The main reason for this is that this information is stored in the .suo file generated by Visual Studio. CMake itself only generates the project and solution files, while the .suo file will be generated by Visual Studio itself.
Alternatively, use CMake's command line build option for this. After configuring your project and generating the VS .sln file from CMake as usual, simply run:
cmake --build <path_to_build_directory> --config Release
This works independently of the selected generator and is the most reliable way of building CMake projects.
I've never used CMake on Windows, or with MSVC, before; so this is a newbie question.
I've installed CMake and some minimal freely-downloadable "Microsoft Visual C++ build tools 2015" (from here) on a Windows 10 machine. I have my CMake-based project (which builds fine on Linux) checked out, and I'm ready to go.
So, in a shell window, I do:
PS C:\Users\joeuser\the_project> mkdir build
... etc. etc. ...
PS C:\Users\joeuser\the_project> cd build
PS C:\Users\joeuser\the_project\build> cmake ../
-- Building for: Visual Studio 14 2015
-- Selecting Windows SDK version to target Windows 10.0.15063.
-- lots of checks here
-- etc. etc.
and that's done. So far so good. But - what now? On a Unix'ish system, I would execute make, and perhaps make install; and maybe make clean later on. My questions are:
Do the MSVC tools I'm using have an equivalent of make? I've head about nmake and msys but I'm not sure those are relevant here.
What do I do now in order to build, install or clean the build directory?
Is it better/easier/more common practice to use a different CMake generator in my scenario?
Making my previous comments an answer:
You would then call the underlying build tool directly via CMake:
cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal
This gives you an almost quiet build process as you are used to from make.
Why the hell do I have to provide so much arguments to CMake?
Because CMake is a build system generator and directs those arguments to the underlying build tool (make, MSBuild, nmake, ...). The underlying build tool may have different naming conventions for targets etc., e.g. make users provide almost always the targets all, clean, and install. But the Visual Studio solution generated by CMake uses by default ALL_BUILD, INSTALL, RUN_TESTS. There is no CLEAN target. Using MSBuild,
To install your solution you would select --target INSTALL.
For running tests, you would select --target RUN_TESTS.
For cleaning you have to use --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /t:Clean because the Visual Studio solution does not contain a clean target but MSBuild provides one.
Further important arguments of MSBuild are:
/maxcpucount:<numberOfCpus> (to limit the number of CPUs the build process is using) and
"/l:FileLogger,Microsoft.Build.Engine;logfile=<YOUR_LOGFILE_NAME>" to save MSBuild output to file.
How to use CMake for building a Universal Windows Application. I have already searched a lot and I came across the following:
CMake -G "Visual Studio 14 2015" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10
This is how I am supposed to invoke CMake.
(How can i use CMake to generate Windows 10 universal project)
How should the corresponding CMakeLists.txt files look like. I know about the command for executables and library like add_executable etc. But I do not know about the command to be used for building a UWP app. Can anyone please provide a sample CMakeLists.txt file along with some sample code?
Also how to use CMake for a WinRT component?
CMake is a cross-platform build tool, Microsoft has an fork branch from the official cmake repository, to bring in support for UWP and WinRT. So the offical cmake has support for UWP since some 3.4.0 version.
The CMakeLists.txt file differs from no general cmake file, you need to specify the cmake version, source file etc...
When targeting UWP project, you need to specify the build command as you pointed out,
CMake -G "Visual Studio 14 2015" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10
You can also use the CMake GUI tool, just declar the MAKE_SYSTEM_NAME and CMAKE_SYSTEM_VERSION macros.
Worth mentioning here is there's a open source fips project, which is a wrapper module around cmake. You can see how easy it is to generate UWP project, following the tutorial here,
fips build uwp-vstudio-debug
I'm trying to deploy a couple of .ini files to the binary directory when compiling, using CMake. I did this through the following lines (typed by hand; feel free to edit if you find a typo)
FILE(GLOB INI_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../misc/*.ini")
INSTALL(FILES ${INI_FILES} CONFIGURATIONS Debug DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug)
INSTALL(FILES ${INI_FILES} CONFIGURATIONS Release DESTINATION ${CMAKE_BINARY_DIR}/bin/Release)
This properly generates an INSTALL project in my Visual Studio solution which works if 'compiled' manually. However, the project is not part of the Debug and Release build configurations of the Solution, meaning it won't be executed when compiling the solution. Is there a way to add the project manually to the build configurations in CMake?
Or is this not intended and I need to call CMake differently?
I'm Using CMake 3.0.2 with Visual Studio 2013.
I'm generating my Visual Studio solution like this:
"%VS120COMNTOOLS%..\..\VC\vcvarsall" amd64
cmake .. -G "Visual Studio 12 2013 Win64"
Yes, you can add a custom command to copy the .ini files before you build the project. Assuming your build target is named my_target, you can do something like this:
FILE(GLOB INI_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../misc/*.ini")
add_executable(my_target test.cpp)
foreach(FN ${INI_FILES})
add_custom_command(TARGET my_target
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${FN}" "${CMAKE_CURRENT_BINARY_DIR}")
endforeach()
It basically uses cmake to copy the .ini files individually over to the build directory.
I am open to either a Visual Studio answer or a MinGW answer. I just finished building LLVM 3.2 using CMake and Visual Studio 2010. Everything went smoothly, but I have no llvm-config. Do I need it? Every example I see on the intertubes makes use of that tool. If I don't need it, how do I configure my project to make use of LLVM?
To be clear, I am not trying to use LLVM tools/compilers (like clang and whatnot). I am trying to write C++ code that uses the LLVM libraries to produce LLVM IR and even compile that stuff. I setup my include and lib folders. I ran llvm-config in Linux and saw a long list of macros and libraries.
I have a wonderful folder full of goodies. It just has no llvm-config in there: C:\Program Files (x86)\LLVM\
llvm-config does not exist in windows prebuilt binaries. You need to compile from the source code to get it.
Grab CMAKE > 3.5 , install it and make sure you add it to PATH.
Download Visual Studio 2019
Donwload the source code (9.0.1 is the latest as I'm writing this)
Extract the source code
Cd into the root of the llvm source-code
In cmd, type cmake . this will generate Visual Studio 2019 sln.
open sln file(LLVM.sln), change the build type to Rlease, build the whole project
navigate to your Rlease\bin, and there you have your llvm-config.exe
If you have built the LLVM in debug version all the executables (including llvm-config) have been placed in your build directory (containing Visual Studio project and solution files) in bin/Debug/ subdirectory. In case of release build replace Debug with Release.
If you are interested in using LLVM on Windows more than building it, check out Windows snapshot builds.