Error CMake couldn't find SFML

Started by Kvaz1r, 19 September 2020, 13:34:49

Kvaz1r

While building TGUI got such error:

QuoteSFML found but some of its dependencies are missing ( FreeType)
CMake Warning at src/Backends/SFML/CMakeLists.txt:13 (find_package):
  Found package configuration file:

    */libraries/C++/SFML-2.5.1/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.
Call Stack (most recent call first):
  src/Backends/CMakeLists.txt:44 (include)
  src/CMakeLists.txt:162 (include)


CMake Error at src/Backends/SFML/CMakeLists.txt:25 (message):
  CMake couldn't find SFML.

  Set SFML_DIR to the directory containing SFMLConfig.cmake (usually
  something like SFML_ROOT/lib/cmake/SFML), or change TGUI_BACKEND to not use
  SFML.
Call Stack (most recent call first):
  src/Backends/CMakeLists.txt:44 (include)
  src/CMakeLists.txt:162 (include)

I suppose that's because this part was removed from CMakeLists.txt:

Quoteif(NOT TGUI_SHARED_LIBS)   
    if(SFML_ROOT)   
        if(TGUI_OS_WINDOWS)   
            set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${SFML_ROOT}/extlibs/headers")   
            if(ARCH_32BITS)   
                if(TGUI_COMPILER_MSVC AND MSVC_VERSION LESS 1900) # older than VC++14   
                    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-msvc/x86")   
                elseif(TGUI_COMPILER_MSVC) # VC++14 or newer   
                    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-msvc-universal/x86")   
                else() # gcc   
                    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-mingw/x86")   
                endif()   
            elseif(ARCH_64BITS)   
                if(TGUI_COMPILER_MSVC AND MSVC_VERSION LESS 1900) # older than VC++14   
                    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-msvc/x64")   
                elseif(TGUI_COMPILER_MSVC) # VC++14 or newer   
                    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-msvc-universal/x64")   
                else() # gcc   
                    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-mingw/x64")   
                endif()   
            endif()   
        elseif(TGUI_OS_MACOSX)   
            set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${SFML_ROOT}/extlibs/headers")   
            set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-osx/lib/")   
        elseif(TGUI_OS_ANDROID)   
            set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${CMAKE_ANDROID_NDK}/sources/third_party/sfml/extlibs/lib/${CMAKE_ANDROID_ARCH_ABI}/")   
        elseif(TGUI_OS_IOS)   
            set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${SFML_ROOT}/extlibs/libs-ios/")   
        endif()   
    endif()   
endif()   

together with SFML_ROOT. When I return it back and define SFML_ROOT all build as expected.

texus

Did you manually copy the SFMLConfig.cmake to a different location, because it seems like SFMLConfig.cmake can't find FreeType? The SFMLConfig.cmake hardcodes relative paths, so you are supposed to keep the SFML folder structure.

The SFML_ROOT method hasn't been recommended for quite some time already (because SFML changed the way you are supposed to find it with CMake), and I don't recommend adding back the code that uses it.

It might work when you put the hardcoded paths back into TGUI's CMake file, but the whole idea of using SFMLConfig.cmake (compared to the old FindSFML.cmake) was that I wouldn't have to hardcode these extlib paths anymore.

Kvaz1r

Quote from: texus on 19 September 2020, 13:41:57
Did you manually copy the SFMLConfig.cmake to a different location, because it seems like SFMLConfig.cmake can't find FreeType? The SFMLConfig.cmake hardcodes relative paths, so you are supposed to keep the SFML folder structure.

No, I didn't change(or move, or copied somewhere else) any file inside SFML folder.

texus

Then were did the SFML folder come from?
SFML doesn't has a SFMLConfig.cmake in the root by default. If you e.g. download it from the SFML website then the file will be in lib/cmake/SFML.
Did you build SFML yourself with CMake? If so, did you create a build directory?
The only case that I can think of where the file would be located there is when you build SFML with CMake and set the build directory to the same as the source directory, but even then it should be able to find freetype.

Kvaz1r

Maybe it exactly the mess in folder, because I built SFML from source into the same folder. I'll try rebuilt it to different location.

Kvaz1r

No, same issue even when build SFML from source into separate folder.

texus

#6
Could you send the SFML*.cmake files to me that you have inside your build folder?

Kvaz1r


texus

I don't see anything wrong with those files, it says that it has freetype at T:/libraries/C++/SFML-2.5.1/extlibs/libs-msvc-universal/x86/freetype.lib

Did you download the SFML version from github?
You are setting TGUI_SHARED_LIBS to FALSE, right?
Could you send the CMakeCache.txt file from your TGUI build?
Could you send your entire SFML folder?

I'm not sure when I'll find enough time to look into this in detail, but if you send me those files then I'll try to find some explanation when I find the time.

By placing the old code back in TGUI's cmake you are changing the CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH variables and the issue is only solved as a side-effect of this (those lines existed in the cmake script for building the gui builder and tests, not for finding sfml). So although it works, it isn't really the solution (it only works by accident that way).

texus

Could it be that C:/Strawberry/c/include/freetype2 is giving a conflict with the freetype that comes with SFML?

Kvaz1r

Quote from: texus on 19 September 2020, 20:01:39
I don't see anything wrong with those files, it says that it has freetype at T:/libraries/C++/SFML-2.5.1/extlibs/libs-msvc-universal/x86/freetype.lib

Did you download the SFML version from github?
You are setting TGUI_SHARED_LIBS to FALSE, right?
Could you send the CMakeCache.txt file from your TGUI build?
Could you send your entire SFML folder?
Yes, I download sourse for 2.5.1 release from Github.
Right.
CMakeCache.txt attached

Entire SFML folder is huge (.pdb files for samples are heavy) if it's really useful I'll build SFML without them and send folder.

Kvaz1r

Quote from: texus on 19 September 2020, 20:05:12
Could it be that C:/Strawberry/c/include/freetype2 is giving a conflict with the freetype that comes with SFML?
Maybe, in any case I am going to remove Strawberry and test it again to be sure.

Kvaz1r

I removed Strawberry but still got the same error.
I tried to build another project that has SFML as dependency and also got the same result. So it's not TGUI issue, but SFML one. I am going to create MCVE and raise issue on SFML forum.

Kvaz1r


Kvaz1r

Solution (define FreeType_LIB variable) was found in this issue - https://github.com/texus/TGUI/issues/180

thanks texus ;-)