I am trying to work with SMFL, CMAKE & VSCode. Cmake cannot link these SFML files. I install SFML & CMake using Homebrew.
I have tried including the SFML files with SMFL_ROOT
& SFML_INCLUDE_DIR
to no avail.
cmake_minimum_required(VERSION 3.14.2)
project(WordTypeCpp VERSION 0.1.0 )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 17)
find_package(SFML REQUIRED COMPONENTS graphics system)
if (SFML_FOUND)
set(SFML_ROOT "/usr/local/Cellar/sfml/2.5.1/include/SFML/")
# include_directories(${SFML_INCLUDE_DIR} "/usr/local/Cellar/sfml/2.5.1/include")
endif(SFML_FOUND)
set(SOURCE_FILES Main.cpp)
add_executable(Main ${SOURCE_FILES})
target_link_libraries(Main ${SFML_LIBRARIES})
add_definitions(-include ${CMAKE_CURRENT_SOURCE_DIR}/PCH.hpp)
include(CPack)
My Main.cpp
file
#include "PCH.hpp"
#include "Main.hpp"
int main()
{
std::cout << "SFML is running!" << '\n';
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
#ifdef SFML_SYSTEM_WINDOWS
__windowsHelper.setIcon(window.getSystemHandle());
#endif
sf::CircleShape shape(window.getSize().x / 2);
shape.setFillColor(sf::Color::White);
sf::Texture shapeTexture;
shapeTexture.loadFromFile("content/sfml.png");
shape.setTexture(&shapeTexture);
sf::Event event;
while (window.isOpen())
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
// PCH.hpp file
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
--config Debug --target Main -- -j 6
[build] [1/2 50% :: 1.825] Building CXX object src/CMakeFiles/Main.dir/Main.cpp.o
[build] FAILED: src/CMakeFiles/Main.dir/Main.cpp.o
[build] /usr/bin/clang++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -include /Users/.../WordTypeCpp/src/PCH.hpp -std=gnu++1z -MD -MT src/CMakeFiles/Main.dir/Main.cpp.o -MF src/CMakeFiles/Main.dir/Main.cpp.o.d -o src/CMakeFiles/Main.dir/Main.cpp.o -c ../src/Main.cpp
[build] In file included from <built-in>:1:
[build] /Users/.../WordTypeCpp/src/PCH.hpp:11:10: fatal error: 'SFML/System.hpp' file not found
[build] #include <SFML/System.hpp>
[build] ^~~~~~~~~~~~~~~~~
[build] 1 error generated.
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1
The error lies on this line:
This won't propagate requirements properly. It will only link the sfml libraries. Usually you also want other requirement such as include directories.
Instead, you should link to the targets exported by sfml:
Also you shouldn't need that: