CMake 64-bit with SFML 64-bit - c++

I'm trying to build a C++ project with CMake 64-bit for Windows and SFML 2.5.1 64-bit. When I run cmake on the project I'm getting an error message.
The only way I can get it to work is to change the CMAKE_PREFIX_PATH to point to a 32-bit version of SFML but that's not what I want.
CMakeLists.txt:
cmake_minimum_required (VERSION 3.8)
#project(GameOfLife)
set(CMAKE_PREFIX_PATH "D:\\Program Files\\SFML-2.5.1\\lib\\cmake\\SFML")
find_package(SFML 2.5 COMPONENTS graphics window REQUIRED)
# Add source to this project's executable.
add_executable (GameOfLife "GameOfLife.cpp" "GameOfLife.h")
# Link SFML
target_link_libraries(GameOfLife sfml-graphics sfml-window)
Error message:
CMake Error at CMakeLists.txt:16 (find_package): Could not find a
configuration file for package "SFML" that is compatible with
requested version "2.5".
The following configuration files were considered but not accepted:
D:/Program Files/SFML-2.5.1/lib/cmake/SFML/SFMLConfig.cmake, version:
2.5.1 (64bit)

I faced with the same problem and after some investigation I understood that Stanley's comment was correct. To use a 64-bit toolchain just run:
cmake -G "Visual Studio 15 2017 Win64" ..
For 32-bit SFML version it is enough to run simply: cmake ..

This issue happened to me on CLion, in my case I downloaded SFML for MinGW-64, but the default toolchain was configured to Visual Studio.
I solved this by going to File->Settings->Build, Execution, Deployment->Toolchains, clicking on MinGW and then the up arrow, making MinGW the defaut toolchain.

Related

CMake Error Failed to run MSBuild command

