0

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 ?

antoine1111
  • 33
  • 1
  • 6
  • The directory `/usr/local/include` is not used as include directory on MacOS by default: https://stackoverflow.com/questions/23905661/on-mac-g-clang-fails-to-search-usr-local-include-and-usr-local-lib-by-def. As for libraries to link, in CMake they are specified by `target_link_libraries` command: https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake/43136695#43136695 – Tsyvarev Oct 19 '22 at 13:38
  • Did you try to add `pkg_check_modules (SFML REQUIRED sfml-all)` command to CMakeLists.txt? Your local include directory might not be a default path to look for includes. – Martin Sand Oct 19 '22 at 13:39
  • Yes actually target_link_libraries is what I initially used but it did not work ` target_link_libraries(silentValleyLib PUBLIC /usr/local/include/SFML/sfml-system /usr/local/include/SFML/sfml-window /usr/local/include/SFML/sfml-graphics /usr/local/include/SFML/ # ${SFML_INCLUDE_DIR} # SFML sfml-system sfml-window sfml-graphics ) ` – antoine1111 Oct 19 '22 at 14:11
  • pkg_check_modules is unknown to Cmake although I'm using 3.24.2. Still trying to figure this out – antoine1111 Oct 19 '22 at 14:23
  • @Tsyvarev For me it seems included by default. Therefore I'm not sure why I have to specify target_link_libraries. I still specify it, but with no success – antoine1111 Oct 19 '22 at 14:26
  • Sorry, I thought you are familiar with CMake. The actual command is `find_package (PkgConfig REQUIRED)` and then in a new line you add `pkg_check_modules (SFML REQUIRED sfml-all)` – Martin Sand Oct 19 '22 at 14:44
  • I had to target_link_libraries to /Library/Frameworks/SFML.framework to advance to linking phase, but it fails. Although this question seems imply that target_link_libraries should be equivalent to -l https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake/43136695#43136695 – antoine1111 Oct 19 '22 at 21:03

1 Answers1

0

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
)```
antoine1111
  • 33
  • 1
  • 6