Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to add SFML 2.5 as a git submodule into CMakeLists  (Read 3984 times)

0 Members and 1 Guest are viewing this topic.

123099

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
How to add SFML 2.5 as a git submodule into CMakeLists
« on: April 20, 2020, 10:12:16 pm »
Hello,

I am using CLion on Windows 10 and am trying to create a project that depends on SFML 2.5.
CLion uses CMake and I want to setup my CMakeLists to automatically include SFML as a subdirectory, compile it, find the library and link it.
This is my current CMakeLists:
Code: [Select]
cmake_minimum_required(VERSION 3.16)
project(Renderer)

set(CMAKE_CXX_STANDARD 20)

add_library(${PROJECT_NAME})

add_subdirectory(src)

target_include_directories(${PROJECT_NAME} PUBLIC include)

add_subdirectory(lib/glm)
target_link_libraries(${PROJECT_NAME} PRIVATE glm)

add_definitions(-DGLEW_STATIC)
add_subdirectory(lib/glew)
target_link_libraries(${PROJECT_NAME} PRIVATE libglew_static)

# SFML
add_subdirectory(lib/SFML)

set(SFML_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies/SFML)

find_package(SFML 2.5 COMPONENTS window audio REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE sfml-window sfml-audio)

And this is my folder structure. SFML is a git submodule.


The error I keep getting is
Code: [Select]
CMake Error at cmake-build-debug/lib/SFML/SFMLConfig.cmake:139 (message):
  Requested SFML configuration (Shared) was not found
Call Stack (most recent call first):
  CMakeLists.txt:23 (find_package)


CMake Error at CMakeLists.txt:23 (find_package):
  Found package configuration file:

    D:/Projects/C++/Renderer/cmake-build-debug/lib/SFML/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.

It seems like the SFML library files are not being built, even though it is included as a subdirectory?

I am not a CMake expert and have no idea how to continue forward from here. Unfortunately all the tutorials online focus on older versions of SFML and use the FindSFML thing instead of the new find_package SFMLConfig way.

Any help is appreciated!
« Last Edit: April 20, 2020, 10:53:56 pm by 123099 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to add SFML 2.5 as a git submodule into CMakeLists
« Reply #1 on: April 21, 2020, 08:32:55 am »
If you add SFML sources as part of your project, with add_subdirectory, then it is compiled with your project and its CMake targets are directly available, you mustn't find it. find_package is for searching an already compiled release.

You already do it correctly for GLEW and GLM, so why did you do it differently for SFML?

add_subdirectory(lib/SFML)
target_link_libraries(${PROJECT_NAME} PRIVATE sfml-window sfml-audio)
Laurent Gomila - SFML developer

123099

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: How to add SFML 2.5 as a git submodule into CMakeLists
« Reply #2 on: April 21, 2020, 12:06:22 pm »
Wow, I cannot believe it was that silly a mistake!
I got confused after looking at all the different tutorials that do use find_package, and didn't realise that that is for already compiled libraries. Thank you so much, it is working now!