Cmake can't find TGUI

Started by avraal, 09 October 2018, 01:12:40

avraal

Hi,
I'm use CLion on Windows, and i want in tgui, but my cmake can't find him


cmake_minimum_required(VERSION 3.12)
project(testSFML)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})

add_executable(testSFML main.cpp)

include_directories(D:/Andrew/Resources/SFML/include)
link_directories(D:/Andrew/Resources/SFML/lib)
include_directories(D:/Andrew/Resources/TGUI/include)
link_directories(D:/Andrew/Resources/TGUI/lib)

find_package(SFML REQUIRED COMPONENTS system window graphics network audio)
find_package(TGUI REQUIRED)

if(NOT SFML_FOUND)
    message(FATAL_ERROR "Could not find SFML")
endif()

if(NOT TGUI_FOUND)
    message(FATAL_ERROR "CMake couldn't find TGUI. Set the TGUI_ROOT entry to TGUI's root directory (containing \"include\" and \"lib\" directories).")
endif()


include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(testSFML ${TGUI_LIBRARY})
target_link_libraries(testSFML tgui sfml-system sfml-window sfml-graphics sfml-network sfml-audio)

And i have error:
QuoteCMake Error at CMakeLists.txt:15 (find_package): By not providing "FindTGUI.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "TGUI", but CMake did not find one.

Where i can find FindTGUI.cmake?

texus

TGUI 0.8 no longer uses TGUI_ROOT, CMAKE_MODULE_PATH or FindTGUI.cmake (and if you are using SFML 2.5 then SFML isn't using such stuff either).

If find_package can't find TGUI by itself (which is normal on windows since it doesn't have default locations to put libraries) then you must set the TGUI_DIR directory to "D:/Andrew/Resources/TGUI/lib/cmake/TGUI" (the folder containing TGUIConfig.cmake).

After find_package you just need "target_link_libraries(testSFML PRIVATE tgui sfml-graphics)" (you only need sfml-window and sfml-system if you are still using the old way of finding SFML). Calling include_directories is also no longer needed with the new method.

Since you are using REQUIRED, you can also drop the checks for SFML_FOUND and TGUI_FOUND, since cmake won't go past the find_package call until they are found.

So a cmake file for SFML 2.5 and  TGUI would look like this:
Code (cmake) Select
cmake_minimum_required(VERSION 3.12)
project(testSFML)

set(CMAKE_CXX_STANDARD 14)

add_executable(testSFML main.cpp)

set(SFML_DIR "D:/Andrew/Resources/SFML/lib/cmake/SFML")
set(TGUI_DIR "D:/Andrew/Resources/TGUI/lib/cmake/TGUI")

find_package(SFML REQUIRED COMPONENTS system window graphics network audio)
find_package(TGUI REQUIRED)

target_link_libraries(testSFML PRIVATE tgui sfml-graphics)


Note that SFML_DIR and TGUI_DIR shouldn't actually be set in your cmake file, it makes your cmake file only work for you. They are supposed to be set in the cmake gui or passed to cmake on the command line. But if it is just a personal project that you only run on one computer then you can just keep the _DIR entries there for simplicity.

avraal

It's a personal project, first time
So, i can't find this directory: "TGUI/lib/cmake/TGUI"
I have directories like in my screenshot
In directory cmake exist file "Config.cmake". You mean this file as "TGUIConfig.cmake"?

texus

Can you also show what is inside the "lib" folder? Doesn't the "lib" folder also contain a "cmake" folder?

avraal

No, this folder has only libs

texus

#5
It appears that the downloads on my website don't contain these files, my build system doesn't copy them. I actually have 2 to 4 variants for each compiler, so I will have to figure out if they are the same and whether I can just copy them or not. I won't be able to provide these files immediately. This issue probably went unnoticed because others aren't using cmake in their own project.

So you will have to build TGUI yourself. Create a "build" folder inside the root TGUI directory. If using the command line, from inside the build folder just run
cmake -DSFML_DIR="D:/Andrew/Resources/SFML/lib/cmake/SFML" ..
(you can add "-DCMAKE_BUILD_TYPE=Debug" for debug libraries or "-DTGUI_SHARED_LIBS=FALSE" for static libraries)

If using the cmake gui, just follow the cmake section of the https://tgui.eu/tutorials/0.8/codeblocks/ tutorial. Basically you just enter the root TGUI directory, the build folder and then when it asks you fill in SFML_DIR. You might also want to select whether you want Release or Debug libraries (if you want both then you need to create 2 build directories and do everything two times) and whether you want shared libraries (with dlls) or static libraries. The other things can be ignored.

When building yourself, the FindTGUI.cmake file will be created in the build folder (you can't copy the file, you must keep it there). So in your own project, TGUI_DIR would then have to become "D:/Andrew/Resources/TGUI/build".

avraal

#6
Ok, i did it
But, TGUIConfig.cmake set TGUI_FOUND to FALSE
I'm check TGUIConfig.cmake, and i found condition, when TGUI_FOUND may set FALSE
I think - it's problem with {targets_config_file}, because i can't found file like "/TGUI${config_name}Targets.cmake"

But, these are just my guesses
What am I doing wrong?

upd: I was choosing shared libraries
upd2: I fixed this problem. I forgot press Generate button in CMake-gui.
After this i'm copied libraries from TGUI/lib/ to TGUI/build/lib/
But it create one more problem. If i definition any variable with "tgui"-like type

std::cout << "Hello, World!" << std::endl;
tgui::Gui gui(window);

Program build, but not executed

During startup program exited with code 0xc0000135.
Process finished with exit code 1

It's worked, if i commented line with gui

Hello, World!
Process finished with exit code 0

If I'm not mistaken, this error is due with wrong installation of libraries

texus

Are you sure your libraries are compatible for your compiler? What is the exact compiler you are using? Which libraries did you download?

Copying the libraries you had to build/lib should have worked. Did you also copy the tgui dll next to your exe?

You could try to build the libraries yourself instead of copying the existing libraries, that would guarantee that they are compatible with your compiler. Check that the compiler which cmake finds is the one you are using (can be seen in the cmake gui at CMAKE_CXX_COMPILER after checking the Advanced checkbox). After you pressed configure and generate, cmake would have created a makefile. (The tutorial I linked showed choosing "CodeBlocks - MinGW makefiles" which aren't the ones you need, so if you chose that in the beginning then you may need to delete the build folder and try again, this time selecting just "MinGW Makefiles"). You can run this makefile from the command line by running "mingw32-make" while in the build folder. When it finished it should have created libraries in the build/lib folder.

texus

I've created the missing cmake files, they are attached to this post.dr

The cmake folder contained in the zip file has to be placed inside "TGUI/lib" and then you should be able to use the cmake script from my first post without needing the "build" folder. I haven't been able to actually test the attached files myself, so let me know if you get any other errors.

avraal

Okey, it was hard, but i can  :o
I'm "reordered" my project
So, i'm downloaded sources from github, built it with cmake, install it with mingw32-make, copied libs from /TGUI/build/libs/ to /ProjectName/cmake-build-debug/ and... It's worked
Thanks for all