0

As per the title, CMake is unable to find SFML which I installed using Microsoft's vcpkg tool through CMakes find_package() macro.

I have verified that SFML has been installed in the vcpkg installed directory (~\vcpkg\installed\x86-windows).

In addition, I have also included the toolchain file from vcpkg in the CMakeSettings.json file.

The specific error is:

CMake Error at ~\CMakeLists.txt:40 (find_package):
Could not find a package configuration file provided by "SFML" (requested
    version 2.4.2) with any of the following names:

 SFMLConfig.cmake
 sfml-config.cmake

CMakeSettings.json (simplified - only debug configuration):

"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -v:minimal",
"variables": [
    {
        "name": "CMAKE_TOOLCHAIN_FILE",
        "value": "C:\\Microsoft\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
    }
]

CMakeLists.txt (also simplified):

cmake_minimum_required(VERSION 3.6)
project(Tempus)
add_subdirectory(src)

# Fails at this step
find_package(SFML 2.4.2 REQUIRED system window graphics)

include_directories(${SFML_INCLUDE_DIR})

add_executable(Tempus ${SRC})
target_link_libraries(Tempus ${SFML_LIBRARIES})

I don't think I missed anything. SFML provides a findSFML.cmake which vcpkg should handle itself through the toolchain file (assuming I have understood their documentation correctly). I must be missing something?

  • 1
    `'SFML' provides a 'findSFML.cmake'` - No, SFML installation may provide `SFMLConfig.cmake`, but `Find*.cmake` scripts are provided either by CMake itself, or with **your project** (by having existed script in the your source tree). This doesn't answer your question, but just a hint. – Tsyvarev Aug 02 '17 at 21:06
  • @Tsyvarev Thanks for your hint! It seems `vcpkg` provides the files and other including and linking stuff, but does not provide the `findSFML.cmake` file. Once it can find `SFML`, it sets all `CMake SFML` macros and constants. By adding the `findSFML.cmake` file manually to a CMake modules directory it has resolved my problem. Would you like to add your comment as a answer? – segmentation_fault Aug 03 '17 at 09:16
  • 1
    [Your answer](https://stackoverflow.com/a/45479833/3440745) resolves the problem. Why have you deleted it? If you bother about plagiarism, then: 1. *Comment* is not an answer. 2. Simple "thanks" in the answer, as you have, is sufficient in the most cases. 3. Your answer contains more than the comment. – Tsyvarev Aug 03 '17 at 18:06
  • Ok, cool. I was worried about plagiarism. I've undeleted it. Thanks :) – segmentation_fault Aug 04 '17 at 13:12

1 Answers1

0

It seems vcpkg provides the files and other including and linking stuff, but does not provide the findSFML.cmake file. Once it can find SFML, it sets all CMake SFML macros and constants. By adding the findSFML.cmake file manually to a CMake modules directory it has resolved my problem.

Thanks to @Tsyvarev for the hint which led me to a solution.

I'll follow up with the vcpkg team to find out if this is how it should work and perhaps ask them to add this into their documentation as well.