Issue
With SFML installed on a Mac, I have some source files set up dependent on SFML such that I can compile them using the following command:
g++ src/* --std=c++20 -l sfml-system -l sfml-window -l sfml-graphics
Anyway, I'm trying to build the project using CMake, but I keep getting this error
`'SFML/Graphics.hpp' file not found
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall -g ")
project(silentValley)
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS src/*.cpp)
add_library(silentValleyLib SHARED ${SRC_FILES})
# BLOCK 1
# target_include_directories(silentValleyLib PUBLIC
# /usr/local/include/SFML/sfml-system
# /usr/local/include/SFML/sfml-window
# /usr/local/include/SFML/sfml-graphics
# /usr/local/include/SFML/
# )
# BlOCK2
# target_compile_options(silentValleyLib PRIVATE "-l sfml-system -l sfml-window -l sfml-graphics")
add_executable(silentValley ${SRC_FILES})
target_link_libraries(silentValley PRIVATE
silentValleyLib
)
Because of how I am able to compile using g++, I would expect this to work. Including the first commented block of code does nothing, and adding the second fails as well providing the warning
warning: -l sfml-system -l sfml-window -l sfml-graphics: 'linker' input unused [-Wunused-command-line-argument]
Can someone help me understand how to set this up ?
Solution
I used this path with target_link_libraries to make it work
target_link_libraries(silentValleyLib
/Library/Frameworks/SFML.framework
/Library/Frameworks/sfml-system.framework/sfml-system
/Library/Frameworks/sfml-window.framework/sfml-window
/Library/Frameworks/sfml-graphics.framework/sfml-graphics
)```
Answered By - antoine1111 Answer Checked By - Dawn Plyler (WPSolving Volunteer)