I'm trying to build a test SFML program the following way:
Windows 10, CLion, MinGW64, CMake, SFML-2.5.1
CmakeList.txt
cmake_minimum_required(VERSION 3.14)
project(Test_sfml_cmake_)
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0)
set(SFML_DIR "SFML-2.5.1/lib/cmake/SFML")
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(SFMLTest main.cpp)
target_link_libraries(SFMLTest sfml-graphics sfml-audio)
The MinGW build fails with an error (full output):
-- Found SFML 2.5.1 in D:/_Documents/Cpp Projects/Test_sfml[cmake]/SFML-2.5.1/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/_Documents/Cpp Projects/Test_sfml[cmake]/cmake-build-debug
Scanning dependencies of target SFMLTest
mingw32-make.exe[2]: *** No rule to make target 'sfml-audio-NOTFOUND', needed by 'SFMLTest.exe'. Stop.
mingw32-make.exe[2]: *** Waiting for unfinished jobs....
[ 50%] Building CXX object CMakeFiles/SFMLTest.dir/main.cpp.obj
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:72: CMakeFiles/SFMLTest.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
Anyone know what the problem is?
Your full path to the SFML library contains brackets [ ]
:
"D:/_Documents/Cpp Projects/Test_sfml[cmake]/SFML-2.5.1"
This is a problem for CMake (see this question), as square brackets are special characters used to denote bracket arguments and quotes.
Using square brackets in the path causes weird behavior in this case, because the find_package
call appears to succeed, but your sfml-*
targets are not created properly (e.g. sfml-audio-NOTFOUND
).
So, just change the directory name of your project to remove the square brackets, re-run CMake, then re-build.