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

Author Topic: How do you use the FindSFML.cmake CMake module?  (Read 1247 times)

0 Members and 1 Guest are viewing this topic.

plutgamer

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
How do you use the FindSFML.cmake CMake module?
« on: April 08, 2012, 05:44:20 pm »
I'm working on a project, so I have to have somekind of building platform.
So I choose CMake.
I found the FindSFML.cmake module here: https://github.com/SFML/SFML/blob/master/cmake/Modules/FindSFML.cmake.
And I found this: http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries to use the module.
But the problem is, I don't know how to use the module, I tried it with the standard way listed on the page, but it gave an undefined resource error.

code:
CMakeLists.txt:
Code: [Select]
cmake_minimum_required (VERSION 2.6)
project (hello)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(SFML REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
set(LIBS ${LIBS} ${SFML_SYSTEM_LIBRARY})
add_executable (hello hello.cxx)
target_link_libraries(hello ${LIBS})
hello.cxx:
Code: [Select]
#include <iostream>
#include <SFML/System.hpp>

int main()
{
    /*sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }*/

    return 0;
}
Console output:
Code: [Select]
[stijn@vaio bin]$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Found SFML: /usr/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/stijn/devel/cmaketest/bin
[stijn@vaio bin]$ make
Scanning dependencies of target hello
[100%] Building CXX object CMakeFiles/hello.dir/hello.cxx.o
Linking CXX executable hello
CMakeFiles/hello.dir/hello.cxx.o: In function `main':
hello.cxx:(.text+0x10): undefined reference to `sf::Clock::Clock()'
hello.cxx:(.text+0x1e): undefined reference to `sf::Clock::GetElapsedTime() const'
hello.cxx:(.text+0x42): undefined reference to `sf::Sleep(float)'
hello.cxx:(.text+0x4e): undefined reference to `sf::Clock::GetElapsedTime() const'
collect2: ld gaf exit-status 1 terug
make[2]: *** [hello] Fout 1
make[1]: *** [CMakeFiles/hello.dir/all] Fout 2
make: *** [all] Fout 2

Sorry for it being half in dutch, and yes it's a Sony VAIO.
CMake says everything is perfect. But when I use make to actually compile it, it gives the undefined resource error.  :'(

Platform info:
Fedora Linux 16 x64
CMake
GNU Make
And g++

Sorry for being such a noob! :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How do you use the FindSFML.cmake CMake module?
« Reply #1 on: April 08, 2012, 06:06:29 pm »
You must specify the version and components that you want to find:
Code: [Select]
find_package(SFML 2 COMPONENTS system REQUIRED)
I should probably make it clearer in the documentation.
Laurent Gomila - SFML developer

plutgamer

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: How do you use the FindSFML.cmake CMake module?
« Reply #2 on: April 08, 2012, 06:29:36 pm »
Thank you!  :D
« Last Edit: April 08, 2012, 06:57:47 pm by plutgamer »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How do you use the FindSFML.cmake CMake module?
« Reply #3 on: April 08, 2012, 06:48:02 pm »
You're not "such a noob", you helped me improve the doc, which was lacking important details ;)
Laurent Gomila - SFML developer