I am very new to CMake and try to build a minimum CMake file on Windows where I have installed Visual Studio 17 and 19. The C++ code is the bare minimum main.cpp:
#include<iostream>
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
The CMakeLists.txt file is also the minimum:
cmake_minimum_required(VERSION 3.1)
project(hello)
add_executable(${PROJECT_NAME} main.cpp)
When I run the CMake on the command line, I get this error and I do not know how to resolve it:
C:\SampleProject\build>cmake ./../src
-- Building for: Visual Studio 15 2017
CMake Error at CMakeLists.txt:3 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
The system cannot find the file specified
By default VC++ tools aren't on the PATH, they are added to the PATH by the vcvarsall.bat script.
Run cmake from a "x64 Native Tools Command Prompt for VS 2019" (it's a shortcut to vcvarsall.bat that Visual Studio installs in the Start Menu).
Bonus note:
When not using Visual Studio integration, you might want to consider Ninja as the alternative build system to MSBuild. It's more CMake-friendly because it doesn't require the Debug/Release duality of configuration (which is the source of headache when working with CMake).
Download ninja.exe, add it to the PATH
Use the Ninja CMake generator: cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
Enjoy easy and fast builds using the ninja command.
To build a Release version, re-run cmake with -DCMAKE_BUILD_TYPE=Release (so this works very much the same as on other platforms, e.g. Linux).
Ninja also integrates well with the VSCode CMake extension (note: VSCode != VS).

CUDA compile problems on Windows, Cmake error: No CUDA toolset found

so I've been successfully working on my CUDA program on my Linux but I would like to support Windows platform as well. However, I've been struggling with correctly compiling it. I use :
Windows 10
Cmake 3.15
Visual Studio 2017
CUDA Toolkit 10.1
When using the old deprecated Cmake CUDA support of using find_package(CUDA 10.1 REQUIRED) it correctly reports the correct path to the toolkit when using it. However, it is my understanding that the latest Cmake does not properly support the old method anymore and that cuda_add_libraryetc don't properly link anymore. So I have reformatted my 'CMakeLists.txt' file to the following based on this:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(myproject LANGUAGES CXX CUDA)
add_library(mylib SHARED mycudalib.cu)
# My code requires C++ 11 for the CUDA library, not sure which ones of these
# will do the trick correctly. Never got the compiler this far.
target_compile_features(mylib PUBLIC cxx_std_11)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CUDA_STANDARD 11)
set_target_properties( mylib PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(test_mylib test.cpp)
target_link_libraries(test_mylib mylib ${CUDA_CUFFT_LIBRARIES})
However, I get the following error from line 2:
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeDetermineCompilerId.cmake:345 (message):
No CUDA toolset found.
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeDetermineCompilerId.cmake:32 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeDetermineCUDACompiler.cmake:72 (CMAKE_DETERMINE_COMPILER_ID)
CMakeLists.txt:2 (project)
I've tried a variation of suggestions online such as adding the following to 'CMakeLists.txt':
set(CMAKE_CUDA_COMPILER "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc")
or adding the following variable to Cmake:
This is the 'CMakeLists.txt' file I use on Linux to compile succesfully. The difference is there I use Cmake 3.5 and CUDA Toolkit 9.0:
cmake_minimum_required(VERSION 3.5)
project( myproject)
find_package(CUDA 9.0 REQUIRED)
if(CUDA_FOUND)
list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
endif(CUDA_FOUND)
cuda_add_library(mylib SHARED mycudalib.cu)
cuda_add_executable(test_mylib test.cpp)
target_link_libraries(test_mylib mylib ${CUDA_CUFFT_LIBRARIES})
For Windows 10, VS2019 Community, and CUDA 11.3, the following worked for me:
Extract the full installation package with 7-zip or WinZip
Copy the four files from this extracted directory .\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions
into the MSBuild folder of your VS2019 install C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations
The four files are:
CUDA 11.3.props
CUDA 11.3.targets
CUDA 11.3.xml
Nvda.Build.CudaTasks.v11.3.dll
I had tried installing (and reinstalling) CUDA with Visual Studio Integration, but CMake wasn't able to find the CUDA installation (even with CUDA_PATH and CMAKE_CUDA_COMPILER defined).
I have tried it on a different PC now and it works fine. So I had absolutely no idea why it's not working on this one. As CUDA_PATH is correctly setup in my system variables.
Then looking into it further, by uninstalling the 'Build Tools' of Visual Studio and only having the Community IDE installed, CMake used the IDE instead of the Build Tools and then it started working fine.
Look at this. It may solve your issues.
https://gitlab.kitware.com/cmake/cmake/issues/19029
Seems like Nvidia cuda installer has some issues with installing the VS integration with vs 2017.
Check if you can find this file in your vs installing path.
C:/Program Files (x86)/Microsoft Visual
Studio/2017/Professional/Common7/IDE/VC/VCTargets/BuildCustomizations/CUDA
10.1.xml
I was trying to build darknet from source and came across this issue.
What resolved it for me was the following:
making sure no other Visual Studio or Visual Studio Build Tool was installed except for VS2019. (I configured this using the uninstall feature of the ~1 mb vs_community.exe installer program)
REINSTALLING CUDA 10.1, using the 2.5 gb installer, and in that process, making sure 'VS Integration' is installed (for me... this was a 'reinstall' since I had already installed it, but with a bunch of VS2019,VS2017 + Build Tools all installed at once!!) during the installation.
At that point, my cudnn files were still in the bin/lib/include folder of the 10.1 installation, and I hit "Configure" in CMake again.
Success! No errors. (CMake 3.18, VS2019, CUDA 10.1.243, cudnn 7.6.5)
I just have the same issue of No CUDA toolset found with different versions, and my system:
-Windows 11
-Cmake 3.20.0
-Visual Studio 2019
-CUDA Toolkit 11.6
Some netizens said that it happened if you installed Visual Studio before you install CUDA. So, I tried and reinstall CUDA, finally it work now. You also can try it. Good luck.
enter image description here

CMake doesn't generate vc pdb for simple test program

I am trying to use CMake on Windows 10. I create a Hello world project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
add_executable(simple-program main.cpp)
main.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!\n";
}
Then I open the project with CMake gui, choose Visual Studio 10 2010 Win64 generator and get this error when trying to generate the project:
testCCompiler.c : fatal error C1033: cannot open program database 'c:\work\prj\simple-program\build\cmakefiles\cmaketmp\cmtc_983e7.dir\debug\vc100.pdb'
Full output.
As I understood the problem, due to Zi option and no Fd, which cmake sets for the sample project, the project is trying to find vc100.pdb database and there is no one because the generator didn't make it.
I've tried the x86 generator. Other cmake versions (3.6, 3.13, 3.12). And I get the same result when using the console. My VS 2010 should be ok - it generates the PDB when I create the project from it.
Thank you!
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1033?view=vs-2017
Fatal Error C1033
This error can be caused by a disk error, a temporary lock created by an anti-virus program, a previous debugger instance that has not fully shut down, or parallel build mspdbsrv.exe processes that attempt to access the same file, among other possible causes.
NOTE:
I couldn't find the error codes for VS2010 on the Microsoft website. I don't think VS2010 is supported anymore and may not make working programs on Windows 10.
The problem was because I created build folder in WSL console. So it can be caused by any kind emulators like Cygwin, etc. Hope it will help someone.
Just build your generated project in Debug mode:
MSBuild ALL_BUILD.vcxproj /p:Configuration=Debug
If you want to create a Release and install it with PDB files just all:
list(APPEND INSTALL_TARGETS simple-program)
list(APPEND INSTALL_TARGETS_PDB simple-program)
# Install
install(TARGETS ${INSTALL_TARGETS}
RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin"
LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/bin"
ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/bin")
# Install *.pdb files
if(MSVC)
foreach(INSTALL_TARGET_PDB ${INSTALL_TARGETS_PDB})
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGET_PDB}> DESTINATION "${PROJECT_SOURCE_DIR}/bin")
endforeach()
endif()
Finall run CMake and build in RelWithDebInfo mode:
cmake -G "Visual Studio 10 2010 Win64"
MSBuild ALL_BUILD.vcxproj /p:Configuration=RelWithDebInfo
MSBuild INSTALL.vcxproj /p:Configuration=RelWithDebInfo
This will create simple-program.exe and simple-program.pdb files in your install dir.

When use Cmake to compile LZO,it notes that can't find any instance of VS

I have installed VS2015 (win64) and I wanna use Cmake to compile LZO to generate a VS project,but the Cmake show this:
CMake Error at CMakeLists.txt:51 (project):
Generator
Visual Studio 15 2017 Win64
could not find any instance of Visual Studio.
I think the problem may come from the Cmakelist.txt document,but I don't know how to fix it...
The 51 row of CmakeList.txt file is:
if(",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_BINARY_DIR},")
message(FATAL_ERROR "ERROR: In-source builds are not allowed.")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
project(lzo VERSION 2.10 LANGUAGES C++)
Generator Visual Studio 15 2017 Win64 is the wrong generator for Visual Studio 2015. You need Visual Studio 14 2015 Win64 if you have any trouble with that execute cmake-gui from a Visual Studio 2015 x64 command prompt so you have the compiler environment variables setup.
When I used LZO of version 2.08,the errors disappeared!So I think there must be some bugs in the original files of LZO in version 2.10.

How to set MSVC Target Platform Version with CMake?

I'm searching for way to set Target Platform Version of MSVC project generated with CMake. I found the following ticket in CMake issue tracker which is now closed. I'm with latest 3.9.1 version of CMake. But the solution described there seems to not work. I tried
set (CMAKE_SYSTEM_VERSION 8.1)
in my CMakeLists.txt.
How to set Terget Platform Version when using CMake?
Afterwords:
Now I checked that setting CMAKE_SYSTEM_VERSION from command line when generating solution works but I want if possible to be able to set this from CMakeLists.txt file.
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_SYSTEM_VERSION=8.1 ..\source\
At least it will be good to be able to set this from CMake GUI.
Using set (CMAKE_SYSTEM_VERSION 8.1 CACHE TYPE INTERNAL FORCE) before first usage of project solves the problem.